public static RedisInt ZCount(string key, double min, double max, bool exclusiveMin = false, bool exclusiveMax = false) { string min_score = RedisArgs.GetScore(min, exclusiveMin); string max_score = RedisArgs.GetScore(max, exclusiveMax); return(ZCount(key, min_score, max_score)); }
public static RedisArray.Strings ZRangeByScore(string key, double min, double max, bool withScores = false, bool exclusiveMin = false, bool exclusiveMax = false, long?offset = null, long?count = null) { string min_score = RedisArgs.GetScore(min, exclusiveMin); string max_score = RedisArgs.GetScore(max, exclusiveMax); return(ZRangeByScore(key, min_score, max_score, withScores, offset, count)); }
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()))); }
/// <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())))); }
public static RedisInt ZRemRangeByScore(string key, double min, double max, bool exclusiveMin = false, bool exclusiveMax = false) { string min_score = RedisArgs.GetScore(min, exclusiveMin); string max_score = RedisArgs.GetScore(max, exclusiveMax); return(new RedisInt("ZREMRANGEBYSCORE", key, min_score, max_score)); }
public static RedisArray.Tuples <string, double> ZRevRangeByScoreWithScores(string key, double max, double min, bool exclusiveMax = false, bool exclusiveMin = false, long?offset = null, long?count = null) { string min_score = RedisArgs.GetScore(min, exclusiveMin); string max_score = RedisArgs.GetScore(max, exclusiveMax); return(ZRevRangeByScoreWithScores(key, max_score, min_score, offset, count)); }
public static RedisStatus HMSet(string key, Dictionary <string, string> dict) { List <object> args = new List <object> { key }; args.AddRange(RedisArgs.FromDict(dict)); return(new RedisStatus("HMSET", args.ToArray())); }
public static RedisStatus HMSet <T>(string key, T obj) where T : class { List <object> args = new List <object> { key }; args.AddRange(RedisArgs.FromObject(obj)); return(new RedisStatus("HMSET", args.ToArray())); }
public static RedisArray.Tuples <string, double> ZRevRangeByScoreWithScores(string key, string max, string min, long?offset = null, long?count = null) { string[] args = new[] { key, max, min, "WITHSCORES" }; if (offset.HasValue && count.HasValue) { args = RedisArgs.Concat(args, new[] { "LIMIT", offset.Value.ToString(), count.Value.ToString() }); } return(new RedisArray.Tuples <string, double>("ZREVRANGEBYSCORE", args)); }
public static RedisArray.Strings ZRevRangeByScore(string key, string max, string min, bool withScores = false, long?offset = null, long?count = null) { string[] args = new[] { key, max, min }; if (withScores) { args = RedisArgs.Concat(args, new[] { "WITHSCORES" }); } if (offset.HasValue && count.HasValue) { args = RedisArgs.Concat(args, new[] { "LIMIT", offset.Value.ToString(), count.Value.ToString() }); } return(new RedisArray.Strings("ZREVRANGEBYSCORE", args)); }
/// <summary> /// 返回有序集 <paramref name="key"/> 中,权重值在 <paramref name="min"/> 和 <paramref name="max"/> 之间的成员的数量。 /// </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> /// <returns>返回权重值包含指定区间的成员数量。</returns> public static long ZCount(this IRedisClient client, string key, double min, double max, bool exclusiveMin = false, bool exclusiveMax = false) { if (client == null) { throw new ArgumentNullException("client"); } if (string.IsNullOrEmpty(key)) { throw new ArgumentNullException("key"); } return(client.Execute(new RedisInteger("ZCOUNT", key , RedisArgs.GetScore(min, exclusiveMin) , RedisArgs.GetScore(max, exclusiveMax)))); }
/// <summary> /// 移除有序集 <paramref name="key"/> 中,权重值在 <paramref name="min"/> 和 <paramref name="max"/> 之间的成员。 /// </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> /// <returns>被移除成员的数量。</returns> public static long ZRemRangeByScore(this IRedisClient client, string key, double min, double max, bool exclusiveMin = false, bool exclusiveMax = false) { if (client == null) { throw new ArgumentNullException(nameof(client)); } if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentNullException(nameof(key)); } return(client.Execute(new RedisInteger("ZREMRANGEBYSCORE", key , RedisArgs.GetScore(min, exclusiveMin) , RedisArgs.GetScore(max, exclusiveMax)))); }
/// <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> /// <returns>返回被移除的成员数量。</returns> public static long ZRemRangeByLex(this IRedisClient client, string key , BinaryValue min, BinaryValue max , bool exclusiveMin = false, bool exclusiveMax = false) { if (client == null) { throw new ArgumentNullException("client"); } if (string.IsNullOrEmpty(key)) { throw new ArgumentNullException("key"); } return(client.Execute(new RedisInteger("ZREMRANGEBYLEX", key , RedisArgs.GetBinaryValue(min, exclusiveMin, "-") , RedisArgs.GetBinaryValue(max, exclusiveMax, "+")))); }
/// <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> /// <returns>包含了有序集合在指定范围内的成员数量。</returns> public static long ZLexCount(this IRedisClient client, string key , BinaryValue min, BinaryValue max , bool exclusiveMin = false, bool exclusiveMax = false) { if (client == null) { throw new ArgumentNullException(nameof(client)); } if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentNullException(nameof(key)); } return(client.Execute(new RedisInteger("ZLEXCOUNT", key , RedisArgs.GetBinaryValue(min, exclusiveMin, "-") , RedisArgs.GetBinaryValue(max, exclusiveMax, "+")))); }
/// <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()))); }
/// <summary> /// 同时设置一个或多个键值。 /// </summary> /// <param name="client">Redis 客户端。</param> /// <param name="keyValues">键值的字典。</param> /// <returns>返回一个结果。</returns> public static Result MSet(this IRedisClient client, RedisDictionary keyValues) { if (client == null) { throw new ArgumentNullException("client"); } if (keyValues == null) { throw new ArgumentNullException("keyValues"); } if (keyValues.Count == 0) { return(Result.Successfully); } var args = RedisArgs.Parse(keyValues).ToArray(); return(client.Execute(new RedisStatus("MSET", args))); }
/// <summary> /// 将一个或多个值按从左到右的顺序依次插入到列表 <paramref name="key"/> 的表头。 /// <para>如果 <paramref name="key"/> 不存在,一个空列表会被创建并执行 LPUSH 操作。</para> /// </summary> /// <param name="client">Redis 客户端。</param> /// <param name="key">列表的键名。</param> /// <param name="values">值元素的数组。当数组长度为 0 时将会抛出异常。</param> /// <returns>返回执行命令列表的总长度。</returns> public static long LPush(this IRedisClient client, string key, params BinaryValue[] values) { if (client == null) { throw new ArgumentNullException("client"); } if (string.IsNullOrEmpty(key)) { throw new ArgumentNullException("key"); } if (values == null || values.Length == 0) { throw new ArgumentNullException("values"); } var args = RedisArgs.ConcatFirst(key, values).ToArray(); return(client.Execute(new RedisInteger("LPUSH", args))); }
/// <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()))); }
/// <summary> /// 同时设置哈希表 <paramref name="key"/> 中一个或多个域值。 /// </summary> /// <param name="client">Redis 客户端。</param> /// <param name="key">键名</param> /// <param name="fieldValues">域值的字典。</param> /// <returns>结果。</returns> public static Result HMSet(this IRedisClient client, string key, RedisDictionary fieldValues) { if (client == null) { throw new ArgumentNullException(nameof(client)); } if (fieldValues == null) { throw new ArgumentNullException(nameof(fieldValues)); } if (fieldValues.Count == 0) { return(Result.Successfully); } var args = RedisArgs.Parse(fieldValues, key).ToArray(); return(client.Execute(new RedisStatus("HMSET", args))); }
/// <summary> /// 将一个或多个值按从左到右的顺序依次插入到列表 <paramref name="key"/> 的表尾。 /// <para>当 <paramref name="key"/> 不存在时,RPUSHX 命令什么也不做。</para> /// </summary> /// <param name="client">Redis 客户端。</param> /// <param name="key">列表的键名。</param> /// <param name="values">值元素的数组。当数组长度为 0 时将会抛出异常。</param> /// <returns>执行命令列表的总长度。</returns> public static long RPushX(this IRedisClient client, string key, params BinaryValue[] values) { if (client == null) { throw new ArgumentNullException(nameof(client)); } if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentNullException(nameof(key)); } if (values == null || values.Length == 0) { throw new ArgumentNullException(nameof(values)); } var args = RedisArgs.ConcatFirst(key, values).ToArray(); return(client.Execute(new RedisInteger("RPUSHX", args))); }
/// <summary> /// 仅当所有给定键都不存在,同时设置一个或多个键值。即使只有一个给定键已存在,MSETNX 也会拒绝执行所有给定键的设置操作。 /// </summary> /// <param name="client">Redis 客户端。</param> /// <param name="keyValues">键值的字典。</param> /// <returns>当所有键都成功设置返回 true,否则返回 false。</returns> public static bool MSetNx(this IRedisClient client, RedisDictionary keyValues) { if (client == null) { throw new ArgumentNullException("client"); } if (keyValues == null) { throw new ArgumentNullException("keyValues"); } if (keyValues.Count == 0) { return(false); } var args = RedisArgs.Parse(keyValues).ToArray(); return(client.Execute(new RedisBoolean("MSETNX", args))); }
/// <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())))); }
/// <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))); }
/// <summary> /// 返回哈希表 <paramref name="key"/> 中一个或多个域的值。 /// </summary> /// <param name="client">Redis 客户端。</param> /// <param name="key">键名</param> /// <param name="fields">哈希表域的数组。</param> /// <returns>值的数组。如果给定的域里面,有某个域不存在,那么这个域对应的值为 null 值。</returns> public static BinaryValue[] HMGet(this IRedisClient client, string key, params string[] fields) { if (client == null) { throw new ArgumentNullException(nameof(client)); } if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentNullException(nameof(key)); } if (fields == null) { throw new ArgumentNullException(nameof(fields)); } if (fields.Length == 0) { return(new BinaryValue[0]); } var args = RedisArgs.ConcatFirst(key, fields).ToArray(); return(client.Execute(RedisArray.Create(new RedisValue("HMGET", args)))); }
/// <summary> /// 将任意数量的元素添加到指定的 HyperLogLog 里面。 /// </summary> /// <param name="client">Redis 客户端。</param> /// <param name="key">HyperLogLog 的键名。</param> /// <param name="elements">元素的数组。</param> /// <returns>返回一个值,如果 HyperLogLog 的内部储存被修改了,那么返回 true, 否则返回 false。</returns> public static bool PFAdd(this IRedisClient client, string key, params BinaryValue[] elements) { if (client == null) { throw new ArgumentNullException("client"); } if (string.IsNullOrEmpty(key)) { throw new ArgumentNullException("key"); } if (elements == null) { throw new ArgumentNullException("elements"); } if (elements.Length == 0) { return(false); } var args = RedisArgs.ConcatFirst(key, elements).ToArray(); return(client.Execute(new RedisBoolean("PFADD", args))); }
/// <summary> /// 将多个 HyperLogLog 合并(merge)为一个 HyperLogLog, 合并后的 HyperLogLog 的基数接近于所有输入 HyperLogLog 的可见集合(observed set)的并集。 /// </summary> /// <param name="client">Redis 客户端。</param> /// <param name="destKey">目标键名。合并得出的 HyperLogLog 会被储存在 <paramref name="destKey"/> 键里面,如果该键并不存在,那么命令在执行之前,会先为该键创建一个空的 HyperLogLog。</param> /// <param name="sourceKeys">源键名列表。</param> /// <returns>返回一个结果。</returns> public static Result PFMerge(this IRedisClient client, string destKey, params string[] sourceKeys) { if (client == null) { throw new ArgumentNullException("client"); } if (string.IsNullOrEmpty(destKey)) { throw new ArgumentNullException("destKey"); } if (sourceKeys == null) { throw new ArgumentNullException("elements"); } if (sourceKeys.Length == 0) { return(Result.SuccessedString); } var args = RedisArgs.ConcatFirst(destKey, sourceKeys).ToArray(); return(client.Execute(new RedisStatus("PFMERGE", args))); }
/// <summary> /// 移除集合 <paramref name="key"/> 中的一个或多成员,不存在的成员会被忽略。 /// </summary> /// <param name="client">Redis 客户端。</param> /// <param name="key">集合的键名。</param> /// <param name="members">成员的数组。</param> /// <returns>被成功移除的成员的数量,不包括被忽略的成员。</returns> public static long SRem(this IRedisClient client, string key, params BinaryValue[] members) { if (client == null) { throw new ArgumentNullException(nameof(client)); } if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentNullException(nameof(key)); } if (members == null) { throw new ArgumentNullException(nameof(members)); } if (members.Length == 0) { return(0L); } var args = RedisArgs.ConcatFirst(key, members).ToArray(); return(client.Execute(new RedisInteger("SREM", args))); }
/// <summary> /// 删除哈希表 <paramref name="key"/> 中的一个或多个指定域,不存在的域将被忽略。 /// </summary> /// <param name="client">Redis 客户端。</param> /// <param name="key">哈希表的键名。</param> /// <param name="fields">哈希表域的数组。</param> /// <returns>键成功被删除域的数量。</returns> public static long HDel(this IRedisClient client, string key, params string[] fields) { if (client == null) { throw new ArgumentNullException(nameof(client)); } if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentNullException(nameof(key)); } if (fields == null) { throw new ArgumentNullException(nameof(fields)); } if (fields.Length == 0) { return(0L); } var args = RedisArgs.ConcatFirst(key, fields).ToArray(); return(client.Execute(new RedisInteger("HDEL", args))); }
/// <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))); }
/// <summary> /// 将所有给定集合之间的差集保存到 <paramref name="destination"/> 集合。 /// </summary> /// <param name="client">Redis 客户端。</param> /// <param name="destination">目标集合。</param> /// <param name="keys">集合的键名数组。</param> /// <returns>结果集中的成员数量。</returns> public static long SDiffStore(this IRedisClient client, string destination, params string[] keys) { if (client == null) { throw new ArgumentNullException(nameof(client)); } if (string.IsNullOrWhiteSpace(destination)) { throw new ArgumentNullException(nameof(destination)); } if (keys == null) { throw new ArgumentNullException(nameof(keys)); } if (keys.Length == 0) { return(0); } var args = RedisArgs.ConcatFirst(destination, keys).ToArray(); return(client.Execute(new RedisInteger("SDIFFSTORE", args))); }