lib/cistern/data/redis.rb in cistern-2.2.3 vs lib/cistern/data/redis.rb in cistern-2.2.4
- old
+ new
@@ -9,46 +9,44 @@
require 'json'
::JSON
end
end
- def self.marshal=(marshal)
- @marshal = marshal
+ class << self
+ attr_writer :marshal
end
- def initialize(options={}, &block)
+ def initialize(options = {}, &block)
@client = options[:client] || ::Redis.new
@default = block
end
def clear
- unless (keys = client.keys("*")).empty?
+ unless (keys = client.keys('*')).empty?
client.del(*keys)
end
end
def store(key, value, *args)
assign_default(key)
client.set(key, Cistern::Data::Redis.marshal.dump(value), *args)
end
- alias []= store
+ alias_method :[]=, :store
def fetch(key, *args)
assign_default(key)
Cistern::Data::Redis.marshal.load(client.get(key, *args))
end
- alias [] fetch
+ alias_method :[], :fetch
protected
attr_reader :client, :default
def assign_default(key)
- if client.keys(key).empty? && default
- default.call(client, key)
- end
+ default.call(client, key) if client.keys(key).empty? && default
end
end