Ejemplo n.º 1
0
        /// <summary>
        /// 返回给定的有序集合键 <paramref name="key"/> 中,值介于 <paramref name="min"/> 和 <paramref name="max"/> 之间从低到高的顺序的成员。
        /// </summary>
        /// <param name="client">Redis 客户端。</param>
        /// <param name="key">有序集的键名</param>
        /// <param name="min">最小成员值。可以为 null 值,表示负无限。</param>
        /// <param name="max">最大成员值。可以为 null 值,表示正无限。</param>
        /// <param name="exclusiveMin">指示最小是否为开区间(true 时表示不含最小值)。</param>
        /// <param name="exclusiveMax">指示最大值是否为开区间(true 时表示不含最大值)。</param>
        /// <param name="offset">返回结果的偏移量。</param>
        /// <param name="count">返回结果的数量。</param>
        /// <returns>返回一个从低到高的顺序列表,列表里面包含了有序集合在指定范围内的成员。</returns>
        public static BinaryValue[] ZRangeByLex(this IRedisClient client, string key
                                                , BinaryValue min, BinaryValue max
                                                , bool exclusiveMin = false, bool exclusiveMax = false
                                                , long?offset       = null, long?count = null)
        {
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }
            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentNullException("key");
            }

            IEnumerable <object> args = new object[] { key
                                                       , RedisArgs.GetBinaryValue(min, exclusiveMin, "-")
                                                       , RedisArgs.GetBinaryValue(max, exclusiveMax, "+") };

            if (offset.HasValue && count.HasValue)
            {
                args = RedisArgs.ConcatAll(args, new[] { "LIMIT", offset.Value.ToString(), count.Value.ToString() });
            }

            return(client.Execute(RedisArray.Create(new RedisValue("ZRANGEBYLEX", args.ToArray()))));
        }
Ejemplo n.º 2
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.º 3
0
        /// <summary>
        /// 根据给定的 sha1 校验码,对缓存在服务器中的脚本进行求值。
        /// </summary>
        /// <param name="client">Redis 客户端。</param>
        /// <param name="sha1">sha1 校验码。</param>
        /// <param name="keyArgs">键名和参数值的字典。</param>
        /// <returns>返回执行脚本后的值。</returns>
        public static object EvalSHA(this IRedisClient client, string sha1, RedisDictionary keyArgs)
        {
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }
            if (string.IsNullOrEmpty(sha1))
            {
                throw new ArgumentNullException("sha1");
            }
            if (keyArgs == null)
            {
                throw new ArgumentNullException("keyArgs");
            }

            var args = RedisArgs.ConcatAll(new object[] { sha1, keyArgs.Keys.Count }, keyArgs.Keys, keyArgs.Values);

            return(client.Execute(new RedisObject("EVALSHA", args.ToArray())));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 执行 Lua 脚本进行求值。
        /// </summary>
        /// <param name="client">Redis 客户端。</param>
        /// <param name="script">Lua 脚本代码。</param>
        /// <param name="keyArgs">键名和参数值的字典。</param>
        /// <returns>执行脚本后的值。</returns>
        public static object Eval(this IRedisClient client, string script, RedisDictionary keyArgs)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }
            if (string.IsNullOrWhiteSpace(script))
            {
                throw new ArgumentNullException(nameof(script));
            }
            if (keyArgs == null)
            {
                throw new ArgumentNullException(nameof(keyArgs));
            }

            var args = RedisArgs.ConcatAll(new object[] { script, keyArgs.Keys.Count }, keyArgs.Keys, keyArgs.Values);

            return(client.Execute(new RedisObject("EVAL", args.ToArray())));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 返回有序集 <paramref name="key"/> 中,权重值在 <paramref name="min"/> 和 <paramref name="max"/> 之间的成员。
        /// <para>1、其中成员的位置按权重值递减(从大到小)来排列。</para>
        /// <para>2、具有相同权重值的成员按字典序的逆序(reverse lexicographical order)排列。</para>
        /// </summary>
        /// <param name="client">Redis 客户端。</param>
        /// <param name="key">有序集的键名。</param>
        /// <param name="min">权重最小值。<paramref name="min"/> 可以是 <see cref="Double.MinValue"/> -或- <see cref="Double.NegativeInfinity"/>,表示有序集的最小值。</param>
        /// <param name="max">权重最大值。<paramref name="max"/> 可以是 <see cref="Double.MaxValue"/> -或- <see cref="Double.PositiveInfinity"/>,表示有序集的最高值。</param>
        /// <param name="exclusiveMin">指示最小值是否为开区间(true 时表示不含最小值)。</param>
        /// <param name="exclusiveMax">指示最大值是否为开区间(true 时表示不含最大值)。</param>
        /// <param name="offset">返回结果的偏移量。</param>
        /// <param name="count">返回结果的数量。</param>
        /// <returns>权重值包含指定区间的成员。</returns>
        public static BinaryValue[] ZRevRangeByScore(this IRedisClient client, string key, double min, double max
                                                     , bool exclusiveMin = false, bool exclusiveMax = false
                                                     , long?offset       = null, long?count = null)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }
            if (string.IsNullOrWhiteSpace(key))
            {
                throw new ArgumentNullException(nameof(key));
            }
            IEnumerable <object> args = new object[] { key, RedisArgs.GetScore(min, exclusiveMin), RedisArgs.GetScore(max, exclusiveMax) };

            if (offset.HasValue && count.HasValue)
            {
                args = RedisArgs.ConcatAll(args, new[] { "LIMIT", offset.Value.ToString(), count.Value.ToString() });
            }
            return(client.Execute(RedisArray.Create(new RedisValue("ZREVRANGEBYSCORE", args.ToArray()))));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 返回有序集 <paramref name="key"/> 中,权重值在 <paramref name="min"/> 和 <paramref name="max"/> 之间的成员(含成员的权重值)。
        /// <para>1、其中成员的位置按权重值递减(从大到小)来排列。</para>
        /// <para>2、具有相同权重值的成员按字典序的逆序(reverse lexicographical order)排列。</para>
        /// </summary>
        /// <param name="client">Redis 客户端。</param>
        /// <param name="key">有序集的键名。</param>
        /// <param name="min">权重最小值。<paramref name="min"/> 可以是 <see cref="System.Double.MinValue"/> -或- <see cref="System.Double.NegativeInfinity"/>,表示有序集的最小值。</param>
        /// <param name="max">权重最大值。<paramref name="max"/> 可以是 <see cref="System.Double.MaxValue"/> -或- <see cref="System.Double.PositiveInfinity"/>,表示有序集的最高值。</param>
        /// <param name="exclusiveMin">指示最小值是否为开区间(true 时表示不含最小值)。</param>
        /// <param name="exclusiveMax">指示最大值是否为开区间(true 时表示不含最大值)。</param>
        /// <param name="offset">返回结果的偏移量。</param>
        /// <param name="count">返回结果的数量。</param>
        /// <returns>返回权重值包含指定区间的成员(含成员的权重值)。</returns>
        public static RedisScoreItem[] ZRevRangeByScoreWithScores(this IRedisClient client, string key, double min, double max
                                                                  , bool exclusiveMin = false, bool exclusiveMax = false
                                                                  , long?offset       = null, long?count = null)
        {
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }
            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentNullException("key");
            }

            IEnumerable <object> args = new object[] { key, RedisArgs.GetScore(min, exclusiveMin), RedisArgs.GetScore(max, exclusiveMax), "WITHSCORES" };

            if (offset.HasValue && count.HasValue)
            {
                args = RedisArgs.ConcatAll(args, new[] { "LIMIT", offset.Value.ToString(), count.Value.ToString() });
            }
            return(client.Execute(RedisArray.Create(new RedisItem <RedisScoreItem>(false, "ZREVRANGEBYSCORE", args.ToArray()), 2)));
        }