class TrailGuide::Adapters::Participants::Redis::Adapter

Attributes

storage_key[R]

Public Class Methods

new(context, config, key: nil) click to toggle source
# File lib/trail_guide/adapters/participants/redis.rb, line 23
def initialize(context, config, key: nil)
  super(context, config)

  if key
    @storage_key = "#{config.namespace}:#{key}"
  elsif config.lookup
    if config.lookup.respond_to?(:call)
      key = config.lookup.call(context)
    else
      key = context.send(config.lookup)
    end
    @storage_key = "#{config.namespace}:#{key}"
  else
    raise ArgumentError, "You must configure a `lookup` proc to use the redis adapter."
  end
end

Public Instance Methods

[](field) click to toggle source
# File lib/trail_guide/adapters/participants/redis.rb, line 40
def [](field)
  TrailGuide.redis.hget(storage_key, field.to_s)
end
[]=(field, value) click to toggle source
# File lib/trail_guide/adapters/participants/redis.rb, line 44
def []=(field, value)
  TrailGuide.redis.hset(storage_key, field.to_s, value)
  TrailGuide.redis.expire(storage_key, config.expiration) if config.expiration
end
delete(field) click to toggle source
# File lib/trail_guide/adapters/participants/redis.rb, line 49
def delete(field)
  TrailGuide.redis.hdel(storage_key, field.to_s)
end
destroy!() click to toggle source
# File lib/trail_guide/adapters/participants/redis.rb, line 53
def destroy!
  TrailGuide.redis.del(storage_key)
end
key?(field) click to toggle source
# File lib/trail_guide/adapters/participants/redis.rb, line 61
def key?(field)
  TrailGuide.redis.hexists(storage_key, field.to_s)
end
keys() click to toggle source
# File lib/trail_guide/adapters/participants/redis.rb, line 57
def keys
  TrailGuide.redis.hkeys(storage_key)
end
to_h() click to toggle source
# File lib/trail_guide/adapters/participants/redis.rb, line 65
def to_h
  TrailGuide.redis.hgetall(storage_key)
end