diff --git "a/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/.vs/Common.Utility/v16/.suo" "b/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/.vs/Common.Utility/v16/.suo"
index 19c463c..3d4c7b8 100644
Binary files "a/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/.vs/Common.Utility/v16/.suo" and "b/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/.vs/Common.Utility/v16/.suo" differ
diff --git "a/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/.vs/Common.Utility/v16/Server/sqlite3/storage.ide" "b/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/.vs/Common.Utility/v16/Server/sqlite3/storage.ide"
index 44dd7b7..6170a05 100644
Binary files "a/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/.vs/Common.Utility/v16/Server/sqlite3/storage.ide" and "b/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/.vs/Common.Utility/v16/Server/sqlite3/storage.ide" differ
diff --git "a/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/.vs/Common.Utility/v16/Server/sqlite3/storage.ide-shm" "b/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/.vs/Common.Utility/v16/Server/sqlite3/storage.ide-shm"
index 65ef565..054ec39 100644
Binary files "a/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/.vs/Common.Utility/v16/Server/sqlite3/storage.ide-shm" and "b/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/.vs/Common.Utility/v16/Server/sqlite3/storage.ide-shm" differ
diff --git "a/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/.vs/Common.Utility/v16/Server/sqlite3/storage.ide-wal" "b/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/.vs/Common.Utility/v16/Server/sqlite3/storage.ide-wal"
index c75f89a..969ea1e 100644
Binary files "a/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/.vs/Common.Utility/v16/Server/sqlite3/storage.ide-wal" and "b/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/.vs/Common.Utility/v16/Server/sqlite3/storage.ide-wal" differ
diff --git "a/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/Common.Utility.csproj" "b/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/Common.Utility.csproj"
index cdc3f8c..c8fe98c 100644
--- "a/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/Common.Utility.csproj"
+++ "b/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/Common.Utility.csproj"
@@ -130,6 +130,9 @@
packages\Quartz.2.4.1\lib\net40\Quartz.dll
True
+
+ F:\Github\Test\RedisSomeHelper\bin\Debug\RedisSomeHelper.exe
+
packages\Microsoft.ReportingServices.ReportViewerControl.WebForms.150.1358.0\lib\net40\Seagull.BarTender.Print.dll
@@ -147,8 +150,7 @@
False
- bin\Debug\StackExchange.Redis.dll
- False
+ F:\Github\Test\RedisSomeHelper\bin\Debug\StackExchange.Redis.dll
diff --git "a/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/RedisHelper/RedisHelper.cs" "b/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/RedisHelper/RedisHelper.cs"
deleted file mode 100644
index 123a30f..0000000
--- "a/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/RedisHelper/RedisHelper.cs"
+++ /dev/null
@@ -1,1153 +0,0 @@
-using StackExchange.Redis;
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Runtime.Serialization;
-using System.Runtime.Serialization.Formatters.Binary;
-using System.Text;
-using System.Threading.Tasks;
-using System.Configuration;
-
-
-namespace DotNet.Utilities.RedisHelper
-{
- ///
- /// 这是一个手动封装的完整RedisHelper
- ///
- public class RedisHelper
- {
- ///
- /// 连接字符串
- ///
- private static readonly string ConnectionString;
- ///
- /// redis 连接对象
- ///
- private static IConnectionMultiplexer _connMultiplexer;
- ///
- /// 默认的key值(用来当作RedisKey的前缀)
- ///
- public static string DefaultKey { get; private set; }
- ///
- /// 锁tomcat
- ///
- private static readonly object Locker = new object();
- ///
- /// 数据库访问对象
- ///
- private readonly IDatabase _db;
- ///
- /// 采用双重锁单例模式,保证数据访问对象有且仅有一个
- ///
- ///
- public IConnectionMultiplexer GetConnectionRedisMultiplexer()
- {
- if ((_connMultiplexer == null || !_connMultiplexer.IsConnected))
- {
- lock (Locker)
- {
- if ((_connMultiplexer == null || !_connMultiplexer.IsConnected))
- {
- _connMultiplexer = ConnectionMultiplexer.Connect(ConnectionString);
- }
- }
- }
- return _connMultiplexer;
- }
- ///
- /// 添加事务处理
- ///
- ///
- public ITransaction GetTransaction()
- {
- //创建事务
- return _db.CreateTransaction();
- }
-
- #region 构造函数
- ///
- /// 静态的构造函数,
- /// 构造函数是属于类的,而不是属于实例的
- /// 就是说这个构造函数只会被执行一次。也就是在创建第一个实例或引用任何静态成员之前,由.NET自动调用。
- ///
- static RedisHelper()
- {
- ConnectionString = "127.0.0.1:6375";
- _connMultiplexer = ConnectionMultiplexer.Connect(ConnectionString);
- DefaultKey = "finchina";
- RegisterEvent();
- }
- ///
- /// 重载构造器,获取redis内部数据库的交互式连接
- ///
- /// 要获取的数据库ID
- public RedisHelper(int db = -1)
- {
- _db = _connMultiplexer.GetDatabase(db);
- }
- #endregion
-
- #region 通用方法
- ///
- /// 添加 key 的前缀
- ///
- ///
- ///
- private static string AddKeyPrefix(string key)
- {
- return $"{DefaultKey}:{key}";
- }
- ///
- /// 序列化,用于存储对象
- ///
- ///
- ///
- private static byte[] Serialize(object obj)
- {
- try
- {
- if (obj == null)
- return null;
- var binaryFormatter = new BinaryFormatter();
- using (var memoryStream = new MemoryStream())
- {
- binaryFormatter.Serialize(memoryStream, obj);
- var data = memoryStream.ToArray();
- return data;
- }
- }
- catch (SerializationException ex)
- {
- throw ex;
- }
- }
- ///
- /// 反序列化,用于解码对象
- ///
- ///
- ///
- ///
- private static T Deserialize(byte[] data)
- {
- if (data == null)
- return default(T);
- var binaryFormatter = new BinaryFormatter();
- using (var memoryStream = new MemoryStream(data))
- {
- var result = (T)binaryFormatter.Deserialize(memoryStream);
- return result;
- }
- }
- #endregion
-
- #region stringGet
- ///
- /// 设置key,并保存字符串(如果key 已存在,则覆盖)
- ///
- ///
- ///
- ///
- ///
- public bool StringSet(string redisKey, string redisValue, TimeSpan? expried = null)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.StringSet(redisKey, redisValue, expried);
- }
- ///
- /// 保存多个key-value
- ///
- ///
- ///
- public bool StringSet(IEnumerable> keyValuePairs)
- {
- keyValuePairs =
- keyValuePairs.Select(x => new KeyValuePair(AddKeyPrefix(x.Key), x.Value));
- return _db.StringSet(keyValuePairs.ToArray());
- }
- ///
- /// 获取字符串
- ///
- ///
- ///
- ///
- public string StringGet(string redisKey, TimeSpan? expired = null)
- {
- try
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.StringGet(redisKey);
- }
- catch (TypeAccessException ex)
- {
- throw ex;
- }
- }
- ///
- /// 存储一个对象,该对象会被序列化存储
- ///
- ///
- ///
- ///
- ///
- ///
- public bool StringSet(string redisKey, T redisValue, TimeSpan? expired = null)
- {
- redisKey = AddKeyPrefix(redisKey);
- var json = Serialize(redisKey);
- return _db.StringSet(redisKey, json, expired);
- }
- ///
- /// 获取一个对象(会进行反序列化)
- ///
- ///
- ///
- ///
- ///
- public T StringSet(string redisKey, TimeSpan? expired = null)
- {
- redisKey = AddKeyPrefix(redisKey);
- return Deserialize(_db.StringGet(redisKey));
- }
-
- ///
- /// 保存一个字符串值
- ///
- ///
- ///
- ///
- ///
- public async Task StringSetAddKeyPrefix(string redisKey, string redisValue, TimeSpan? expired = null)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.StringSet(redisKey, redisValue, expired);
- }
- ///
- /// 保存一个字符串值
- ///
- ///
- ///
- public async Task StringSetkeyValuePairs(IEnumerable> keyValuePairs)
- {
- keyValuePairs
- = keyValuePairs.Select(x => new KeyValuePair(AddKeyPrefix(x.Key), x.Value));
- return _db.StringSet(keyValuePairs.ToArray());
- }
- ///
- /// 获取单个值
- ///
- ///
- ///
- ///
- ///
- public async Task StringGet(string redisKey, string redisValue, TimeSpan? expired = null)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.StringGet(redisKey);
- }
- ///
- /// 存储一个对象(该对象会被序列化保存)
- ///
- ///
- ///
- ///
- ///
- ///
- public async Task StringSet(string redisKey, string redisValue, TimeSpan? expired = null)
- {
- redisKey = AddKeyPrefix(redisKey);
- var json = Serialize(redisValue);
- return _db.StringSet(redisKey, json, expired);
- }
- ///
- /// 获取一个对象(反序列化)
- ///
- ///
- ///
- ///
- ///
- ///
- public async Task StringGet(string redisKey, string redisValue, TimeSpan? expired = null)
- {
- redisKey = AddKeyPrefix(redisKey);
- return Deserialize( _db.StringGet(redisKey));
- }
- #endregion
-
- #region Hash
- ///
- /// 判断字段是否在hash中
- ///
- ///
- ///
- ///
- public bool HashExist(string redisKey, string hashField)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.HashExists(redisKey, hashField);
- }
- ///
- /// 从hash 中删除字段
- ///
- ///
- ///
- ///
- public bool HashDelete(string redisKey, string hashField)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.HashDelete(redisKey, hashField);
- }
- ///
- /// 从hash中移除指定字段
- ///
- ///
- ///
- ///
- public long HashDelete(string redisKey, IEnumerable hashField)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.HashDelete(redisKey, hashField.ToArray());
- }
- ///
- /// 在hash中设定值
- ///
- ///
- ///
- ///
- ///
- public bool HashSet(string redisKey, string hashField, string value)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.HashSet(redisKey, hashField, value);
- }
- ///
- /// 从Hash 中获取值
- ///
- ///
- ///
- ///
- public RedisValue HashGet(string redisKey, string hashField)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.HashGet(redisKey, hashField);
- }
- ///
- /// 从Hash 中获取值
- ///
- ///
- ///
- ///
- public RedisValue[] HashGet(string redisKey, RedisValue[] hashField)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.HashGet(redisKey, hashField);
- }
- ///
- /// 从hash 返回所有的key值
- ///
- ///
- ///
- public IEnumerable HashKeys(string redisKey)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.HashKeys(redisKey);
- }
- ///
- /// 根据key返回hash中的值
- ///
- ///
- ///
- public RedisValue[] HashValues(string redisKey)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.HashValues(redisKey);
- }
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- public bool HashSet(string redisKey, string hashField, T value)
- {
- redisKey = AddKeyPrefix(redisKey);
- var json = Serialize(value);
- return _db.HashSet(redisKey, hashField, json);
- }
- ///
- /// 在hash 中获取值 (反序列化)
- ///
- ///
- ///
- ///
- ///
- public T HashGet(string redisKey, string hashField)
- {
- redisKey = AddKeyPrefix(redisKey);
- return Deserialize(_db.HashGet(redisKey, hashField));
- }
- ///
- /// 判断字段是否存在hash 中
- ///
- ///
- ///
- ///
- public async Task HashExists(string redisKey, string hashField)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.HashExists(redisKey, hashField);
- }
- ///
- /// 从hash中移除指定字段
- ///
- ///
- ///
- ///
- public async Task HashDeleteByRedisKey(string redisKey, string hashField)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.HashDelete(redisKey, hashField);
- }
- ///
- /// 从hash中移除指定字段
- ///
- ///
- ///
- ///
- public async Task HashDeleteByRedisKey(string redisKey, IEnumerable hashField)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.HashDelete(redisKey, hashField.ToArray());
- }
- ///
- /// 在hash 设置值
- ///
- ///
- ///
- ///
- ///
- public async Task HashSetByRedisKey(string redisKey, string hashField, string value)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.HashSet(redisKey, hashField, value);
- }
- ///
- /// 在hash 中设定值
- ///
- ///
- ///
- ///
- public async Task HashSet(string redisKey, IEnumerable hashFields)
- {
- redisKey = AddKeyPrefix(redisKey);
- _db.HashSet(redisKey, hashFields.ToArray());
- }
- ///
- /// 在hash 中设定值
- ///
- ///
- ///
- ///
- public async Task HashGetByRedisKey(string redisKey, string hashField)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.HashGet(redisKey, hashField);
- }
- ///
- /// 在hash 中获取值
- ///
- ///
- ///
- ///
- ///
- public async Task> HashGet(string redisKey, RedisValue[] hashField, string value)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.HashGet(redisKey, hashField);
- }
- ///
- /// 从hash返回所有的字段值
- ///
- ///
- ///
- public async Task> HashKeysByRedisKey(string redisKey)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.HashKeys(redisKey);
- }
- ///
- /// 返回hash中所有的值
- ///
- ///
- ///
- public async Task> HashValuesByRedisKey(string redisKey)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.HashValues(redisKey);
- }
- ///
- /// 在hash 中设定值(序列化)
- ///
- ///
- ///
- ///
- ///
- ///
- public async Task HashSetAsync(string redisKey, string hashField, T value)
- {
- redisKey = AddKeyPrefix(redisKey);
- var json = Serialize(value);
- return _db.HashSet(redisKey, hashField, json);
- }
- ///
- /// 在hash中获取值(反序列化)
- ///
- ///
- ///
- ///
- ///
- public async Task HashGetAsync(string redisKey, string hashField)
- {
- redisKey = AddKeyPrefix(redisKey);
- return Deserialize( _db.HashGet(redisKey, hashField));
- }
- #endregion
-
- #region list
- ///
- /// 移除并返回key所对应列表的第一个元素
- ///
- ///
- ///
- public string ListLeftPop(string redisKey)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.ListLeftPop(redisKey);
- }
- ///
- /// 移除并返回key所对应列表的最后一个元素
- ///
- ///
- ///
- public string ListRightPop(string redisKey)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.ListRightPop(redisKey);
- }
- ///
- /// 移除指定key及key所对应的元素
- ///
- ///
- ///
- ///
- public long ListRemove(string redisKey, string redisValue)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.ListRemove(redisKey, redisValue);
- }
- ///
- /// 在列表尾部插入值,如果键不存在,先创建再插入值
- ///
- ///
- ///
- ///
- public long ListRightPush(string redisKey, string redisValue)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.ListRightPush(redisKey, redisValue);
- }
- ///
- /// 在列表头部插入值,如果键不存在,先创建再插入值
- ///
- ///
- ///
- ///
- public long ListLeftPush(string redisKey, string redisValue)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.ListLeftPush(redisKey, redisValue);
- }
- ///
- /// 返回列表上该键的长度,如果不存在,返回0
- ///
- ///
- ///
- public long ListLength(string redisKey)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.ListLength(redisKey);
- }
- ///
- /// 返回在该列表上键所对应的元素
- ///
- ///
- ///
- public IEnumerable ListRange(string redisKey)
- {
- try
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.ListRange(redisKey);
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- ///
- /// 移除并返回存储在该键列表的第一个元素
- ///
- ///
- ///
- ///
- public T ListLeftPop(string redisKey)
- {
- redisKey = AddKeyPrefix(redisKey);
- return Deserialize(_db.ListLeftPop(redisKey));
- }
- ///
- /// 移除并返回该列表上的最后一个元素
- ///
- ///
- ///
- ///
- public T ListRightPop(string redisKey)
- {
- redisKey = AddKeyPrefix(redisKey);
- return Deserialize(_db.ListRightPop(redisKey));
- }
- ///
- /// 在列表尾部插入值,如果键不存在,先创建再插入值
- ///
- ///
- ///
- ///
- ///
- public long ListRightPush(string redisKey, T redisValue)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.ListRightPush(redisKey, Serialize(redisValue));
- }
- ///
- /// 在列表头部插入值,如果键不存在,创建后插入值
- ///
- ///
- ///
- ///
- ///
- public long ListLeftPush(string redisKey, T redisValue)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.ListRightPush(redisKey, Serialize(redisValue));
- }
- ///
- /// 移除并返回存储在该键列表的第一个元素
- ///
- ///
- ///
- public async Task ListLeftPopByRedisKey(string redisKey)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.ListLeftPop(redisKey);
- }
- ///
- /// 移除并返回存储在该键列表的最后一个元素
- ///
- ///
- ///
- public async Task ListRightPopByRedisKey(string redisKey)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.ListRightPop(redisKey);
- }
- ///
- /// 移除列表指定键上与值相同的元素
- ///
- ///
- ///
- public async Task ListRemoveByRedisKey(string redisKey, string redisValue)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.ListRemove(redisKey, redisValue);
- }
- ///
- /// 在列表尾部差入值,如果键不存在,先创建后插入
- ///
- ///
- ///
- ///
- public async Task ListRightPushByRedisKey(string redisKey, string redisValue)
- {
- redisKey = AddKeyPrefix(redisKey);
- return ListRightPush(redisKey, redisValue);
- }
- ///
- /// 在列表头部插入值,如果键不存在,先创建后插入
- ///
- ///
- ///
- ///
- public async Task ListLeftPushByRedisKey(string redisKey, string redisValue)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.ListLeftPush(redisKey, redisValue);
- }
- ///
- /// 返回列表上的长度,如果不存在,返回0
- ///
- ///
- ///
- public async Task ListLengthByRedisKey(string redisKey)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.ListLength(redisKey);
- }
- ///
- /// 返回在列表上键对应的元素
- ///
- ///
- ///
- public async Task> ListRangeByRedisKey(string redisKey)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.ListRange(redisKey);
- }
- ///
- /// 移除并返回存储在key对应列表的第一个元素
- ///
- ///
- ///
- ///
- public async Task ListLeftPopAsync(string redisKey)
- {
- redisKey = AddKeyPrefix(redisKey);
- return Deserialize( _db.ListLeftPop(redisKey));
- }
- ///
- /// 移除并返回存储在key 对应列表的最后一个元素
- ///
- ///
- ///
- ///
- public async Task ListRightPopAsync(string redisKey)
- {
- redisKey = AddKeyPrefix(redisKey);
- return Deserialize( _db.ListRightPop(redisKey));
- }
- ///
- /// 在列表尾部插入值,如果值不存在,先创建后写入值
- ///
- ///
- ///
- ///
- ///
- public async Task ListRightPushAsync(string redisKey, string redisValue)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.ListRightPush(redisKey, Serialize(redisValue));
- }
- ///
- /// 在列表头部插入值,如果值不存在,先创建后写入值
- ///
- ///
- ///
- ///
- ///
- public async Task ListLeftPushAsync(string redisKey, string redisValue)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.ListLeftPush(redisKey, Serialize(redisValue));
- }
- #endregion
-
- #region SortedSet 操作
- ///
- /// sortedset 新增
- ///
- ///
- ///
- ///
- ///
- public bool SortedSetAdd(string redisKey, string member, double score)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.SortedSetAdd(redisKey, member, score);
- }
- ///
- /// 在有序集合中返回指定范围的元素,默认情况下由低到高
- ///
- ///
- ///
- public IEnumerable SortedSetRangeByRank(string redisKey)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.SortedSetRangeByRank(redisKey);
- }
- ///
- /// 返回有序集合的个数
- ///
- ///
- ///
- public long SortedSetLength(string redisKey)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.SortedSetLength(redisKey);
- }
- ///
- /// 返回有序集合的元素个数
- ///
- ///
- ///
- ///
- public bool SortedSetLength(string redisKey, string member)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.SortedSetRemove(redisKey, member);
- }
- ///
- /// sorted set Add
- ///
- ///
- ///
- ///
- ///
- ///
- public bool SortedSetAdd(string redisKey, T member, double score)
- {
- redisKey = AddKeyPrefix(redisKey);
- var json = Serialize(member);
- return _db.SortedSetAdd(redisKey, json, score);
- }
-
- #region SortedSet-Async
- ///
- /// SortedSet 新增
- ///
- ///
- ///
- ///
- ///
- public async Task SortedSetAddByRedisKey(string redisKey, string member, double score)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.SortedSetAdd(redisKey, member, score);
- }
- ///
- /// 在有序集合中返回指定范围的元素,默认情况下由低到高
- ///
- ///
- ///
- public async Task> SortedSetRangeByRankByRedisKey(string redisKey)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.SortedSetRangeByRank(redisKey);
- }
- ///
- /// 返回有序集合的元素个数
- ///
- ///
- ///
- public async Task SortedSetLengthByRedisKey(string redisKey)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.SortedSetLength(redisKey);
- }
- ///
- /// 返回有序集合的元素个数
- ///
- ///
- ///
- ///
- public async Task SortedSetRemove(string redisKey, string member)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.SortedSetRemove(redisKey, member);
- }
- ///
- /// SortedSet 新增
- ///
- ///
- ///
- ///
- ///
- ///
- public async Task SortedSetAddAsync(string redisKey, T member, double score)
- {
- redisKey = AddKeyPrefix(redisKey);
- var json = Serialize(member);
- return _db.SortedSetAdd(redisKey, json, score);
- }
- #endregion SortedSet-Async
-
- #endregion
-
- #region key
- ///
- /// 移除指定key
- ///
- ///
- ///
- public bool KeyDelete(string redisKey)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.KeyDelete(redisKey);
- }
- ///
- /// 删除指定key
- ///
- ///
- ///
- public long KeyDelete(IEnumerable redisKeys)
- {
- var keys = redisKeys.Select(x => (RedisKey)AddKeyPrefix(x));
- return _db.KeyDelete(keys.ToArray());
- }
- ///
- /// 检验key是否存在
- ///
- ///
- ///
- public bool KeyExists(string redisKey)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.KeyExists(redisKey);
- }
- ///
- /// 重命名key
- ///
- ///
- ///
- ///
- public bool KeyReName(string oldKeyName, string newKeyName)
- {
- oldKeyName = AddKeyPrefix(oldKeyName);
- return _db.KeyRename(oldKeyName, newKeyName);
- }
- ///
- /// 设置key 的过期时间
- ///
- ///
- ///
- ///
- public bool KeyExpire(string redisKey, TimeSpan? expired = null)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.KeyExpire(redisKey, expired);
- }
-
- #region key-async
- ///
- /// 移除指定的key
- ///
- ///
- ///
- public async Task KeyDeleteByRedisKey(string redisKey)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.KeyDelete(redisKey);
- }
- ///
- /// 删除指定的key
- ///
- ///
- ///
- public async Task KeyDeleteByRedisKey(IEnumerable redisKeys)
- {
- var keys = redisKeys.Select(x => (RedisKey)AddKeyPrefix(x));
- return _db.KeyDelete(keys.ToArray());
- }
- ///
- /// 检验key 是否存在
- ///
- ///
- ///
- public async Task KeyExistsByRedisKey(string redisKey)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.KeyExists(redisKey);
- }
- ///
- /// 重命名key
- ///
- ///
- ///
- ///
- public async Task KeyRename(string redisKey, string redisNewKey)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.KeyRename(redisKey, redisNewKey);
- }
- ///
- /// 设置 key 时间
- ///
- ///
- ///
- ///
- public async Task KeyExpireByRedisKey(string redisKey, TimeSpan? expired)
- {
- redisKey = AddKeyPrefix(redisKey);
- return _db.KeyExpire(redisKey, expired);
- }
- #endregion key-async
-
- #endregion
-
- #region 发布订阅
- ///
- /// 订阅
- ///
- /// 频道
- /// 事件
- public void Subscribe(RedisChannel channel, Action handle)
- {
- //getSubscriber() 获取到指定服务器的发布者订阅者的连接
- var sub = _connMultiplexer.GetSubscriber();
- //订阅执行某些操作时改变了 优先/主动 节点广播
- sub.Subscribe(channel, handle);
- }
- ///
- /// 发布
- ///
- ///
- ///
- ///
- public long Publish(RedisChannel channel, RedisValue message)
- {
- var sub = _connMultiplexer.GetSubscriber();
- return sub.Publish(channel, message);
- }
- ///
- /// 发布(使用序列化)
- ///
- ///
- ///
- ///
- ///
- public long Publish(RedisChannel channel, T message)
- {
- var sub = _connMultiplexer.GetSubscriber();
- return sub.Publish(channel, Serialize(message));
- }
-
- #region 发布订阅-async
- ///
- /// 订阅
- ///
- ///
- ///
- ///
- public async Task SubscribeByRedisKey(RedisChannel redisChannel, Action handle)
- {
- var sub = _connMultiplexer.GetSubscriber();
- sub.Subscribe(redisChannel, handle);
- }
- ///
- /// 发布
- ///
- ///
- ///
- ///
- public async Task PublishByRedisKey(RedisChannel redisChannel, RedisValue message)
- {
- var sub = _connMultiplexer.GetSubscriber();
- return sub.Publish(redisChannel, message);
- }
- ///
- /// 发布(使用序列化)
- ///
- ///
- ///
- ///
- ///
- public async Task PublishAsync(RedisChannel redisChannel, T message)
- {
- var sub = _connMultiplexer.GetSubscriber();
- return sub.Publish(redisChannel, Serialize(message));
- }
- #endregion 发布订阅-async
-
- #endregion
-
- #region 注册事件
- ///
- /// 注册事件
- ///
- private static void RegisterEvent()
- {
- _connMultiplexer.ConnectionRestored += ConnMultiplexer_ConnectionRestored;
- _connMultiplexer.ConnectionFailed += ConnMultiplexer_ConnectionFailed;
- _connMultiplexer.ErrorMessage += ConnMultiplexer_ErrorMessage;
- _connMultiplexer.ConfigurationChanged += ConnMultiplexer_ConfigurationChanged;
- _connMultiplexer.HashSlotMoved += ConnMultiplexer_HashSlotMoved;
- _connMultiplexer.InternalError += ConnMultiplexer_InternalError;
- _connMultiplexer.ConfigurationChangedBroadcast += ConnMultiplexer_ConfigurationChangedBroadcast;
- }
- ///
- /// 重新配置广播时(主从同步更改)
- ///
- ///
- ///
- private static void ConnMultiplexer_ConfigurationChangedBroadcast(object sender, EndPointEventArgs e)
- {
- Console.WriteLine($"{nameof(ConnMultiplexer_ConfigurationChangedBroadcast)}: {e.EndPoint}");
- }
- ///
- /// 发生内部错误时(调试用)
- ///
- ///
- ///
- private static void ConnMultiplexer_InternalError(object sender, InternalErrorEventArgs e)
- {
- Console.WriteLine($"{nameof(ConnMultiplexer_InternalError)}: {e.Exception}");
- }
- ///
- /// 更改集群时
- ///
- ///
- ///
- private static void ConnMultiplexer_HashSlotMoved(object sender, HashSlotMovedEventArgs e)
- {
- Console.WriteLine($"{nameof(ConnMultiplexer_HashSlotMoved)}: {nameof(e.OldEndPoint)}-{e.OldEndPoint} To {nameof(e.NewEndPoint)}-{e.NewEndPoint} ");
- }
- ///
- /// 配置更改时
- ///
- ///
- ///
- private static void ConnMultiplexer_ConfigurationChanged(object sender, EndPointEventArgs e)
- {
- Console.WriteLine($"{nameof(ConnMultiplexer_ConfigurationChanged)}: {e.EndPoint}");
- }
- ///
- /// 发生错误时
- ///
- ///
- ///
- private static void ConnMultiplexer_ErrorMessage(object sender, RedisErrorEventArgs e)
- {
- Console.WriteLine($"{nameof(ConnMultiplexer_ErrorMessage)}: {e.Message}");
- }
- ///
- /// 物理连接失败时
- ///
- ///
- ///
- private static void ConnMultiplexer_ConnectionFailed(object sender, ConnectionFailedEventArgs e)
- {
- Console.WriteLine($"{nameof(ConnMultiplexer_ConnectionFailed)}: {e.Exception}");
- }
- ///
- /// 建立物理连接时
- ///
- ///
- ///
- private static void ConnMultiplexer_ConnectionRestored(object sender, ConnectionFailedEventArgs e)
- {
- Console.WriteLine($"{nameof(ConnMultiplexer_ConnectionRestored)}: {e.Exception}");
- }
- #endregion
-
- }
-}
diff --git "a/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/bin/Debug/DotNet.Utilities.dll" "b/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/bin/Debug/DotNet.Utilities.dll"
index 007db65..8de66d3 100644
Binary files "a/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/bin/Debug/DotNet.Utilities.dll" and "b/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/bin/Debug/DotNet.Utilities.dll" differ
diff --git "a/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/bin/Debug/DotNet.Utilities.pdb" "b/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/bin/Debug/DotNet.Utilities.pdb"
index 11f9324..b5b8460 100644
Binary files "a/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/bin/Debug/DotNet.Utilities.pdb" and "b/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/bin/Debug/DotNet.Utilities.pdb" differ
diff --git "a/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/obj/Debug/Common.Utility.csprojAssemblyReference.cache" "b/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/obj/Debug/Common.Utility.csprojAssemblyReference.cache"
index 9372c01..c7a7231 100644
Binary files "a/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/obj/Debug/Common.Utility.csprojAssemblyReference.cache" and "b/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/obj/Debug/Common.Utility.csprojAssemblyReference.cache" differ
diff --git "a/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache" "b/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache"
index 8616471..70d1d28 100644
Binary files "a/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache" and "b/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache" differ
diff --git "a/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/obj/Debug/DotNet.Utilities.dll" "b/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/obj/Debug/DotNet.Utilities.dll"
index 007db65..8de66d3 100644
Binary files "a/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/obj/Debug/DotNet.Utilities.dll" and "b/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/obj/Debug/DotNet.Utilities.dll" differ
diff --git "a/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/obj/Debug/DotNet.Utilities.pdb" "b/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/obj/Debug/DotNet.Utilities.pdb"
index 11f9324..b5b8460 100644
Binary files "a/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/obj/Debug/DotNet.Utilities.pdb" and "b/Utility\345\237\272\347\241\200\347\261\273\345\244\247\345\205\250/obj/Debug/DotNet.Utilities.pdb" differ