class RedisStore::Store
Redis-backed store object
Attributes
raw[R]
Public Class Methods
new(params = {})
click to toggle source
Generate an empty store
# File lib/redisstore.rb, line 23 def initialize(params = {}) @raw = Redis.new(params) end
Public Instance Methods
[](key)
click to toggle source
Retrieve a key
# File lib/redisstore.rb, line 44 def [](key) parse @raw.get(prep key) end
[]=(key, value)
click to toggle source
Set a key
# File lib/redisstore.rb, line 51 def []=(key, value) @raw.set prep(key), prep(value) end
clear!(key = nil)
click to toggle source
Clears a specified key or the whole store
# File lib/redisstore.rb, line 30 def clear!(key = nil) if key.nil? @raw.flushdb && {} else key = prep(key) value = @raw.get key @raw.del key parse value end end
include?(key)
click to toggle source
Check for a key in the store
# File lib/redisstore.rb, line 65 def include?(key) @raw.exists(prep key) end
keys()
click to toggle source
Array of keys in the store
# File lib/redisstore.rb, line 72 def keys @raw.keys.map { |x| parse x } end
size()
click to toggle source
Return the size of the store
# File lib/redisstore.rb, line 58 def size @raw.dbsize end
Private Instance Methods
parse(object)
click to toggle source
# File lib/redisstore.rb, line 82 def parse(object) object.nil? ? nil : Marshal.load(object) end
prep(object)
click to toggle source
# File lib/redisstore.rb, line 78 def prep(object) Marshal.dump object end