Module: Protocol::Redis::Methods::SortedSets
- Defined in:
- lib/protocol/redis/methods/sorted_sets.rb
Instance Method Summary collapse
- 
  
    
      #bzpopmax(*keys, timeout: 0)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Remove and return the member with the highest score from one or more sorted sets, or block until one is available. 
- 
  
    
      #bzpopmin(*keys, timeout: 0)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Remove and return the member with the lowest score from one or more sorted sets, or block until one is available. 
- 
  
    
      #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. 
- 
  
    
      #zcard(key)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Get the number of members in a sorted set. 
- 
  
    
      #zcount(key, min, max)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Count the members in a sorted set with scores within the given values. 
- 
  
    
      #zincrby(key, increment, member)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Increment the score of a member in a sorted set. 
- 
  
    
      #zinterstore(destination, keys, weights = nil, aggregate: nil)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Intersect multiple sorted sets and store the resulting sorted set in a new key. 
- 
  
    
      #zlexcount(key, min, max)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Count the number of members in a sorted set between a given lexicographical range. 
- 
  
    
      #zpopmax(key, count = 1)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Remove and return members with the highest scores in a sorted set. 
- 
  
    
      #zpopmin(key, count = 1)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Remove and return members with the lowest scores in a sorted set. 
- 
  
    
      #zrange(key, start, stop, with_scores: false)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Return a range of members in a sorted set, by index. 
- 
  
    
      #zrangebylex(key, min, max, limit: nil)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Return a range of members in a sorted set, by lexicographical range. 
- 
  
    
      #zrangebyscore(key, min, max, with_scores: false, limit: nil)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Return a range of members in a sorted set, by score. 
- 
  
    
      #zrank(key, member)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Determine the index of a member in a sorted set. 
- 
  
    
      #zrem(key, member)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Remove one or more members from a sorted set. 
- 
  
    
      #zremrangebylex(key, min, max)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Remove all members in a sorted set between the given lexicographical range. 
- 
  
    
      #zremrangebyrank(key, start, stop)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Remove all members in a sorted set within the given indexes. 
- 
  
    
      #zremrangebyscore(key, min, max)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Remove all members in a sorted set within the given scores. 
- 
  
    
      #zrevrange(key, min, max, with_scores: false)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Return a range of members in a sorted set, by index, with scores ordered from high to low. 
- 
  
    
      #zrevrangebylex(key, min, max, limit: nil)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Return a range of members in a sorted set, by lexicographical range, ordered from higher to lower strings. 
- 
  
    
      #zrevrangebyscore(key, min, max, with_scores: false, limit: nil)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Return a range of members in a sorted set, by score, with scores ordered from high to low. 
- 
  
    
      #zrevrank(key, member)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Determine the index of a member in a sorted set, with scores ordered from high to low. 
- 
  
    
      #zscan(key, cursor = 0, match: nil, count: nil)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Incrementally iterate sorted sets elements and associated scores. 
- 
  
    
      #zscore(key, member)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Get the score associated with the given member in a sorted set. 
- 
  
    
      #zunionstore(*arguments)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Add multiple sorted sets and store the resulting sorted set in a new key. 
Instance Method Details
#bzpopmax(*keys, timeout: 0) ⇒ Object
Remove and return the member with the highest score from one or more sorted sets, or block until one is available. O(log(N)) with N being the number of elements in the sorted set.
| 40 41 42 | # File 'lib/protocol/redis/methods/sorted_sets.rb', line 40 def bzpopmax(*keys, timeout: 0) call("BZPOPMAX", *keys, timeout: 0) end | 
#bzpopmin(*keys, timeout: 0) ⇒ Object
Remove and return the member with the lowest score from one or more sorted sets, or block until one is available. O(log(N)) with N being the number of elements in the sorted set.
| 32 33 34 | # File 'lib/protocol/redis/methods/sorted_sets.rb', line 32 def bzpopmin(*keys, timeout: 0) call("BZPOPMIN", *keys, timeout) end | 
#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.
| 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | # File 'lib/protocol/redis/methods/sorted_sets.rb', line 56 def zadd(key, score, member, *others, update: nil, change: false, increment: false) arguments = ["ZADD", key] if update == true arguments.push("XX") elsif update == false arguments.push("NX") end arguments.push("CH") if change arguments.push("INCR") if increment arguments.push(score, member) arguments.push(*others) call(*arguments) end | 
#zcard(key) ⇒ Object
Get the number of members in a sorted set. O(1).
| 77 78 79 | # File 'lib/protocol/redis/methods/sorted_sets.rb', line 77 def zcard(key) call("ZCARD", key) end | 
#zcount(key, min, max) ⇒ Object
Count the members in a sorted set with scores within the given values. O(log(N)) with N being the number of elements in the sorted set.
| 86 87 88 | # File 'lib/protocol/redis/methods/sorted_sets.rb', line 86 def zcount(key, min, max) call("ZCOUNT", key, min, max) end | 
#zincrby(key, increment, member) ⇒ Object
Increment the score of a member in a sorted set. O(log(N)) where N is the number of elements in the sorted set.
| 95 96 97 | # File 'lib/protocol/redis/methods/sorted_sets.rb', line 95 def zincrby(key, increment, member) call("ZINCRBY", key, amount, member) end | 
#zinterstore(destination, keys, weights = nil, aggregate: nil) ⇒ Object
Intersect multiple sorted sets and store the resulting sorted set in a new key. O(N*K)+O(M*log(M)) worst case with N being the smallest input sorted set, K being the number of input sorted sets and M being the number of elements in the resulting sorted set.
| 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | # File 'lib/protocol/redis/methods/sorted_sets.rb', line 105 def zinterstore(destination, keys, weights = nil, aggregate: nil) arguments = [] if weights if weights.size != keys.size raise ArgumentError, "#{weights.size} weights given for #{keys.size} keys!" end arguments.push("WEIGHTS") arguments.concat(weights) end if aggregate arguments.push("AGGREGATE", aggregate) end call("ZINTERSTORE", destination, keys.size, *keys, *arguments) end | 
#zlexcount(key, min, max) ⇒ Object
Count the number of members in a sorted set between a given lexicographical range. O(log(N)) with N being the number of elements in the sorted set.
| 129 130 131 | # File 'lib/protocol/redis/methods/sorted_sets.rb', line 129 def zlexcount(key, min, max) call("ZLEXCOUNT", key, min, max) end | 
#zpopmax(key, count = 1) ⇒ Object
Remove and return members with the highest scores in a sorted set. O(log(N)*M) with N being the number of elements in the sorted set, and M being the number of elements popped.
| 137 138 139 | # File 'lib/protocol/redis/methods/sorted_sets.rb', line 137 def zpopmax(key, count = 1) call("ZPOPMAX", key, count) end | 
#zpopmin(key, count = 1) ⇒ Object
Remove and return members with the lowest scores in a sorted set. O(log(N)*M) with N being the number of elements in the sorted set, and M being the number of elements popped.
| 145 146 147 | # File 'lib/protocol/redis/methods/sorted_sets.rb', line 145 def zpopmin(key, count = 1) call("ZPOPMIN", key, count = 1) 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.
| 155 156 157 158 159 160 161 | # File 'lib/protocol/redis/methods/sorted_sets.rb', line 155 def zrange(key, start, stop, with_scores: false) arguments = [start, stop] arguments.push("WITHSCORES") if with_scores call("ZRANGE", key, *arguments) end | 
#zrangebylex(key, min, max, limit: nil) ⇒ Object
Return a range of members in a sorted set, by lexicographical range. O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements being returned. If M is constant (e.g. always asking for the first 10 elements with LIMIT), you can consider it O(log(N)).
| 169 170 171 172 173 174 175 | # File 'lib/protocol/redis/methods/sorted_sets.rb', line 169 def zrangebylex(key, min, max, limit: nil) if limit arguments = ["LIMIT", *limit] end call("ZRANGEBYLEX", key, min, max, *arguments) end | 
#zrangebyscore(key, min, max, with_scores: false, limit: nil) ⇒ Object
Return a range of members in a sorted set, by score. O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements being returned. If M is constant (e.g. always asking for the first 10 elements with LIMIT), you can consider it O(log(N)).
| 200 201 202 203 204 205 206 207 | # File 'lib/protocol/redis/methods/sorted_sets.rb', line 200 def zrangebyscore(key, min, max, with_scores: false, limit: nil) arguments = [min, max] arguments.push('WITHSCORES') if with_scores arguments.push('LIMIT', *limit) if limit call('ZRANGEBYSCORE', key, *arguments) end | 
#zrank(key, member) ⇒ Object
Determine the index of a member in a sorted set. O(log(N)).
| 213 214 215 | # File 'lib/protocol/redis/methods/sorted_sets.rb', line 213 def zrank(key, member) call("ZRANK", key, member) 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.
| 221 222 223 | # File 'lib/protocol/redis/methods/sorted_sets.rb', line 221 def zrem(key, member) call("ZREM", key, member) end | 
#zremrangebylex(key, min, max) ⇒ Object
Remove all members in a sorted set between the given lexicographical range. O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements removed by the operation.
| 230 231 232 | # File 'lib/protocol/redis/methods/sorted_sets.rb', line 230 def zremrangebylex(key, min, max) call("ZREMRANGEBYLEX", key, min, max) end | 
#zremrangebyrank(key, start, stop) ⇒ Object
Remove all members in a sorted set within the given indexes. O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements removed by the operation.
| 239 240 241 | # File 'lib/protocol/redis/methods/sorted_sets.rb', line 239 def zremrangebyrank(key, start, stop) call("ZREMRANGEBYRANK", key, start, stop) end | 
#zremrangebyscore(key, min, max) ⇒ Object
Remove all members in a sorted set within the given scores. O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements removed by the operation.
| 248 249 250 | # File 'lib/protocol/redis/methods/sorted_sets.rb', line 248 def zremrangebyscore(key, min, max) call("ZREMRANGEBYSCORE", key, min, max) end | 
#zrevrange(key, min, max, with_scores: false) ⇒ Object
Return a range of members in a sorted set, by index, with scores ordered from high to low. O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements returned.
| 258 259 260 261 262 263 264 | # File 'lib/protocol/redis/methods/sorted_sets.rb', line 258 def zrevrange(key, min, max, with_scores: false) arguments = [min, max] arguments.push('WITHSCORES') if with_scores call("ZREVRANGE", key, *arguments) end | 
#zrevrangebylex(key, min, max, limit: nil) ⇒ Object
Return a range of members in a sorted set, by lexicographical range, ordered from higher to lower strings. O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements being returned. If M is constant (e.g. always asking for the first 10 elements with LIMIT), you can consider it O(log(N)).
| 182 183 184 185 186 187 188 | # File 'lib/protocol/redis/methods/sorted_sets.rb', line 182 def zrevrangebylex(key, min, max, limit: nil) if limit arguments = ["LIMIT", *limit] end call("ZREVRANGEBYLEX", key, min, max, *arguments) end | 
#zrevrangebyscore(key, min, max, with_scores: false, limit: nil) ⇒ Object
Return a range of members in a sorted set, by score, with scores ordered from high to low. O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements being returned. If M is constant (e.g. always asking for the first 10 elements with LIMIT), you can consider it O(log(N)).
| 272 273 274 275 276 277 278 279 | # File 'lib/protocol/redis/methods/sorted_sets.rb', line 272 def zrevrangebyscore(key, min, max, with_scores: false, limit: nil) arguments = [min, max] arguments.push('WITHSCORES') if with_scores arguments.push('LIMIT', *limit) if limit call("ZREVRANGEBYSCORE", key, *arguments) end | 
#zrevrank(key, member) ⇒ Object
Determine the index of a member in a sorted set, with scores ordered from high to low. O(log(N)).
| 285 286 287 | # File 'lib/protocol/redis/methods/sorted_sets.rb', line 285 def zrevrank(key, member) call("ZREVRANK", key, member) end | 
#zscan(key, cursor = 0, match: nil, count: nil) ⇒ Object
Incrementally iterate sorted sets elements and associated scores. O(1) for every call. O(N) for a complete iteration, including enough command calls for the cursor to return back to 0. N is the number of elements inside the collection..
| 310 311 312 313 314 315 316 317 318 319 320 321 322 | # File 'lib/protocol/redis/methods/sorted_sets.rb', line 310 def zscan(key, cursor = 0, match: nil, count: nil) arguments = [key, cursor] if match arguments.push("MATCH", match) end if count arguments.push("COUNT", count) end call("ZSCAN", *arguments) end | 
#zscore(key, member) ⇒ Object
Get the score associated with the given member in a sorted set. O(1).
| 293 294 295 | # File 'lib/protocol/redis/methods/sorted_sets.rb', line 293 def zscore(key, member) call("ZSCORE", key, member) end | 
#zunionstore(*arguments) ⇒ Object
Add multiple sorted sets and store the resulting sorted set in a new key. O(N)+O(M log(M)) with N being the sum of the sizes of the input sorted sets, and M being the number of elements in the resulting sorted set.
| 302 303 304 | # File 'lib/protocol/redis/methods/sorted_sets.rb', line 302 def zunionstore(*arguments) call("ZUNIONSTORE", *arguments) end |