Method: ActiveSupport::Cache::RedisStore#increment
- Defined in:
- lib/active_support/cache/redis_store.rb
#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"
63 64 65 66 |
# File 'lib/active_support/cache/redis_store.rb', line 63 def increment(key, amount = 1) log "increment", key, amount @data.incr key, amount end |