Module: RedisCluster::Function::SortedSet
- Included in:
- RedisCluster::Function
- Defined in:
- lib/redis_cluster/function/sorted_set.rb
Overview
SortedSet implement redis sorted set commands. There will be some adjustment for cluster. see redis.io/commands#sorted_set. Most of the code are copied from github.com/redis/redis-rb/blob/master/lib/redis.rb.
SETTER = [:zadd, :zincrby, :zrem, :zremrangebyrank, :zremrangebyscore] GETTER = [:zcard, :zscore, :zrange, :zrevrange, :zrank, :zrevrange, :zrangebylex,
:zrevrangebylex, :zrangebyscore, :zrevrangebyscore, :zcount]
Instance Method Summary collapse
-
#zadd(key, *args) ⇒ Boolean, ...
Add one or more members to a sorted set, or update the score for members that already exist.
-
#zcard(key) ⇒ Fixnum
Get the number of members in a sorted set.
-
#zcount(key, min, max) ⇒ Fixnum
Count the members in a sorted set with scores within the given values.
-
#zincrby(key, increment, member) ⇒ Float
Increment the score of a member in a sorted set.
-
#zrange(key, start, stop, options = {}) ⇒ Array<String>, Array<[String, Float]>
Return a range of members in a sorted set, by index.
-
#zrangebylex(key, min, max, options = {}) ⇒ Array<String>, Array<[String, Float]>
Return a range of members with the same score in a sorted set, by lexicographical ordering.
-
#zrangebyscore(key, min, max, options = {}) ⇒ Array<String>, Array<[String, Float]>
Return a range of members in a sorted set, by score.
-
#zrank(key, member) ⇒ Fixnum
Determine the index of a member in a sorted set.
-
#zrem(key, member) ⇒ Fixnum
Remove one or more members from a sorted set.
-
#zremrangebyrank(key, start, stop) ⇒ Fixnum
Remove all members in a sorted set within the given indexes.
-
#zremrangebyscore(key, min, max) ⇒ Fixnum
Remove all members in a sorted set within the given scores.
-
#zrevrange(key, start, stop, options = {}) ⇒ Object
Return a range of members in a sorted set, by index, with scores ordered from high to low.
-
#zrevrangebylex(key, max, min, options = {}) ⇒ Object
Return a range of members with the same score in a sorted set, by reversed lexicographical ordering.
-
#zrevrangebyscore(key, max, min, options = {}) ⇒ Object
Return a range of members in a sorted set, by score, with scores ordered from high to low.
-
#zrevrank(key, member) ⇒ Fixnum
Determine the index of a member in a sorted set, with scores ordered from high to low.
-
#zscore(key, member) ⇒ Float
Get the score associated with the given member in a sorted set.
Instance Method Details
#zadd(key, *args) ⇒ Boolean, ...
Add one or more members to a sorted set, or update the score for members that already exist.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/redis_cluster/function/sorted_set.rb', line 60 def zadd(key, *args) = [:zadd, key] if args.last.is_a?(::Hash) = args.pop incr = [:incr] << 'NX' if [:nx] << 'XX' if [:xx] << 'CH' if [:ch] << 'INCR' if incr end if args.size == 1 && args[0].is_a?(Array) # Variadic: return float if INCR, integer if !INCR call(key, + args[0], transform: (incr ? Redis::Floatify : nil)) elsif args.size == 2 # Single pair: return float if INCR, boolean if !INCR call(key, + args, transform: (incr ? Redis::Floatify : Redis::Boolify)) else raise ArgumentError, 'wrong number of arguments' end end |
#zcard(key) ⇒ Fixnum
Get the number of members in a sorted set.
25 26 27 |
# File 'lib/redis_cluster/function/sorted_set.rb', line 25 def zcard(key) call(key, [:zcard, key], read: true) end |
#zcount(key, min, max) ⇒ Fixnum
Count the members in a sorted set with scores within the given values.
371 372 373 |
# File 'lib/redis_cluster/function/sorted_set.rb', line 371 def zcount(key, min, max) call(key, [:zcount, key, min, max], read: true) end |
#zincrby(key, increment, member) ⇒ Float
Increment the score of a member in a sorted set.
93 94 95 |
# File 'lib/redis_cluster/function/sorted_set.rb', line 93 def zincrby(key, increment, member) call(key, [:zincrby, key, increment, member], transform: Redis::Floatify) end |
#zrange(key, start, stop, options = {}) ⇒ Array<String>, Array<[String, Float]>
Return a range of members in a sorted set, by index.
145 146 147 148 149 150 151 152 153 154 |
# File 'lib/redis_cluster/function/sorted_set.rb', line 145 def zrange(key, start, stop, = {}) args = [:zrange, key, start, stop] if [:withscores] args << 'WITHSCORES' block = Redis::FloatifyPairs end call(key, args, transform: block, read: true) end |
#zrangebylex(key, min, max, options = {}) ⇒ Array<String>, Array<[String, Float]>
Return a range of members with the same score in a sorted set, by lexicographical ordering
235 236 237 238 239 240 241 242 |
# File 'lib/redis_cluster/function/sorted_set.rb', line 235 def zrangebylex(key, min, max, = {}) args = [:zrangebylex, key, min, max] limit = [:limit] args.concat(['LIMIT'] + limit) if limit call(key, args, read: true) end |
#zrangebyscore(key, min, max, options = {}) ⇒ Array<String>, Array<[String, Float]>
Return a range of members in a sorted set, by score.
291 292 293 294 295 296 297 298 299 300 301 302 303 |
# File 'lib/redis_cluster/function/sorted_set.rb', line 291 def zrangebyscore(key, min, max, = {}) args = [:zrangebyscore, key, min, max] if [:withscores] args << 'WITHSCORES' block = Redis::FloatifyPairs end limit = [:limit] args.concat(['LIMIT'] + limit) if limit call(key, args, transform: block, read: true) end |
#zrank(key, member) ⇒ Fixnum
Determine the index of a member in a sorted set.
183 184 185 |
# File 'lib/redis_cluster/function/sorted_set.rb', line 183 def zrank(key, member) call(key, [:zrank, key, member], read: true) end |
#zrem(key, member) ⇒ Fixnum
Remove one or more members from a sorted set.
110 111 112 |
# File 'lib/redis_cluster/function/sorted_set.rb', line 110 def zrem(key, member) call(key, [:zrem, key, member]) end |
#zremrangebyrank(key, start, stop) ⇒ Fixnum
Remove all members in a sorted set within the given indexes.
210 211 212 |
# File 'lib/redis_cluster/function/sorted_set.rb', line 210 def zremrangebyrank(key, start, stop) call(key, [:zremrangebyrank, key, start, stop]) end |
#zremrangebyscore(key, min, max) ⇒ Fixnum
Remove all members in a sorted set within the given scores.
350 351 352 |
# File 'lib/redis_cluster/function/sorted_set.rb', line 350 def zremrangebyscore(key, min, max) call(key, [:zremrangebyscore, key, min, max]) end |
#zrevrange(key, start, stop, options = {}) ⇒ Object
Return a range of members in a sorted set, by index, with scores ordered from high to low.
167 168 169 170 171 172 173 174 175 176 |
# File 'lib/redis_cluster/function/sorted_set.rb', line 167 def zrevrange(key, start, stop, = {}) args = [:zrevrange, key, start, stop] if [:withscores] args << 'WITHSCORES' block = Redis::FloatifyPairs end call(key, args, transform: block, read: true) end |
#zrevrangebylex(key, max, min, options = {}) ⇒ Object
Return a range of members with the same score in a sorted set, by reversed lexicographical ordering. Apart from the reversed ordering, #zrevrangebylex is similar to #zrangebylex.
255 256 257 258 259 260 261 262 |
# File 'lib/redis_cluster/function/sorted_set.rb', line 255 def zrevrangebylex(key, max, min, = {}) args = [:zrevrangebylex, key, min, max] limit = [:limit] args.concat(['LIMIT'] + limit) if limit call(key, args, read: true) end |
#zrevrangebyscore(key, max, min, options = {}) ⇒ Object
Return a range of members in a sorted set, by score, with scores ordered from high to low.
319 320 321 322 323 324 325 326 327 328 329 330 331 |
# File 'lib/redis_cluster/function/sorted_set.rb', line 319 def zrevrangebyscore(key, max, min, = {}) args = [:zrevrangebyscore, key, min, max] if [:withscores] args << 'WITHSCORES' block = Redis::FloatifyPairs end limit = [:limit] args.concat(['LIMIT'] + limit) if limit call(key, args, transform: block, read: true) end |
#zrevrank(key, member) ⇒ Fixnum
Determine the index of a member in a sorted set, with scores ordered from high to low.
193 194 195 |
# File 'lib/redis_cluster/function/sorted_set.rb', line 193 def zrevrank(key, member) call(key, [:zrevrank, key, member], read: true) end |
#zscore(key, member) ⇒ Float
Get the score associated with the given member in a sorted set.
123 124 125 |
# File 'lib/redis_cluster/function/sorted_set.rb', line 123 def zscore(key, member) call(key, [:zscore, key, member], transform: Redis::Floatify, read: true) end |