Skip to content

Commit

Permalink
Handle float input to incr/decr, fixes petergoldsteinGH-165
Browse files Browse the repository at this point in the history
  • Loading branch information
mperham committed Feb 1, 2012
1 parent 1cb62ba commit 357bca5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions History.md
Expand Up @@ -4,6 +4,7 @@ Dalli Changelog
HEAD
=======

- Coerce input to incr/decr to integer via #to\_i [#165]
- Convert test suite to minitest/spec (crigor, #166)
- Fix encoding issue with keys [#162]
- Fix double namespacing with Rails and dalli\_store. [#160]
Expand Down
8 changes: 4 additions & 4 deletions lib/dalli/client.rb
Expand Up @@ -183,7 +183,7 @@ def flush(delay=0)

##
# Incr adds the given amount to the counter on the memcached server.
# Amt must be a positive value.
# Amt must be a positive integer value.
#
# If default is nil, the counter must already exist or the operation
# will fail and will return nil. Otherwise this method will return
Expand All @@ -195,12 +195,12 @@ def flush(delay=0)
def incr(key, amt=1, ttl=nil, default=nil)
raise ArgumentError, "Positive values only: #{amt}" if amt < 0
ttl ||= @options[:expires_in]
perform(:incr, key, amt, ttl, default)
perform(:incr, key, amt.to_i, ttl, default)
end

##
# Decr subtracts the given amount from the counter on the memcached server.
# Amt must be a positive value.
# 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.
Expand All @@ -215,7 +215,7 @@ def incr(key, amt=1, ttl=nil, default=nil)
def decr(key, amt=1, ttl=nil, default=nil)
raise ArgumentError, "Positive values only: #{amt}" if amt < 0
ttl ||= @options[:expires_in]
perform(:decr, key, amt, ttl, default)
perform(:decr, key, amt.to_i, ttl, default)
end

##
Expand Down

0 comments on commit 357bca5

Please sign in to comment.