Module: Protocol::Redis::Methods::SortedSets
- Defined in:
- lib/protocol/redis/methods/sorted_sets.rb
Instance Method Summary collapse
-
#zadd(key, score, member, *others, update: nil, change: false, increment: false) ⇒ Object
Add one or more members to a sorted set, or update its score if it already exists.
-
#zrange(key, start, stop, with_scores: false) ⇒ Object
Return a range of members in a sorted set, by index.
-
#zrem(key, member) ⇒ Object
Remove one or more members from a sorted set.
Instance Method Details
#zadd(key, score, member, *others, update: nil, change: false, increment: false) ⇒ Object
Add one or more members to a sorted set, or update its score if it already exists. O(log(N)) for each item added, where N is the number of elements in the sorted set.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/protocol/redis/methods/sorted_sets.rb', line 40 def zadd(key, score, member, *others, update: nil, change: false, increment: false) arguments = ["ZADD", key] if update == true arguments << "XX" elsif update == false arguments << "NX" end arguments << "CH" if change arguments << "INCR" if increment arguments << score << member arguments.concat(others) call(*arguments) end |
#zrange(key, start, stop, with_scores: false) ⇒ Object
Return a range of members in a sorted set, by index. O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements returned.
64 65 66 67 68 69 70 |
# File 'lib/protocol/redis/methods/sorted_sets.rb', line 64 def zrange(key, start, stop, with_scores: false) arguments = [start, stop] arguments << "WITHSCORES" if with_scores call("ZRANGE", key, *arguments) end |
#zrem(key, member) ⇒ Object
Remove one or more members from a sorted set. O(M*log(N)) with N being the number of elements in the sorted set and M the number of elements to be removed.
76 77 78 |
# File 'lib/protocol/redis/methods/sorted_sets.rb', line 76 def zrem(key, member) call("ZREM", key, member) end |