class Cistern::Data::Redis
Attributes
marshal[W]
client[R]
default[R]
Public Class Methods
marshal()
click to toggle source
# File lib/cistern/data/redis.rb, line 6 def self.marshal @marshal ||= begin require 'multi_json' MultiJson rescue LoadError require 'json' ::JSON end end
new(options = {}, &block)
click to toggle source
# File lib/cistern/data/redis.rb, line 20 def initialize(options = {}, &block) @client = options[:client] || ::Redis.new @default = block end
Public Instance Methods
clear()
click to toggle source
# File lib/cistern/data/redis.rb, line 25 def clear unless (keys = client.keys('*')).empty? client.del(*keys) end end
fetch(key, *args)
click to toggle source
# File lib/cistern/data/redis.rb, line 39 def fetch(key, *args) assign_default(key) Cistern::Data::Redis.marshal.load(client.get(key, *args)) end
Also aliased as: []
store(key, value, *args)
click to toggle source
# File lib/cistern/data/redis.rb, line 31 def store(key, value, *args) assign_default(key) client.set(key, Cistern::Data::Redis.marshal.dump(value), *args) end
Also aliased as: []=
Protected Instance Methods
assign_default(key)
click to toggle source
# File lib/cistern/data/redis.rb, line 51 def assign_default(key) default.call(client, key) if client.keys(key).empty? && default end