Ejemplo n.º 1
0
        private static long ZStore(string command, IRedisClient client, string destination, RedisWeightDictionary keyWeights, RedisAggregate?aggregate)
        {
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }
            if (string.IsNullOrEmpty(destination))
            {
                throw new ArgumentNullException("destination");
            }
            if (keyWeights == null)
            {
                throw new ArgumentNullException("keyWeights");
            }
            if (keyWeights.Count == 0)
            {
                return(0L);
            }

            IEnumerable <object> args = new object[] { destination, keyWeights.Count };

            args = RedisArgs.ConcatAll(args, keyWeights.Keys);
            if (keyWeights.Values.Where(weight => weight != 1.0).Count() > 0)
            {
                args = RedisArgs.ConcatAll(RedisArgs.ConcatLast(args, "WEIGHTS"), keyWeights.Values.Cast <object>());
            }
            if (aggregate.HasValue)
            {
                args = RedisArgs.ConcatLasts(args, "AGGREGATE", aggregate.Value.ToString().ToUpperInvariant());
            }
            return(client.Execute(new RedisInteger(command, args.ToArray())));
        }