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 => ["example.com:23682/1/theplaylist"]
# => host: example.com, port: 23682, db: 1, namespace: theplaylist
RedisStore.new :servers => ["localhost:6379/0", "localhost:6380/0"]
# => instantiate a cluster
24 25 26 |
# File 'lib/cache/merb/redis_store.rb', line 24 def initialize(config = { }) @data = Redis::Factory.create config[:servers] end |
Instance Method Details
#delete(key, parameters = {}) ⇒ Object
55 56 57 |
# File 'lib/cache/merb/redis_store.rb', line 55 def delete(key, parameters = {}) @data.del normalize(key, parameters) end |
#delete_all ⇒ Object
59 60 61 |
# File 'lib/cache/merb/redis_store.rb', line 59 def delete_all @data.flushdb end |
#delete_all! ⇒ Object
63 64 65 |
# File 'lib/cache/merb/redis_store.rb', line 63 def delete_all! delete_all end |
#exists?(key, parameters = {}) ⇒ Boolean
51 52 53 |
# File 'lib/cache/merb/redis_store.rb', line 51 def exists?(key, parameters = {}) @data.exists normalize(key, parameters) end |
#fetch(key, parameters = {}, conditions = {}, &blk) ⇒ Object
47 48 49 |
# File 'lib/cache/merb/redis_store.rb', line 47 def fetch(key, parameters = {}, conditions = {}, &blk) read(key, parameters) || (write key, yield, parameters, conditions if block_given?) end |
#read(key, parameters = {}, conditions = {}) ⇒ Object
32 33 34 |
# File 'lib/cache/merb/redis_store.rb', line 32 def read(key, parameters = {}, conditions = {}) @data.get normalize(key, parameters), conditions end |
#writable?(key, parameters = {}, conditions = {}) ⇒ Boolean
28 29 30 |
# File 'lib/cache/merb/redis_store.rb', line 28 def writable?(key, parameters = {}, conditions = {}) true end |
#write(key, data = nil, parameters = {}, conditions = {}) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/cache/merb/redis_store.rb', line 36 def write(key, data = nil, parameters = {}, conditions = {}) if writable?(key, parameters, conditions) method = conditions && conditions[:unless_exist] ? :setnx : :set @data.send method, normalize(key, parameters), data, conditions end end |
#write_all(key, data = nil, parameters = {}, conditions = {}) ⇒ Object
43 44 45 |
# File 'lib/cache/merb/redis_store.rb', line 43 def write_all(key, data = nil, parameters = {}, conditions = {}) write key, data, parameters, conditions end |