lib/fakeredis/zset.rb in fakeredis-0.4.3 vs lib/fakeredis/zset.rb in fakeredis-0.5.0
- old
+ new
@@ -9,18 +9,22 @@
def increment(key, val)
self[key] += _floatify(val)
end
def select_by_score min, max
- min = _floatify(min)
- max = _floatify(max)
+ min = _floatify(min, true)
+ max = _floatify(max, false)
reject {|_,v| v < min || v > max }
end
+ private
+
# Originally lifted from redis-rb
- def _floatify(str)
+ def _floatify(str, increment = true)
if (( inf = str.to_s.match(/^([+-])?inf/i) ))
(inf[1] == "-" ? -1.0 : 1.0) / 0.0
+ elsif (( number = str.to_s.match(/^\((\d+)/i) ))
+ number[1].to_i + (increment ? 1 : -1)
else
Float str
end
end