class Redis
def zadd(key, *args) #, options
-
(Boolean, Fixnum, Float)
-
Parameters:
-
options
(Hash
) -- -
args
([Float, String], Array<[Float, String]>
) -- -
key
(String
) --
Other tags:
- Example: Add an array of `[score, member]` pairs to a sorted set -
Example: Add a single `[score, member]` pair to a sorted set -
def zadd(key, *args) #, options zadd_options = [] if args.last.is_a?(Hash) options = args.pop nx = options[:nx] zadd_options << "NX" if nx xx = options[:xx] zadd_options << "XX" if xx ch = options[:ch] zadd_options << "CH" if ch incr = options[:incr] zadd_options << "INCR" if incr end synchronize do |client| if args.size == 1 && args[0].is_a?(Array) # Variadic: return float if INCR, integer if !INCR client.call([:zadd, key] + zadd_options + args[0], &(incr ? Floatify : nil)) elsif args.size == 2 # Single pair: return float if INCR, boolean if !INCR client.call([:zadd, key] + zadd_options + args, &(incr ? Floatify : Boolify)) else raise ArgumentError, "wrong number of arguments" end end end