Method: Dalli::Client#decr

Defined in:
lib/dalli/client.rb

#decr(key, amt = 1, ttl = nil, default = nil) ⇒ Object

Decr subtracts the given amount from the counter on the memcached server. Amt must be a positive integer value.

memcached counters are unsigned and cannot hold negative values. Calling decr on a counter which is 0 will just return 0.

If default is nil, the counter must already exist or the operation will fail and will return nil. Otherwise this method will return the new value for the counter.

Note that the ttl will only apply if the counter does not already exist. To decrease an existing counter and update its TTL, use #cas.

If the value already exists, it must have been set with raw: true



438
439
440
441
442
# File 'lib/dalli/client.rb', line 438

def decr(key, amt = 1, ttl = nil, default = nil)
  check_positive!(amt)

  perform(:decr, key, amt.to_i, ttl_or_default(ttl), default)
end