Class: FakeRedis::ZSet

Inherits:
Hash
  • Object
show all
Defined in:
lib/fakeredis/zset.rb

Instance Method Summary collapse

Instance Method Details

#[]=(key, val) ⇒ Object



4
5
6
# File 'lib/fakeredis/zset.rb', line 4

def []=(key, val)
  super(key, _floatify(val))
end

#_floatify(str) ⇒ Object

Originally lifted from redis-rb



20
21
22
23
24
25
26
# File 'lib/fakeredis/zset.rb', line 20

def _floatify(str)
  if (( inf = str.to_s.match(/^([+-])?inf/i) ))
    (inf[1] == "-" ? -1.0 : 1.0) / 0.0
  else
    Float str
  end
end

#increment(key, val) ⇒ Object

Increments the value of key by val



9
10
11
# File 'lib/fakeredis/zset.rb', line 9

def increment(key, val)
  self[key] += _floatify(val)
end

#select_by_score(min, max) ⇒ Object



13
14
15
16
17
# File 'lib/fakeredis/zset.rb', line 13

def select_by_score min, max
  min = _floatify(min)
  max = _floatify(max)
  reject {|_,v| v < min || v > max }
end