Method: Redis::Commands::SortedSets#zrangestore

Defined in:
lib/redis/commands/sorted_sets.rb

#zrangestore(dest_key, src_key, start, stop, byscore: false, by_score: byscore, bylex: false, by_lex: bylex, rev: false, limit: nil) ⇒ Integer

Select a range of members in a sorted set, by index, score or lexicographical ordering and store the resulting sorted set in a new key.

Examples:

redis.zadd("foo", [[1.0, "s1"], [2.0, "s2"], [3.0, "s3"]])
redis.zrangestore("bar", "foo", 0, 1)
  # => 2
redis.zrange("bar", 0, -1)
  # => ["s1", "s2"]

Returns:

  • (Integer)

    the number of elements in the resulting sorted set

See Also:



343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
# File 'lib/redis/commands/sorted_sets.rb', line 343

def zrangestore(dest_key, src_key, start, stop, byscore: false, by_score: byscore,
                bylex: false, by_lex: bylex, rev: false, limit: nil)
  if by_score && by_lex
    raise ArgumentError, "only one of :by_score or :by_lex can be specified"
  end

  args = [:zrangestore, dest_key, src_key, start, stop]

  if by_score
    args << "BYSCORE"
  elsif by_lex
    args << "BYLEX"
  end

  args << "REV" if rev

  if limit
    args << "LIMIT"
    args.concat(limit.map { |l| Integer(l) })
  end

  send_command(args)
end