Class: Merb::Cache::RedisStore
- Inherits:
-
AbstractStore
- Object
- AbstractStore
- Merb::Cache::RedisStore
- Defined in:
- lib/cache/merb/redis_store.rb
Instance Method Summary collapse
- #delete(key, parameters = {}) ⇒ Object
- #delete_all ⇒ Object
- #delete_all! ⇒ Object
- #exists?(key, parameters = {}) ⇒ Boolean
- #fetch(key, parameters = {}, conditions = {}, &blk) ⇒ Object
-
#initialize(config = {}) ⇒ RedisStore
constructor
Instantiate the store.
- #read(key, parameters = {}, conditions = {}) ⇒ Object
- #writable?(key, parameters = {}, conditions = {}) ⇒ Boolean
- #write(key, data = nil, parameters = {}, conditions = {}) ⇒ Object
- #write_all(key, data = nil, parameters = {}, conditions = {}) ⇒ Object
Constructor Details
#initialize(config = {}) ⇒ RedisStore
Instantiate the store.
Example:
RedisStore.new # => host: localhost, port: 6379, db: 0
RedisStore.new :servers => ["example.com"] # => host: example.com, port: 6379, db: 0
RedisStore.new :servers => ["example.com:23682"] # => host: example.com, port: 23682, db: 0
RedisStore.new :servers => ["example.com:23682/1"] # => host: example.com, port: 23682, db: 1
RedisStore.new :servers => ["localhost:6379/0", "localhost:6380/0"] # => instantiate a cluster
12 13 14 |
# File 'lib/cache/merb/redis_store.rb', line 12 def initialize(config = {}) @data = RedisFactory.create config[:servers] end |
Instance Method Details
#delete(key, parameters = {}) ⇒ Object
43 44 45 |
# File 'lib/cache/merb/redis_store.rb', line 43 def delete(key, parameters = {}) @data.delete normalize(key, parameters) end |
#delete_all ⇒ Object
47 48 49 |
# File 'lib/cache/merb/redis_store.rb', line 47 def delete_all @data.flush_db end |
#delete_all! ⇒ Object
51 52 53 |
# File 'lib/cache/merb/redis_store.rb', line 51 def delete_all! delete_all end |
#exists?(key, parameters = {}) ⇒ Boolean
39 40 41 |
# File 'lib/cache/merb/redis_store.rb', line 39 def exists?(key, parameters = {}) @data.key? normalize(key, parameters) end |
#fetch(key, parameters = {}, conditions = {}, &blk) ⇒ Object
35 36 37 |
# File 'lib/cache/merb/redis_store.rb', line 35 def fetch(key, parameters = {}, conditions = {}, &blk) read(key, parameters) || (write key, yield, parameters, conditions if block_given?) end |
#read(key, parameters = {}, conditions = {}) ⇒ Object
20 21 22 |
# File 'lib/cache/merb/redis_store.rb', line 20 def read(key, parameters = {}, conditions = {}) @data.get normalize(key, parameters), conditions end |
#writable?(key, parameters = {}, conditions = {}) ⇒ Boolean
16 17 18 |
# File 'lib/cache/merb/redis_store.rb', line 16 def writable?(key, parameters = {}, conditions = {}) true end |
#write(key, data = nil, parameters = {}, conditions = {}) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/cache/merb/redis_store.rb', line 24 def write(key, data = nil, parameters = {}, conditions = {}) if writable?(key, parameters, conditions) method = conditions && conditions[:unless_exist] ? :set_unless_exists : :set @data.send method, normalize(key, parameters), data, conditions end end |
#write_all(key, data = nil, parameters = {}, conditions = {}) ⇒ Object
31 32 33 |
# File 'lib/cache/merb/redis_store.rb', line 31 def write_all(key, data = nil, parameters = {}, conditions = {}) write key, data, parameters, conditions end |