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())));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 阻塞式(blocking)移除并返回列表键的尾元素。
        /// </summary>
        /// <param name="client">Redis 客户端。</param>
        /// <param name="timeout">接受一个以秒为单位的数字作为值。超时参数设为 0 表示阻塞时间可以无限期延长(block indefinitely) 。</param>
        /// <param name="keys">按参数键的先后顺序依次检查各个列表,弹出第一个非空列表的尾元素。</param>
        /// <returns>在指定时间内,如果列表为空,返回一个 null。否则,返回一个含有键值的元素项。</returns>
        public static RedisKeyItem BRPop(this IRedisClient client, long timeout, params string[] keys)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }
            if (timeout < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(timeout));
            }
            if (keys == null)
            {
                throw new ArgumentNullException(nameof(keys));
            }
            if (keys.Length == 0)
            {
                return(null);
            }

            var args = RedisArgs.ConcatLast(keys, timeout).ToArray();

            return(client.Execute(new RedisItem <RedisKeyItem>(true, "BRPOP", args)));
        }