Class: ActiveSupport::Cache::RedisStore
- Inherits:
-
Store
- Object
- Store
- ActiveSupport::Cache::RedisStore
- Includes:
- Redis::Store.rails3? ? Rails3 : Rails2
- Defined in:
- lib/active_support/cache/redis_store.rb
Instance Method Summary collapse
-
#clear ⇒ Object
Clear all the data from the store.
-
#decrement(key, amount = 1) ⇒ Object
Decrement a key in the store.
-
#increment(key, amount = 1) ⇒ Object
Increment a key in the store.
-
#read_multi(*names) ⇒ Object
Reads multiple keys from the cache using a single call to the servers for all keys.
- #stats ⇒ Object
Instance Method Details
#clear ⇒ Object
Clear all the data from the store.
217 218 219 220 221 |
# File 'lib/active_support/cache/redis_store.rb', line 217 def clear instrument(:clear, nil, nil) do @data.flushdb end end |
#decrement(key, amount = 1) ⇒ Object
Decrement a key in the store
If the key doesn’t exist it will be initialized on 0. If the key exist but it isn’t a Fixnum it will be initialized on 0.
Example:
We have two objects in cache:
counter # => 23
rabbit # => #<Rabbit:0x5eee6c>
cache.decrement "counter"
cache.read "counter", :raw => true # => "22"
cache.decrement "counter", 2
cache.read "counter", :raw => true # => "20"
cache.decrement "a counter"
cache.read "a counter", :raw => true # => "-1"
cache.decrement "rabbit"
cache.read "rabbit", :raw => true # => "-1"
210 211 212 213 214 |
# File 'lib/active_support/cache/redis_store.rb', line 210 def decrement(key, amount = 1) instrument(:decrement, key, :amount => amount) do @data.decrby key, amount end end |
#increment(key, amount = 1) ⇒ Object
Increment a key in the store.
If the key doesn’t exist it will be initialized on 0. If the key exist but it isn’t a Fixnum it will be initialized on 0.
Example:
We have two objects in cache:
counter # => 23
rabbit # => #<Rabbit:0x5eee6c>
cache.increment "counter"
cache.read "counter", :raw => true # => "24"
cache.increment "counter", 6
cache.read "counter", :raw => true # => "30"
cache.increment "a counter"
cache.read "a counter", :raw => true # => "1"
cache.increment "rabbit"
cache.read "rabbit", :raw => true # => "1"
183 184 185 186 187 |
# File 'lib/active_support/cache/redis_store.rb', line 183 def increment(key, amount = 1) instrument(:increment, key, :amount => amount) do @data.incrby key, amount end end |
#read_multi(*names) ⇒ Object
Reads multiple keys from the cache using a single call to the servers for all keys. Options can be passed in the last argument.
Example:
cache.read_multi "rabbit", "white-rabbit"
cache.read_multi "rabbit", "white-rabbit", :raw => true
158 159 160 |
# File 'lib/active_support/cache/redis_store.rb', line 158 def read_multi(*names) @data.mget *names end |
#stats ⇒ Object
223 224 225 |
# File 'lib/active_support/cache/redis_store.rb', line 223 def stats @data.info end |