Permalink
Browse files

Handle float input to incr/decr, fixes GH-165

  • Loading branch information...
1 parent 1cb62ba commit 357bca5221280074e3ba63cc4d77bca660687df9 @mperham mperham committed Feb 1, 2012
Showing with 5 additions and 4 deletions.
  1. +1 −0 History.md
  2. +4 −4 lib/dalli/client.rb
View
@@ -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]
View
@@ -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
@@ -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.
@@ -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
##

0 comments on commit 357bca5

Please sign in to comment.