/// <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 ZCount(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("ZCOUNT", key , RedisArgs.GetScore(min, exclusiveMin) , RedisArgs.GetScore(max, exclusiveMax)))); }
/// <summary> /// 给定一个或多个脚本的 SHA1 校验和,表示校验和所指定的脚本是否已经被保存在缓存当中。 /// </summary> /// <param name="client">Redis 客户端。</param> /// <param name="scripts">sha1 校验码列表。</param> /// <returns>返回一个数组。脚本已经被保存在缓存当中为 true,否则为 false。</returns> public static bool[] ScriptExists(this IRedisClient client, params string[] scripts) { if (client == null) { throw new ArgumentNullException("client"); } if (scripts == null) { throw new ArgumentNullException("scripts"); } if (scripts.Length == 0) { return(new bool[0]); } return(client.Execute(RedisArray.Create(new RedisBoolean("SCRIPT EXISTS", scripts)))); }
/// <summary> /// 用 <paramref name="value"/> 参数覆写(overwrite)给定 <paramref name="key"/> 所储存的值,从偏移量 <paramref name="offset"/> 开始。 /// <para>不存在的 <paramref name="key"/> 当作空值处理。</para> /// </summary> /// <param name="client">Redis 客户端。</param> /// <param name="key">键名。</param> /// <param name="offset">偏移量。</param> /// <param name="value">覆盖的键值。</param> /// <returns>返回修改之后的字节总长度。</returns> public static long SetRange(this IRedisClient client, string key, long offset, BinaryValue value) { if (client == null) { throw new ArgumentNullException("client"); } if (string.IsNullOrEmpty(key)) { throw new ArgumentNullException("key"); } if (offset < 0) { throw new ArgumentOutOfRangeException("offset"); } return(client.Execute(new RedisInteger("SETRANGE", key, offset, value))); }
/// <summary> /// 返回一个或多个键的值。 /// </summary> /// <param name="client">Redis 客户端。</param> /// <param name="keys">键的数组。</param> /// <returns>返回值的数组。如果给定的键里面,有某个键不存在,那么这个键对应的值为 null 值 。</returns> public static BinaryValue[] MGet(this IRedisClient client, params string[] keys) { if (client == null) { throw new ArgumentNullException("client"); } if (keys == null) { throw new ArgumentNullException("keys"); } if (keys.Length == 0) { return(new BinaryValue[0]); } return(client.Execute(RedisArray.Create(new RedisValue("MGET", keys)))); }
/// <summary> /// 为当前连接分配一个名字。 /// </summary> /// <param name="client">Redis 客户端。</param> /// <param name="connectionName">用于识别当前正在与服务器进行连接的客户端名称。 /// <para>要移除一个连接的名字, 可以将连接的名字设为空字符串 "" 。</para> /// </param> /// <returns>结果。</returns> public static Result ClientSetName(this IRedisClient client, string connectionName) { if (client == null) { throw new ArgumentNullException(nameof(client)); } if (string.IsNullOrWhiteSpace(connectionName)) { throw new ArgumentNullException(nameof(connectionName)); } if (connectionName.Contains(' ')) { connectionName = connectionName.Replace(' ', '_'); } return(client.Execute(new RedisStatus("CLIENT SETNAME", connectionName))); }
/// <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> /// 将 <paramref name="value"/> 追加到 <paramref name="key"/> 原来的值的末尾。 /// </summary> /// <param name="client">Redis 客户端。</param> /// <param name="key">键名。</param> /// <param name="value">键值。</param> /// <returns>返回追加 <paramref name="value"/> 之后,<paramref name="key"/> 中的总字节长度。</returns> public static long Append(this IRedisClient client, string key, BinaryValue value) { if (client == null) { throw new ArgumentNullException("client"); } if (string.IsNullOrEmpty(key)) { throw new ArgumentNullException("key"); } if (value == null) { throw new ArgumentNullException("value"); } return(client.Execute(new RedisInteger("APPEND", key, value))); }
/// <summary> /// 返回哈希表 <paramref name="key"/> 所关联域的值。 /// </summary> /// <param name="client">Redis 客户端。</param> /// <param name="key">哈希表的键名。</param> /// <param name="field">键的域。</param> /// <returns>当 <paramref name="key"/> 的域不存在时,返回 null ,否则返回 <paramref name="key"/> 的域值。</returns> public static BinaryValue HGet(this IRedisClient client, string key, string field) { if (client == null) { throw new ArgumentNullException("client"); } if (string.IsNullOrEmpty(key)) { throw new ArgumentNullException("key"); } if (string.IsNullOrEmpty(field)) { throw new ArgumentNullException("field"); } return(client.Execute(new RedisValue("HGET", key, field))); }
/// <summary> /// 检查给定哈希表 <paramref name="key"/> 的域是否存在。 /// </summary> /// <param name="client">Redis 客户端。</param> /// <param name="key">哈希表的键名。</param> /// <param name="field">键的域。</param> /// <returns>如果 <paramref name="key"/> 的域存在,那么返回 true。否则返回 false。</returns> public static bool HExists(this IRedisClient client, string key, string field) { if (client == null) { throw new ArgumentNullException("client"); } if (string.IsNullOrEmpty(key)) { throw new ArgumentNullException("key"); } if (string.IsNullOrEmpty(field)) { throw new ArgumentNullException("field"); } return(client.Execute(new RedisBoolean("HEXISTS", key, field))); }
/// <summary> /// 将哈希表 <paramref name="key"/> 中储存给定的域 <paramref name="field"/> 的数字值递增指定的 <paramref name="increment"/> 数值。 /// </summary> /// <param name="client">Redis 客户端。</param> /// <param name="key">哈希表的键名。</param> /// <param name="field">键的域。</param> /// <param name="increment">递增量。</param> /// <returns>返回递增 <paramref name="increment"/> 之后 <paramref name="key"/> 的域 <paramref name="field"/> 的值。</returns> public static long HIncrBy(this IRedisClient client, string key, string field, long increment = 1) { if (client == null) { throw new ArgumentNullException("client"); } if (string.IsNullOrEmpty(key)) { throw new ArgumentNullException("key"); } if (string.IsNullOrEmpty(field)) { throw new ArgumentNullException("field"); } return(client.Execute(new RedisInteger("HINCRBY", key, field, increment))); }
/// <summary> /// 为有序集 <paramref name="key"/> 的成员 <paramref name="member"/> 的权重值加上增量 <paramref name="increment"/>。 /// </summary> /// <param name="client">Redis 客户端。</param> /// <param name="key">有序集的键名。</param> /// <param name="increment">递增量。可以通过传递一个负数值 <paramref name="increment"/> ,让权重减去相应的值。</param> /// <param name="member">有序集的成员。</param> /// <returns>返回递增 <paramref name="increment"/> 之后 <paramref name="key"/> 的 <paramref name="member"/> 的权重值。</returns> public static double ZIncrBy(this IRedisClient client, string key, double increment, BinaryValue member) { if (client == null) { throw new ArgumentNullException("client"); } if (string.IsNullOrEmpty(key)) { throw new ArgumentNullException("key"); } if (member == null) { throw new ArgumentNullException("member"); } return(client.Execute(new RedisFloat("ZINCRBY", key, increment, member))); }
/// <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="member"/> 的权重值。 /// </summary> /// <param name="client">Redis 客户端。</param> /// <param name="key">有序集的键名。</param> /// <param name="member">有序集的成员。</param> /// <returns>如果 <paramref name="member"/> 是有序集 <paramref name="key"/> 的成员,返回 <paramref name="member"/> 的权重值。否则返回 null 值。</returns> public static double?ZScore(this IRedisClient client, string key, BinaryValue member) { if (client == null) { throw new ArgumentNullException("client"); } if (string.IsNullOrEmpty(key)) { throw new ArgumentNullException("key"); } if (member == null) { throw new ArgumentNullException("member"); } return(client.Execute(new RedisFloat.Nullable("ZSCORE", key, member))); }
/// <summary> /// 返回有序集 <paramref name="key"/> 中成员 <paramref name="member"/> 的排名。其中有序集成员按权重值递减(从大到小)顺序排列。 /// </summary> /// <param name="client">Redis 客户端。</param> /// <param name="key">有序集的键名。</param> /// <param name="member">有序集的成员。</param> /// <returns>如果 <paramref name="member"/> 是有序集 <paramref name="key"/> 的成员,返回 <paramref name="member"/> 的排名。否则返回 null 值。</returns> public static long?ZRevRank(this IRedisClient client, string key, BinaryValue member) { if (client == null) { throw new ArgumentNullException("client"); } if (string.IsNullOrEmpty(key)) { throw new ArgumentNullException("key"); } if (member == null) { throw new ArgumentNullException("member"); } return(client.Execute(new RedisInteger.Nullable("ZREVRANK", key, member))); }
/// <summary> /// 返回储存在给定键(或给定键数组的并集)的 HyperLogLog 的近似基数。 /// </summary> /// <param name="client">Redis 客户端。</param> /// <param name="keys">HyperLogLog 的键名数组。</param> /// <returns>给定单个键时,返回储存在给定键的 HyperLogLog 的近似基数。给定多个键时,返回所有给定 HyperLogLog 的并集的近似基数,这个近似基数是通过将所有给定 HyperLogLog 合并至一个临时 HyperLogLog 来计算得出的。</returns> public static long PFCount(this IRedisClient client, params string[] keys) { if (client == null) { throw new ArgumentNullException(nameof(client)); } if (keys == null) { throw new ArgumentNullException(nameof(keys)); } if (keys.Length == 0) { return(0); } return(client.Execute(new RedisInteger("PFCOUNT", keys))); }
/// <summary> /// 将列表 <paramref name="source"/> 中的尾元素弹出,并返回给客户端。并将 <paramref name="source"/> 弹出的元素插入到列表 <paramref name="destination"/> ,作为 <paramref name="destination"/> 列表的的头元素。 /// </summary> /// <param name="client">Redis 客户端。</param> /// <param name="source">源列表。</param> /// <param name="destination">目标列表。</param> /// <returns>如果列表为空,返回一个 null。否则,返回元素项的值。</returns> public static BinaryValue RPopLPush(this IRedisClient client, string source, string destination) { if (client == null) { throw new ArgumentNullException("client"); } if (string.IsNullOrEmpty(source)) { throw new ArgumentNullException("source"); } if (string.IsNullOrEmpty(destination)) { throw new ArgumentNullException("destination"); } return(client.Execute(new RedisValue("RPOPLPUSH", source, destination))); }
/// <summary> /// 将当前数据库的 <paramref name="key"/> 移动到给定的数据库 <paramref name="database"/> 当中。 /// <para>1、若源数据库不存在 <paramref name="key"/>,移动将会失败。</para> /// <para>2、若目标数据库已存在 <paramref name="key"/>,移动将会失败。</para> /// </summary> /// <param name="client">Redis 客户端。</param> /// <param name="key">键名。</param> /// <param name="database">目标数据库索引。</param> /// <returns>如果移动成功返回 true,否则返回 false。</returns> public static bool Move(this IRedisClient client, string key, int database) { if (client == null) { throw new ArgumentNullException("client"); } if (string.IsNullOrEmpty(key)) { throw new ArgumentNullException("key"); } if (database < 0) { throw new ArgumentOutOfRangeException("database"); } return(client.Execute(new RedisBoolean("MOVE", key, database))); }
/// <summary> /// 返回有序集 <paramref name="key"/> 中成员 <paramref name="member"/> 的排名。其中有序集成员按权重值递增(从小到大)顺序排列。 /// </summary> /// <param name="client">Redis 客户端。</param> /// <param name="key">有序集的键名。</param> /// <param name="member">有序集的成员。</param> /// <returns>如果 <paramref name="member"/> 是有序集 <paramref name="key"/> 的成员,返回 <paramref name="member"/> 的排名。否则返回 null 值。</returns> public static long?ZRank(this IRedisClient client, string key, BinaryValue member) { if (client == null) { throw new ArgumentNullException(nameof(client)); } if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentNullException(nameof(key)); } if (member == null) { throw new ArgumentNullException(nameof(member)); } return(client.Execute(new RedisInteger.Nullable("ZRANK", key, member))); }
/// <summary> /// 返回一个集合的全部成员,该集合是所有给定集合之间的差集。 /// </summary> /// <param name="client">Redis 客户端。</param> /// <param name="keys">集合的键名数组。</param> /// <returns>包含差集成员列表。</returns> public static BinaryValue[] SDiff(this IRedisClient client, params string[] keys) { if (client == null) { throw new ArgumentNullException(nameof(client)); } if (keys == null) { throw new ArgumentNullException(nameof(keys)); } if (keys.Length == 0) { return(new BinaryValue[0]); } return(client.Execute(RedisArray.Create(new RedisValue("SDIFF", keys)))); }
/// <summary> /// 删除给定的一个或多个键。不存在的键会被忽略。 /// </summary> /// <param name="client">Redis 客户端。</param> /// <param name="keys">键的数组。</param> /// <returns>返回被删除键的数量。</returns> public static long Del(this IRedisClient client, params string[] keys) { if (client == null) { throw new ArgumentNullException("client"); } if (keys == null) { throw new ArgumentNullException("keys"); } if (keys.Length == 0) { return(0L); } return(client.Execute(new RedisInteger("DEL", keys))); }
/// <summary> /// 返回哈希表 <paramref name="key"/> 所关联域的值。 /// </summary> /// <param name="client">Redis 客户端。</param> /// <param name="key">哈希表的键名。</param> /// <param name="field">键的域。</param> /// <returns>当 <paramref name="key"/> 的域不存在时,返回 null ,否则返回 <paramref name="key"/> 的域值。</returns> public static BinaryValue HGet(this IRedisClient client, string key, string field) { if (client == null) { throw new ArgumentNullException(nameof(client)); } if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentNullException(nameof(key)); } if (string.IsNullOrWhiteSpace(field)) { throw new ArgumentNullException(nameof(field)); } return(client.Execute(new RedisValue("HGET", key, field))); }
/// <summary> /// 将 <paramref name="member"/> 从 <paramref name="source"/> 集合移动到 <paramref name="destination"/> 集合。 /// </summary> /// <param name="client">Redis 客户端。</param> /// <param name="source">源集合。</param> /// <param name="destination">目标集合。</param> /// <param name="member">移动的成员。</param> /// <returns>表示移动是否成功。</returns> public static bool SMove(this IRedisClient client, string source, string destination, BinaryValue member) { if (client == null) { throw new ArgumentNullException(nameof(client)); } if (string.IsNullOrWhiteSpace(source)) { throw new ArgumentNullException(nameof(source)); } if (string.IsNullOrWhiteSpace(destination)) { throw new ArgumentNullException(nameof(destination)); } return(client.Execute(new RedisBoolean("SMOVE", source, destination, member))); }
/// <summary> /// 将哈希表 <paramref name="key"/> 中储存给定的域 <paramref name="field"/> 的数字值递减指定的 <paramref name="decrement"/> 数值。 /// </summary> /// <param name="client">Redis 客户端。</param> /// <param name="key">哈希表的键名。</param> /// <param name="field">键的域。</param> /// <param name="decrement">递减量。</param> /// <returns>递减 <paramref name="decrement"/> 之后 <paramref name="key"/> 的域 <paramref name="field"/> 的值。</returns> public static long HDecrBy(this IRedisClient client, string key, string field, long decrement = 1) { if (client == null) { throw new ArgumentNullException(nameof(client)); } if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentNullException(nameof(key)); } if (string.IsNullOrWhiteSpace(field)) { throw new ArgumentNullException(nameof(field)); } return(client.Execute(new RedisInteger("HINCRBY", key, field, -decrement))); }
/// <summary> /// 检查给定哈希表 <paramref name="key"/> 的域是否存在。 /// </summary> /// <param name="client">Redis 客户端。</param> /// <param name="key">哈希表的键名。</param> /// <param name="field">键的域。</param> /// <returns>如果 <paramref name="key"/> 的域存在,那么返回 true。否则返回 false。</returns> public static bool HExists(this IRedisClient client, string key, string field) { if (client == null) { throw new ArgumentNullException(nameof(client)); } if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentNullException(nameof(key)); } if (string.IsNullOrWhiteSpace(field)) { throw new ArgumentNullException(nameof(field)); } return(client.Execute(new RedisBoolean("HEXISTS", key, field))); }
/// <summary> /// 将列表 <paramref name="source"/> 中的尾元素弹出,并返回给客户端。并将 <paramref name="source"/> 弹出的元素插入到列表 <paramref name="destination"/> ,作为 <paramref name="destination"/> 列表的的头元素。 /// </summary> /// <param name="client">Redis 客户端。</param> /// <param name="source">源列表。</param> /// <param name="destination">目标列表。</param> /// <returns>如果列表为空,返回一个 null。否则,返回元素项的值。</returns> public static BinaryValue RPopLPush(this IRedisClient client, string source, string destination) { if (client == null) { throw new ArgumentNullException(nameof(client)); } if (string.IsNullOrWhiteSpace(source)) { throw new ArgumentNullException(nameof(source)); } if (string.IsNullOrWhiteSpace(destination)) { throw new ArgumentNullException(nameof(destination)); } return(client.Execute(new RedisValue("RPOPLPUSH", source, destination))); }
/// <summary> /// 将值 <paramref name="value"/> 插入到列表 <paramref name="key"/> 当中,位于值 <paramref name="pivot"/> 之前或之后。 /// </summary> /// <param name="client">Redis 客户端。</param> /// <param name="key">列表的键名。</param> /// <param name="position">插入的位置。</param> /// <param name="pivot">定位的支点键名。</param> /// <param name="value">插入的值。</param> /// <returns>插入的结果。</returns> public static long LInsert(this IRedisClient client, string key, RedisInsertPosition position, string pivot, BinaryValue value) { if (client == null) { throw new ArgumentNullException(nameof(client)); } if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentNullException(nameof(key)); } if (string.IsNullOrWhiteSpace(pivot)) { throw new ArgumentNullException(nameof(pivot)); } return(client.Execute(new RedisInteger("LINSERT", key , position == RedisInsertPosition.Before ? "BEFORE" : "AFTER" , pivot, value))); }
/// <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))); }
private static long ZStore(string command, IRedisClient client, string destination, RedisWeightDictionary keyWeights, RedisAggregate? aggregate) { if(client == null) throw new ArgumentNullException(nameof(client)); if(string.IsNullOrWhiteSpace(destination)) throw new ArgumentNullException(nameof(destination)); if(keyWeights == null) throw new ArgumentNullException(nameof(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())); }