Module: FakeRedis::Redis::SortedSetsMethods
Defined Under Namespace
Classes: CustomSortedSet, Elem
Instance Method Summary
collapse
-
#zadd(key, score, value) ⇒ Object
-
#zcard(key) ⇒ Object
-
#zcount(key, min, max) ⇒ Object
-
#zincrby(key, incr, value) ⇒ Object
-
#zrange(key, start, stop) ⇒ Object
-
#zrangescore(key, start, stop) ⇒ Object
-
#zrank(key, value) ⇒ Object
-
#zscore(key, value) ⇒ Object
Instance Method Details
#zadd(key, score, value) ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/fakeredis/sorted_sets.rb', line 30
def zadd(key, score, value)
fail_unless_sorted_set(key)
case set = @data[key]
when nil then @data[key] = CustomSortedSet.new([Elem.new(value.to_s, score)])
when CustomSortedSet then set.delete(value.to_s) ; set.add(Elem.new(value.to_s, score))
end
end
|
#zcard(key) ⇒ Object
38
39
40
41
42
43
44
|
# File 'lib/fakeredis/sorted_sets.rb', line 38
def zcard(key)
fail_unless_sorted_set(key)
case set = @data[key]
when nil then 0
when CustomSortedSet then set.size
end
end
|
#zcount(key, min, max) ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/fakeredis/sorted_sets.rb', line 46
def zcount(key, min, max)
fail_unless_sorted_set(key)
case set = @data[key]
when nil then 0
when CustomSortedSet then set.select{|x| x.score >= min && x.score <= max }.size
end
end
|
#zincrby(key, incr, value) ⇒ Object
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/fakeredis/sorted_sets.rb', line 54
def zincrby(key, incr, value)
fail_unless_sorted_set(key)
case set = @data[key]
when nil then @data[key] = CustomSortedSet.new([Elem.new(value.to_s, incr)])
when CustomSortedSet then
score = set.to_a.select{|x| x == value.to_s}.first.score
set.delete(value.to_s)
set.add(Elem.new(value.to_s, score+incr))
end
end
|
#zrange(key, start, stop) ⇒ Object
65
66
67
68
69
70
71
|
# File 'lib/fakeredis/sorted_sets.rb', line 65
def zrange(key, start, stop)
fail_unless_sorted_set(key)
case set = @data[key]
when nil then []
when CustomSortedSet then set.indexed_set.to_a[start..stop]
end
end
|
#zrangescore(key, start, stop) ⇒ Object
73
74
75
76
77
78
79
|
# File 'lib/fakeredis/sorted_sets.rb', line 73
def zrangescore(key, start, stop)
fail_unless_sorted_set(key)
case set = @data[key]
when nil then []
when CustomSortedSet then set.to_a.reverse[start..stop]
end
end
|
#zrank(key, value) ⇒ Object
81
82
83
84
85
86
87
|
# File 'lib/fakeredis/sorted_sets.rb', line 81
def zrank(key, value)
fail_unless_sorted_set(key)
case set = @data[key]
when nil then nil
when CustomSortedSet then set.to_a.index(value)
end
end
|
#zscore(key, value) ⇒ Object
89
90
91
92
93
94
|
# File 'lib/fakeredis/sorted_sets.rb', line 89
def zscore(key, value)
case set = @data[key]
when nil then 0
when CustomSortedSet then set.to_a.select{|x| x == value.to_s}.first.score
end
end
|