Class: Stockpot::RedisController

Inherits:
MainController
  • Object
show all
Defined in:
app/controllers/stockpot/redis_controller.rb

Instance Method Summary collapse

Methods included from Helper::Errors

#rescue_error, #return_error

Instance Method Details

#createObject



17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/stockpot/redis_controller.rb', line 17

def create
  if params[:field].present?
    # Sets :field in the hash stored at :key to :value
    REDIS.hset(params[:key], params[:field], params[:value])
  else
    # Sets :key to hold the string :value
    REDIS.set(params[:key], params[:value])
  end

  render json: { status: 201 }
end

#indexObject



5
6
7
8
9
10
11
12
13
14
15
# File 'app/controllers/stockpot/redis_controller.rb', line 5

def index
  if params[:field].present?
    # Returns the value associated with :field in the hash stored at :key
    record = REDIS.hget(params[:key], params[:field])
  else
    # Returns the value of :key
    record = REDIS.get(params[:key])
  end

  render json: record.to_json, status: :ok
end

#keysObject



29
30
31
32
33
# File 'app/controllers/stockpot/redis_controller.rb', line 29

def keys
  record = REDIS.keys

  render json: record.to_json, status: :ok
end