Method: Sinatra::Cache::RedisStore#increment
- Defined in:
- lib/cache/sinatra/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"
75 76 77 |
# File 'lib/cache/sinatra/redis_store.rb', line 75 def increment(key, amount = 1) @data.incrby key, amount end |