class FakeRedis::ZSet
Public Instance Methods
[]=(key, val)
click to toggle source
Calls superclass method
# File lib/fakeredis/zset.rb, line 4 def []=(key, val) super(key, _floatify(val)) end
identical_scores?()
click to toggle source
# File lib/fakeredis/zset.rb, line 8 def identical_scores? values.uniq.size == 1 end
increment(key, val)
click to toggle source
Increments the value of key by val
# File lib/fakeredis/zset.rb, line 13 def increment(key, val) self[key] += _floatify(val) end
select_by_score(min, max)
click to toggle source
# File lib/fakeredis/zset.rb, line 17 def select_by_score min, max min = _floatify(min, true) max = _floatify(max, false) reject {|_,v| v < min || v > max } end
Private Instance Methods
_floatify(str, increment = true)
click to toggle source
Originally lifted from redis-rb
# File lib/fakeredis/zset.rb, line 26 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.to_s end rescue ArgumentError raise Redis::CommandError, "ERR value is not a valid float" end