Class: Cistern::Data::Redis
- Inherits:
-
Object
- Object
- Cistern::Data::Redis
- Defined in:
- lib/cistern/data/redis.rb
Class Attribute Summary collapse
Instance Method Summary collapse
- #clear ⇒ Object
- #fetch(key, *args) ⇒ Object (also: #[])
-
#initialize(options = {}, &block) ⇒ Redis
constructor
A new instance of Redis.
- #store(key, value, *args) ⇒ Object (also: #[]=)
Constructor Details
#initialize(options = {}, &block) ⇒ Redis
Returns a new instance of Redis.
20 21 22 23 |
# File 'lib/cistern/data/redis.rb', line 20 def initialize( = {}, &block) @client = [:client] || ::Redis.new @default = block end |
Class Attribute Details
.marshal ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/cistern/data/redis.rb', line 6 def self.marshal @marshal ||= begin require 'multi_json' MultiJson rescue LoadError require 'json' ::JSON end end |
Instance Method Details
#clear ⇒ Object
25 26 27 28 29 |
# File 'lib/cistern/data/redis.rb', line 25 def clear unless (keys = client.keys('*')).empty? client.del(*keys) end end |
#fetch(key, *args) ⇒ Object Also known as: []
39 40 41 42 43 |
# 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 |
#store(key, value, *args) ⇒ Object Also known as: []=
31 32 33 34 35 |
# 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 |