jiangjc 2 年 前
コミット
ec5761156e

+ 0 - 1
OASystem/OASystem.Api/Controllers/SystemController.cs

@@ -22,7 +22,6 @@ namespace OASystem.API.Controllers
             _mapper = mapper;
         }
 
-
         //[Authorize]
         [HttpPost]
         [ProducesResponseType(typeof(LoginView), StatusCodes.Status200OK)]

+ 7 - 0
OASystem/OASystem.Api/OASystem.API.csproj

@@ -32,12 +32,19 @@
   <ItemGroup>
     <ProjectReference Include="..\OASystem.Domain\OASystem.Domain.csproj" />
     <ProjectReference Include="..\OASystem.Infrastructure\OASystem.Infrastructure.csproj" />
+    <ProjectReference Include="..\OASystem.RedisRepository\OASystem.RedisRepository.csproj" />
   </ItemGroup>
 
   <ItemGroup>
     <Folder Include="Include\" />
   </ItemGroup>
 
+  <ItemGroup>
+    <Content Update="appsettings.json">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </Content>
+  </ItemGroup>
+
   <ProjectExtensions><VisualStudio><UserProperties properties_4launchsettings_1json__JsonSchema="" /></VisualStudio></ProjectExtensions>
 
 </Project>

+ 29 - 28
OASystem/OASystem.Api/Program.cs

@@ -1,10 +1,12 @@
-
+
 using StackExchange.Redis;
 using Autofac.Core;
+using System.Configuration;
+using static Org.BouncyCastle.Math.EC.ECCurve;
 
 var builder = WebApplication.CreateBuilder(args);
 var basePath = AppContext.BaseDirectory;
-//引入配置文件
+//寮曞叆閰嶇疆鏂囦欢
 var _config = new ConfigurationBuilder()
                  .SetBasePath(basePath)
                  .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
@@ -13,31 +15,30 @@ builder.Services.AddSingleton(new AppSettingsHelper(_config));
 
 // Add services to the container.
 builder.Services.AddControllersWithViews();
-
 #region redis
 
-//redis缓存
-var section = builder.Configuration.GetSection("Redis:Default");
-//连接字符串
-string _connectionString = section.GetSection("Connection").Value;
-//实例名称
-string _instanceName = section.GetSection("InstanceName").Value;
-//默认数据库 
-int _defaultDB = int.Parse(section.GetSection("DefaultDB").Value ?? "0");
-builder.Services.AddSingleton(new RedisHelper1(_connectionString+",password=123456", _instanceName, _defaultDB));
+//redis缂撳瓨
+//var section = builder.Configuration.GetSection("Redis:Default");
+////连接字符串
+//string _connectionString = section.GetSection("Connection").Value;
+////瀹炰緥鍚嶇О
+//string _instanceName = section.GetSection("InstanceName").Value;
+////默认数据库 
+//int _defaultDB = int.Parse(section.GetSection("DefaultDB").Value ?? "0");
+//builder.Services.AddSingleton(new RedisHelper1(_connectionString+",password=123456", _instanceName, _defaultDB));
 
 #endregion
 
 
-#region 接口分组
+#region 鎺ュ彛鍒嗙粍
 var groups = new List<Tuple<string, string>>
 {
-    //new Tuple<string, string>("Group1","分组一"),
-    //new Tuple<string, string>("Group2","分组二")
+    //new Tuple<string, string>("Group1","鍒嗙粍涓€"),
+    //new Tuple<string, string>("Group2","分组二")
 };
 #endregion
 
-#region 注入数据库
+#region 注入数据库
 builder.Services.AddScoped(options =>
 {
     return new SqlSugarClient(new List<ConnectionConfig>()
@@ -50,7 +51,7 @@ builder.Services.AddScoped(options =>
 });
 #endregion
 
-#region 注入Swagger注释(启用)
+#region 娉ㄥ叆Swagger娉ㄩ噴(鍚�敤)
 
 if (AppSettingsHelper.Get("UseSwagger").ToBool())
 {
@@ -60,11 +61,11 @@ if (AppSettingsHelper.Get("UseSwagger").ToBool())
         {
             Version = "v1",
             Title = "Api",
-            Description = "Api接口文档"
+            Description = "Api鎺ュ彛鏂囨。"
         });
         foreach (var item in groups)
         {
-            a.SwaggerDoc(item.Item1, new OpenApiInfo { Version = item.Item1, Title = item.Item2, Description = $"{item.Item2}接口文档" });
+            a.SwaggerDoc(item.Item1, new OpenApiInfo { Version = item.Item1, Title = item.Item2, Description = $"{item.Item2}鎺ュ彛鏂囨。" });
         }
         a.DocumentFilter<SwaggerApi>();
         a.IncludeXmlComments(Path.Combine(basePath, "OASystem.Api.xml"), true);
@@ -92,7 +93,7 @@ if (AppSettingsHelper.Get("UseSwagger").ToBool())
 }
 #endregion
 
-#region 添加swagger注释
+#region 娣诲姞swagger娉ㄩ噴
 //if (AppSettingsHelper.Get("UseSwagger").ToBool())
 //{
 //    builder.Services.AddSwaggerGen(c =>
@@ -100,8 +101,8 @@ if (AppSettingsHelper.Get("UseSwagger").ToBool())
 //        c.SwaggerDoc("v1", new OpenApiInfo
 //        {
 //            Version = "v1",
-//            Title = "文华商旅支付测试接口",
-//            Description = "请先从Auth鉴权=>login获取token进行认证,输入:token进行认证(Bearer)"
+//            Title = "鏂囧崕鍟嗘梾鏀�粯娴嬭瘯鎺ュ彛",
+//            Description = "璇峰厛浠嶢uth閴存潈=>login鑾峰彇token杩涜�璁よ瘉,杈撳叆:token杩涜�璁よ瘉(Bearer)"
 //        });
 //        c.DocumentFilter<SwaggerApi>();
 //        var xmlPath = Path.Combine(basePath, "OASystem.API.xml");
@@ -133,7 +134,7 @@ if (AppSettingsHelper.Get("UseSwagger").ToBool())
 //}
 #endregion
 
-#region 添加校验
+#region 娣诲姞鏍¢獙
 builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options =>
 {
     options.TokenValidationParameters = new TokenValidationParameters
@@ -149,14 +150,14 @@ builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJw
 });
 #endregion
 
-#region 初始化日志
+#region 初始化日志
 Log.Logger = new LoggerConfiguration()
        .MinimumLevel.Debug()
        .WriteTo.File(Path.Combine("Logs", @"Log.txt"), rollingInterval: RollingInterval.Day)
        .CreateLogger();
 #endregion
 
-#region 引入注册Autofac OASystem.Infrastructure中所有以Repository结尾的文件都会被注入到项目
+#region 引入注册Autofac OASystem.Infrastructure中所有以Repository结尾的文件都会被注入到项目
 builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory());
 var hostBuilder = builder.Host.ConfigureContainer<ContainerBuilder>(builder =>
 {
@@ -174,11 +175,11 @@ var hostBuilder = builder.Host.ConfigureContainer<ContainerBuilder>(builder =>
 
 #region AutoMapper
 
-AutoMapper.IConfigurationProvider config = new MapperConfiguration(cfg =>
+AutoMapper.IConfigurationProvider mapperConfig = new MapperConfiguration(cfg =>
 {
     cfg.AddProfile<_baseMappingProfile>();
 });
-builder.Services.AddSingleton(config);
+builder.Services.AddSingleton(mapperConfig);
 builder.Services.AddScoped<IMapper, Mapper>();
 
 #endregion
@@ -197,7 +198,7 @@ app.UseAuthentication();
 app.UseAuthorization();
 
 
-#region 启用swaggerUI
+#region 鍚�敤swaggerUI
 if (AppSettingsHelper.Get("UseSwagger").ToBool())
 {
     app.UseSwagger();

+ 2 - 0
OASystem/OASystem.Api/appsettings.json

@@ -11,4 +11,6 @@
       "DefaultDB": "0" //Db8数据库
     }
   }
+  ,"RedisServer": "11"
+
 }

+ 32 - 0
OASystem/OASystem.RedisRepository/CommonHelper/RedisInnerTypeHelper.cs

@@ -0,0 +1,32 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using StackExchange.Redis;
+
+namespace OASystem.RedisRepository.CommonHelper
+{
+    internal class RedisInnerTypeHelper
+    {
+        public static List<T> RedisValuesToGenericList<T>(RedisValue[] redisValues)
+        {
+            var result=new List<T>();
+            redisValues.ToList().ForEach(r => result.Add(SerializeHelper.Deserialize<T>(r)));
+            return result;
+        }
+        public static RedisValue[] GenericListToRedisValues<T>(List<T> values)
+        {
+            var redisValues = new List<RedisValue>();
+            values.ForEach(v => redisValues.Add(SerializeHelper.Serialize(values)));
+            return redisValues.ToArray();
+        }
+
+        public static RedisKey[] GenericListToRedisKeys(List<string> keys)
+        {
+            var redisKeys = new List<RedisKey>();
+            keys.ForEach(k => redisKeys.Add(k));
+            return redisKeys.ToArray();
+        }
+    }
+}

+ 54 - 0
OASystem/OASystem.RedisRepository/CommonHelper/SerializeHelper.cs

@@ -0,0 +1,54 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.Serialization.Formatters.Binary;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.RedisRepository.CommonHelper
+{
+    internal static class SerializeHelper
+    {
+        /// <summary>
+        /// 字节数组序列化
+        /// </summary>
+        /// <param name="o"></param>
+        /// <returns></returns>
+        internal static byte[] Serialize(object o)
+        {
+            if (o == null)
+            {
+                return null;
+            }
+
+            BinaryFormatter binaryFormatter = new BinaryFormatter();
+            using (MemoryStream memoryStream = new MemoryStream())
+            {
+                binaryFormatter.Serialize(memoryStream, o);
+                byte[] objectDataAsStream = memoryStream.ToArray();
+                return objectDataAsStream;
+            }
+        }
+
+        /// <summary>
+        /// 字节数组反序列化
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="stream"></param>
+        /// <returns></returns>
+        internal static T Deserialize<T>(byte[] stream)
+        {
+            if (stream == null)
+            {
+                return default(T);
+            }
+
+            BinaryFormatter binaryFormatter = new BinaryFormatter();
+            using (MemoryStream memoryStream = new MemoryStream(stream))
+            {
+                T result = (T)binaryFormatter.Deserialize(memoryStream);
+                return result;
+            }
+        }
+    }
+}

+ 28 - 0
OASystem/OASystem.RedisRepository/Config/ConfigHelper.cs

@@ -0,0 +1,28 @@
+using Microsoft.Extensions.Configuration;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.RedisRepository.Config
+{
+    internal class ConfigHelper
+    {
+        //internal static T Get<T>(string appSettingsKey, T defaultValue)
+        //{
+        //    //string text = ConfigurationManager.AppSettings[appSettingsKey];
+        //    //if (string.IsNullOrWhiteSpace(text))
+        //    //    return defaultValue;
+        //    //try
+        //    //{
+        //    //    var value = Convert.ChangeType(text, typeof(T));
+        //    //    return (T)value;
+        //    //}
+        //    //catch
+        //    //{
+        //    //    return defaultValue;
+        //    //}
+        //}
+    }
+}

+ 98 - 0
OASystem/OASystem.RedisRepository/Config/RedisClientConfig.cs

@@ -0,0 +1,98 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.RedisRepository.Config
+{
+    internal class RedisClientConfig
+    {
+        //private static string _server = ConfigHelper.Get("RedisServer", "132.232.92.186");
+        private static string _server = "132.232.92.186";
+        /// <summary>
+        /// 节点IP
+        /// </summary>
+        public static string Server
+        {
+            get { return _server; }
+            set { _server = value; }
+        }
+
+        //private static int _port = ConfigHelper.Get("RedisPort", 6379);
+        private static int _port = 6379;
+        /// <summary>
+        /// 节点端口
+        /// </summary>
+        public static int Port
+        {
+            get { return _port; }
+            set { _port = value; }
+        }
+
+        //private static string _slaveServer = ConfigHelper.Get("SlaveServer", "132.232.92.186");
+        private static string _slaveServer = "132.232.92.186";
+        /// <summary>
+        /// 节点IP
+        /// </summary>
+        public static string SlaveServer
+        {
+            get { return _slaveServer; }
+            set { _slaveServer = value; }
+        }
+
+        //private static int _slavePort = ConfigHelper.Get("SlavePort", 6380);
+        private static int _slavePort = 6380;
+        /// <summary>
+        /// 节点端口
+        /// </summary>
+        public static int SlavePort
+        {
+            get { return _slavePort; }
+            set { _slavePort = value; }
+        }
+
+        //private static string _auth = ConfigHelper.Get("RedisAuth", "123456");
+        private static string _auth = "123456";
+        /// <summary>
+        /// 节点密码
+        /// </summary>
+        public static string RedisAuth
+        {
+            get { return _auth; }
+            set { _auth = value; }
+        }
+
+        //private static int _defaultDatabase = ConfigHelper.Get("RedisDataBase", 0);
+        private static int _defaultDatabase = 0;
+        /// <summary>
+        /// redis默认0号库
+        /// </summary>
+        public static int DefaultDatabase
+        {
+            get { return _defaultDatabase; }
+            set { _defaultDatabase = value; }
+        }
+
+        private static int _connectTimeout = 10000;
+        public static int ConnectTimeout
+        {
+            get { return _connectTimeout; }
+            set { _connectTimeout = value; }
+        }
+
+        private static int _connectRetry = 3;
+        public static int ConnectRetry
+        {
+            get { return _connectRetry; }
+            set { _connectRetry = value; }
+        }
+
+        private static bool _preserveAsyncOrder = false;
+        public static bool PreserveAsyncOrder
+        {
+            get { return _preserveAsyncOrder; }
+            set { _preserveAsyncOrder = value; }
+        }
+    }
+}

+ 41 - 0
OASystem/OASystem.RedisRepository/Config/RedisConnection.cs

@@ -0,0 +1,41 @@
+using StackExchange.Redis;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.RedisRepository.Config
+{
+    public class RedisConnection
+    {
+        private static ConnectionMultiplexer _connection;
+        private static readonly object SyncObject = new object();
+        /// <summary>
+        /// redis连接对象,单例加锁不影响性能
+        /// </summary>
+        public static ConnectionMultiplexer GenerateConnection
+        {
+            get
+            {
+                if (_connection == null || !_connection.IsConnected)
+                {
+                    lock (SyncObject)
+                    {
+                        var configurationOptions = new ConfigurationOptions()
+                        {
+                            Password = RedisClientConfig.RedisAuth,
+                            EndPoints =
+                            {
+                                {RedisClientConfig.Server, RedisClientConfig.Port},
+                                {RedisClientConfig.SlaveServer, RedisClientConfig.SlavePort}
+                            }
+                        };
+                        _connection = ConnectionMultiplexer.Connect(configurationOptions);
+                    }
+                }
+                return _connection;
+            }
+        }
+    }
+}

+ 14 - 0
OASystem/OASystem.RedisRepository/OASystem.RedisRepository.csproj

@@ -0,0 +1,14 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <TargetFramework>net6.0</TargetFramework>
+    <ImplicitUsings>enable</ImplicitUsings>
+    <Nullable>enable</Nullable>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
+    <PackageReference Include="StackExchange.Redis" Version="2.6.96" />
+  </ItemGroup>
+
+</Project>

+ 468 - 0
OASystem/OASystem.RedisRepository/RedisAsyncHelper/IRedisHelper.cs

@@ -0,0 +1,468 @@
+using StackExchange.Redis;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.RedisRepository.RedisAsyncHelper
+{
+    /// <summary>
+    /// 异步方法接口  
+    /// 存入数据均为方法内部序列化后的byte,所以取数据的时候需要反序列化时,请指定正确的数据类型
+    /// </summary>
+    public partial interface IRedisHelper
+    {
+        #region Redis数据类型—String 
+
+        /// <summary>
+        /// 将任何数据以redis string存储
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="key"></param>
+        /// <param name="value"></param>
+        /// <param name="timeout"></param>
+        /// <returns></returns>
+        Task<bool> StringSetAsync<T>(string key, T value, TimeSpan? timeout = null);
+
+        /// <summary>
+        /// 对数值进行减法操作,默认-1
+        /// </summary>
+        /// <param name="key"></param>
+        /// <param name="value"></param>
+        /// <returns>操作后的结果</returns>
+        Task<long> StringDecrementAsync(string key, long value = 1L);
+
+        /// <summary>
+        /// 对数值进行加法操作,默认+1
+        /// </summary>
+        /// <param name="key"></param>
+        /// <param name="value"></param>
+        /// <returns>操作后的结果</returns>
+        Task<long> StringIncrementAsync(string key, long value = 1L);
+
+        /// <summary>
+        /// 从redis string中以指定类型取出
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="key"></param>
+        /// <returns></returns>
+        Task<T> StringGetAsync<T>(string key);
+
+        #endregion
+
+        #region Redis数据类型—Hash
+
+        /// <summary>
+        /// 向Hash key中存储任意类型任意值
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="key"></param>
+        /// <param name="field"></param>
+        /// <param name="value"></param>
+        /// <returns>是否成功</returns>
+        Task<bool> HashSetAsync<T>(string key, string field, T value);
+
+        /// <summary>
+        /// 批量 向Hash key中存储任意类型任意值
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="key"></param>
+        /// <param name="hashFields"></param>
+        /// <returns>无返回值</returns>
+        Task HashMultiSetAsync<T>(string key, Dictionary<string, T> hashFields);
+
+        /// <summary>
+        /// 对指定hash key中制定field做数量增加操作 默认自增1 
+        /// 如果此操作前key不存在 则创建。 如果此操作前该field不存在或者非数字 则先被置0,再被继续操作
+        /// </summary>
+        /// <param name="key"></param>
+        /// <param name="field"></param>
+        /// <param name="incrCount"></param>
+        /// <returns>操作后的结果</returns>
+        Task<long> HashIncrementAsync(string key, string field, long incrCount = 1);
+
+        /// <summary>
+        /// 对指定hash key中制定field做数量增加操作 默认自减1 
+        /// 如果此操作前key不存在 则创建。 如果此操作前该field不存在或者非数字 则先被置0,再被继续操作
+        /// </summary>
+        /// <param name="key"></param>
+        /// <param name="field"></param>
+        /// <param name="decrCount"></param>
+        /// <returns>操作后的结果</returns>
+        Task<long> HashDecrementAsync(string key, string field, long decrCount = 1);
+
+        /// <summary>
+        /// 从指定Hash中 删除指定field
+        /// 如果key或者field不存在,则false
+        /// </summary>
+        /// <param name="key"></param>
+        /// <param name="field"></param>
+        /// <returns>是否成功</returns>
+        Task<bool> HashDeleteFieldAsync(string key, string field);
+
+        /// <summary>
+        /// 从指定Hash key中 批量删除指定field
+        /// 如果key或者field不存在,则false
+        /// </summary>
+        /// <param name="key"></param>
+        /// <param name="fields"></param>
+        /// <returns>移除数量</returns>
+        Task<long> HashMultiDeleteFieldAsync(string key, List<string> fields);
+
+        /// <summary>
+        /// 从指定Hash key中获取指定field值
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="key"></param>
+        /// <param name="field"></param>
+        /// <returns></returns>
+        Task<T> HashGetAsync<T>(string key, string field);
+
+        /// <summary>
+        /// 从指定Hash key中判断field是否存在
+        /// </summary>
+        /// <param name="key"></param>
+        /// <param name="field"></param>
+        /// <returns></returns>
+        Task<bool> HashFieldExistAsync(string key, string field);
+
+        /// <summary>
+        /// 获取指定Hash key中的所有field的值 
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="key"></param>
+        /// <returns></returns>
+        Task<List<T>> HashValuesAsync<T>(string key);
+
+        /// <summary>
+        /// 获取指定Hash key中所有 field名称及其Value
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="key"></param>
+        /// <returns></returns>
+        Task<Dictionary<string, T>> HashGetAllAsync<T>(string key);
+
+        /// <summary>
+        /// 获取指定Hash key中所有field
+        /// </summary>
+        /// <param name="key"></param>
+        /// <returns></returns>
+        Task<List<string>> HashFieldsAsync(string key);
+
+        #endregion
+
+        #region Redis数据类型—List     
+
+        /// <summary>
+        /// 在指定pivot后插入value, 如果pivot不存在,则返回-1, 如果key不存在,则返回0
+        /// 如果存在多个相同指定的的pivot,则插入第一个指定pivot后面.
+        /// 即链表从左向右查找,遇到指定pivot,则确定位置
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="key"></param>
+        /// <param name="pivot">list中的一个值</param>
+        /// <param name="value"></param>
+        /// <returns></returns>
+        Task<long> ListInsertAfterAsync<T>(string key, string pivot, T value);
+
+        /// <summary>
+        /// 在指定pivot前插入value, 如果pivot不存在,则返回-1, 如果key不存在,则返回0
+        /// 如果存在多个相同指定的的pivot,则插入第一个指定pivot前面.
+        /// 即链表从左向右查找,遇到指定pivot,则确定位置
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="key"></param>
+        /// <param name="pivot"></param>
+        /// <param name="value"></param>
+        /// <returns></returns>
+        Task<long> ListInsertBeforeAsync<T>(string key, string pivot, T value);
+
+        /// <summary>
+        /// 从链表左侧弹出第一个元素(弹出能获取到该元素并且被删除)
+        /// 如果key不存在 或者链表为空 则为null
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="key"></param>
+        /// <returns></returns>
+        Task<T> ListLeftPopAsync<T>(string key);
+
+        /// <summary>
+        /// 从链表左侧增加一个元素,key不存在则被创建
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="key"></param>
+        /// <param name="value"></param>
+        /// <returns>返回操作后的链表长度</returns>
+        Task<long> ListLeftPushAsync<T>(string key, T value);
+
+        /// <summary>
+        /// 从链表左侧批量增加元素,如果 a b c  则c会在链表左侧第一位  b第二位  a第三位
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="key"></param>
+        /// <param name="values"></param>
+        /// <returns>返回操作后的链表长度</returns>
+        Task<long> ListLeftMultiPushAsync<T>(string key, List<T> values);
+
+        /// <summary>
+        /// 获取链表长度,不存在key则为0
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="key"></param>
+        /// <returns></returns>
+        Task<long> ListLengthAsync<T>(string key);
+
+        /// <summary>
+        /// 获取链表中所有数据,从左侧start开始到stop结束,从0—-1则认为获取全部,默认获取全部
+        /// start为负数则代表从链表右侧开始,-1为右侧第一位,-2为右侧第二位
+        /// start要小于stop,否则返回null
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="key"></param>
+        /// <param name="start"></param>
+        /// <param name="stop"></param>
+        /// <returns></returns>
+        Task<List<T>> ListRangeAsync<T>(string key, long start = 0L, long stop = -1L);
+
+        /// <summary>
+        /// 从链表中一处count数量的value. count大于0则从左至右,count小于0则从右至左,count=0则移除全部
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="key"></param>
+        /// <param name="value"></param>
+        /// <param name="count"></param>
+        /// <returns></returns>
+        Task<long> ListRemoveAsync<T>(string key, T value, long count = 0L);
+
+        /// <summary>
+        /// 从右侧弹出第一个元素(弹出能获取到该元素并且被删除)
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="key"></param>
+        /// <returns></returns>
+        Task<T> ListRightPopAsync<T>(string key);
+
+
+        /// <summary>
+        /// 从链表右侧加入元素,如果 rpush a b c 则c为右侧第一位 b第二位 c第三位
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="key"></param>
+        /// <param name="value"></param>
+        /// <returns></returns>
+        Task<long> ListRightPushAsync<T>(string key, T value);
+
+        /// <summary>
+        /// 从右侧批量插入,和左侧相反
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="key"></param>
+        /// <param name="values"></param>
+        /// <returns></returns>
+        Task<long> ListRightMultiPushAsync<T>(string key, List<T> values);
+
+        /// <summary>
+        /// 在链表指定索引处,插入元素
+        /// 正数索引从0开始,代表左侧。负数从-1开始 代表从右侧。-1为右侧第一位
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="key"></param>
+        /// <param name="index"></param>
+        /// <param name="value"></param>
+        /// <returns></returns>
+        Task ListSetByIndexAsync<T>(string key, int index, T value);
+
+        /// <summary>
+        /// 留下start到stop之间的数据。负数代表从右侧寻找  -1为右侧第一位
+        /// </summary>
+        /// <param name="key"></param>
+        /// <param name="start"></param>
+        /// <param name="stop"></param>
+        /// <returns></returns>
+        Task ListTrimAsync(string key, long start, long stop);
+
+        /// <summary>
+        /// 获取指定index的值,负数代表从右侧寻找  -1为右侧第一位
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="key"></param>
+        /// <param name="index"></param>
+        /// <returns></returns>
+        Task<T> ListGetByIndexAsync<T>(string key, long index);
+
+        #endregion
+
+        #region Redis数据类型—Set
+
+        /// <summary>
+        /// 向指定集合中增加一个元素
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="key"></param>
+        /// <param name="value"></param>
+        /// <returns></returns>
+        Task<bool> SetAddAsync<T>(string key, T value);
+
+        /// <summary>
+        /// 指定集合计算操作operation枚举,指定计算结果将存的目标destKey,指定需要参与计算的多个key
+        /// </summary>
+        /// <param name="operation"></param>
+        /// <param name="destKey"></param>
+        /// <param name="combineKeys"></param>
+        /// <returns></returns>
+        Task<long> SetCombineAndStoreAsync(SetOperation operation, string destKey, List<string> combineKeys);
+
+        /// <summary>
+        /// 指定集合计算操作operation枚举,指定需要参与计算的多个key
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="operation"></param>
+        /// <param name="combineKeys"></param>
+        /// <returns></returns>
+        Task<List<T>> SetCombineAsync<T>(SetOperation operation, List<string> combineKeys);
+
+        /// <summary>
+        /// 指定值是否存在于指定集合中
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="key"></param>
+        /// <param name="value"></param>
+        /// <returns></returns>
+        Task<bool> SetContainsAsync<T>(string key, T value);
+
+        /// <summary>
+        /// 获取指定集合中元素个数
+        /// </summary>
+        /// <param name="key"></param>
+        /// <returns></returns>
+        Task<long> SetLengthAsync(string key);
+
+        /// <summary>
+        /// 获取指定集合中的所有元素
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="key"></param>
+        /// <param name="value"></param>
+        /// <returns></returns>
+        Task<List<T>> SetMembersAsync<T>(string key, T value);
+
+        /// <summary>
+        /// 从sourceKey移除指定value到目标distKey集合当中
+        /// 如果sourceKey存在指定value则返回true,否则不做任何操作返回false
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="sourcekey"></param>
+        /// <param name="distKey"></param>
+        /// <param name="value"></param>
+        /// <returns></returns>
+        Task<bool> SetMoveAsync<T>(string sourcekey, string distKey, T value);
+
+        /// <summary>
+        /// 从指定集合当中随机取出一个元素
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="key"></param>
+        /// <returns></returns>
+        Task<T> SetRandomMemberAsync<T>(string key);
+
+        /// <summary>
+        /// 从指定集合随机弹出(删除并获取)一个元素
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="key"></param>
+        /// <returns></returns>
+        Task<T> SetPopAsync<T>(string key);
+
+        /// <summary>
+        /// 从集合中随机弹出(删除并获取)多个元素
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="key"></param>
+        /// <returns></returns>
+        Task<List<T>> SetRandomMembersAsync<T>(string key);
+
+        /// <summary>
+        /// 从集合中移除指定元素
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="key"></param>
+        /// <param name="value"></param>
+        /// <returns></returns>
+        Task<bool> SetRemoveAsync<T>(string key, T value);
+
+        /// <summary>
+        /// 从集合中批量移除元素
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="key"></param>
+        /// <param name="values"></param>
+        /// <returns></returns>
+        Task<long> SetMultiRemoveAsync<T>(string key, List<T> values);
+
+        #endregion
+
+        #region Redis数据类型—SortSet
+
+
+
+        #endregion
+
+        #region Redis Key操作
+
+        /// <summary>
+        /// 删除指定key
+        /// </summary>
+        /// <param name="key"></param>
+        /// <returns></returns>
+        Task<bool> KeyDeleteAsync(string key);
+
+        /// <summary>
+        /// 设置key过期时间具体DateTime
+        /// </summary>
+        /// <param name="key"></param>
+        /// <param name="expireAt"></param>
+        /// <returns></returns>
+        Task<bool> KeyExpireAtAsync(string key, DateTime expireAt);
+
+        /// <summary>
+        /// 设置key在将来的timeout后过期(TimeSpan)
+        /// </summary>
+        /// <param name="key"></param>
+        /// <param name="timeout"></param>
+        /// <returns></returns>
+        Task<bool> KeyExpireInAsync(string key, TimeSpan timeout);
+
+        /// <summary>
+        /// key重命名
+        /// </summary>
+        /// <param name="key"></param>
+        /// <param name="newKey"></param>
+        /// <returns></returns>
+        Task<bool> KeyRenameAsync(string key, string newKey);
+
+        /// <summary>
+        /// 判断key是否已存在
+        /// </summary>
+        /// <param name="key"></param>
+        /// <returns></returns>
+        Task<bool> KeyExistsAsync(string key);
+
+        #endregion
+
+        #region Redis Transcation
+
+        /// <summary>
+        /// 在事务中执行一系列redis命令。注意:在委托中的一系列命令的所有 值  都需要进行字节数组序列化
+        /// </summary>
+        /// <param name="ranOperations"></param>
+        /// <returns></returns>
+        Task<bool> DoInTranscationAsync(Action<ITransaction> ranOperations);
+
+        #endregion
+
+
+
+        Task<RedisResult> Test();
+    }
+}

+ 66 - 0
OASystem/OASystem.RedisRepository/RedisAsyncHelper/RedisStringHelperAsync.cs

@@ -0,0 +1,66 @@
+using OASystem.RedisRepository.CommonHelper;
+using OASystem.RedisRepository.Config;
+using StackExchange.Redis;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.RedisRepository.RedisAsyncHelper
+{/// <summary>
+ /// Redis异步操作类  String部分类
+ /// </summary>
+    internal partial class RedisHelper// : IRedisHelper
+    {
+
+        private static IDatabase _client;
+
+        internal RedisHelper()
+        {
+            _client = RedisConnection.GenerateConnection.GetDatabase();
+        }
+
+        #region String 写操作
+
+        /// <summary>
+        ///  将任何数据添加到redis中
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="key"></param>
+        /// <param name="value"></param>
+        /// <param name="timeout"></param>
+        /// <returns></returns>
+        public async Task<bool> StringSetAsync<T>(string key, T value, TimeSpan? timeout = null)
+        {
+            return await _client.StringSetAsync(key, SerializeHelper.Serialize(value), timeout);
+        }
+
+        public async Task<long> StringDecrementAsync(string key, long value = 1L)
+        {
+            return await _client.StringDecrementAsync(key, value);
+        }
+
+        public async Task<long> StringIncrementAsync(string key, long value = 1L)
+        {
+            return await _client.StringIncrementAsync(key, value);
+        }
+        #endregion
+
+        #region String 读操作
+
+        /// <summary>
+        /// 根据key获取指定类型数据
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="key"></param>
+        /// <returns></returns>
+        public async Task<T> StringGetAsync<T>(string key)
+        {
+            return SerializeHelper.Deserialize<T>(await _client.StringGetAsync(key, CommandFlags.PreferSlave));
+        }
+
+        #endregion
+
+    }
+}

+ 6 - 0
OASystem/OASystem.sln

@@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EntitySync", "EntitySync\En
 EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "_Doc", "_Doc\_Doc.csproj", "{F832A3AA-9BDB-4699-854C-5A4C2948DDDC}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OASystem.RedisRepository", "OASystem.RedisRepository\OASystem.RedisRepository.csproj", "{3D0BF9D4-0214-4464-94CB-C09D97C6912F}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -39,6 +41,10 @@ Global
 		{F832A3AA-9BDB-4699-854C-5A4C2948DDDC}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{F832A3AA-9BDB-4699-854C-5A4C2948DDDC}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{F832A3AA-9BDB-4699-854C-5A4C2948DDDC}.Release|Any CPU.Build.0 = Release|Any CPU
+		{3D0BF9D4-0214-4464-94CB-C09D97C6912F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{3D0BF9D4-0214-4464-94CB-C09D97C6912F}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{3D0BF9D4-0214-4464-94CB-C09D97C6912F}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{3D0BF9D4-0214-4464-94CB-C09D97C6912F}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 275 - 0
gitignore

@@ -0,0 +1,275 @@
+## Ignore Visual Studio temporary files, build results, and
+## files generated by popular Visual Studio add-ons.
+##
+## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
+
+# User-specific files
+*.suo
+*.user
+*.userosscache
+*.sln.docstates
+*.vcxproj.filters
+
+# User-specific files (MonoDevelop/Xamarin Studio)
+*.userprefs
+
+# Build results
+[Dd]ebug/
+[Dd]ebugPublic/
+[Rr]elease/
+[Rr]eleases/
+x64/
+x86/
+bld/
+[Bb]in/
+[Oo]bj/
+[Ll]og/
+
+# Visual Studio 2015 cache/options directory
+.vs/
+# Uncomment if you have tasks that create the project's static files in wwwroot
+#wwwroot/
+
+# MSTest test Results
+[Tt]est[Rr]esult*/
+[Bb]uild[Ll]og.*
+
+# NUNIT
+*.VisualState.xml
+TestResult.xml
+
+# Build Results of an ATL Project
+[Dd]ebugPS/
+[Rr]eleasePS/
+dlldata.c
+
+# .NET Core
+project.lock.json
+project.fragment.lock.json
+artifacts/
+**/Properties/launchSettings.json
+
+*_i.c
+*_p.c
+*_i.h
+*.ilk
+*.meta
+*.obj
+*.pch
+*.pdb
+*.pgc
+*.pgd
+*.rsp
+*.sbr
+*.tlb
+*.tli
+*.tlh
+*.tmp
+*.tmp_proj
+*.log
+*.vspscc
+*.vssscc
+.builds
+*.pidb
+*.svclog
+*.scc
+
+# Chutzpah Test files
+_Chutzpah*
+
+# Visual C++ cache files
+ipch/
+*.aps
+*.ncb
+*.opendb
+*.opensdf
+*.sdf
+*.cachefile
+*.VC.db
+*.VC.VC.opendb
+
+# Visual Studio profiler
+*.psess
+*.vsp
+*.vspx
+*.sap
+
+# TFS 2012 Local Workspace
+$tf/
+
+# Guidance Automation Toolkit
+*.gpState
+
+# ReSharper is a .NET coding add-in
+_ReSharper*/
+*.[Rr]e[Ss]harper
+*.DotSettings.user
+
+# JustCode is a .NET coding add-in
+.JustCode
+
+# TeamCity is a build add-in
+_TeamCity*
+
+# DotCover is a Code Coverage Tool
+*.dotCover
+
+# Visual Studio code coverage results
+*.coverage
+*.coveragexml
+
+# NCrunch
+_NCrunch_*
+.*crunch*.local.xml
+nCrunchTemp_*
+
+# MightyMoose
+*.mm.*
+AutoTest.Net/
+
+# Web workbench (sass)
+.sass-cache/
+
+# Installshield output folder
+[Ee]xpress/
+
+# DocProject is a documentation generator add-in
+DocProject/buildhelp/
+DocProject/Help/*.HxT
+DocProject/Help/*.HxC
+DocProject/Help/*.hhc
+DocProject/Help/*.hhk
+DocProject/Help/*.hhp
+DocProject/Help/Html2
+DocProject/Help/html
+
+# Click-Once directory
+publish/
+
+# Publish Web Output
+*.[Pp]ublish.xml
+*.azurePubxml
+# TODO: Comment the next line if you want to checkin your web deploy settings
+# but database connection strings (with potential passwords) will be unencrypted
+*.pubxml
+*.publishproj
+
+# Microsoft Azure Web App publish settings. Comment the next line if you want to
+# checkin your Azure Web App publish settings, but sensitive information contained
+# in these scripts will be unencrypted
+PublishScripts/
+
+# NuGet Packages
+*.nupkg
+# The packages folder can be ignored because of Package Restore
+**/packages/*
+# except build/, which is used as an MSBuild target.
+!**/packages/build/
+# Uncomment if necessary however generally it will be regenerated when needed
+#!**/packages/repositories.config
+# NuGet v3's project.json files produces more ignoreable files
+*.nuget.props
+*.nuget.targets
+
+# Microsoft Azure Build Output
+csx/
+*.build.csdef
+
+# Microsoft Azure Emulator
+ecf/
+rcf/
+
+# Windows Store app package directories and files
+AppPackages/
+BundleArtifacts/
+Package.StoreAssociation.xml
+_pkginfo.txt
+
+# Visual Studio cache files
+# files ending in .cache can be ignored
+*.[Cc]ache
+# but keep track of directories ending in .cache
+!*.[Cc]ache/
+
+# Others
+ClientBin/
+~$*
+*~
+*.dbmdl
+*.dbproj.schemaview
+*.jfm
+*.pfx
+*.publishsettings
+node_modules/
+orleans.codegen.cs
+
+# Since there are multiple workflows, uncomment next line to ignore bower_components
+# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
+#bower_components/
+
+# RIA/Silverlight projects
+Generated_Code/
+
+# Backup & report files from converting an old project file
+# to a newer Visual Studio version. Backup files are not needed,
+# because we have git ;-)
+_UpgradeReport_Files/
+Backup*/
+UpgradeLog*.XML
+UpgradeLog*.htm
+
+# SQL Server files
+*.mdf
+*.ldf
+
+# Business Intelligence projects
+*.rdl.data
+*.bim.layout
+*.bim_*.settings
+
+# Microsoft Fakes
+FakesAssemblies/
+
+# GhostDoc plugin setting file
+*.GhostDoc.xml
+
+# Node.js Tools for Visual Studio
+.ntvs_analysis.dat
+
+# Visual Studio 6 build log
+*.plg
+
+# Visual Studio 6 workspace options file
+*.opt
+
+# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
+*.vbw
+
+# Visual Studio LightSwitch build output
+**/*.HTMLClient/GeneratedArtifacts
+**/*.DesktopClient/GeneratedArtifacts
+**/*.DesktopClient/ModelManifest.xml
+**/*.Server/GeneratedArtifacts
+**/*.Server/ModelManifest.xml
+_Pvt_Extensions
+
+# Paket dependency manager
+.paket/paket.exe
+paket-files/
+
+# FAKE - F# Make
+.fake/
+
+# JetBrains Rider
+.idea/
+*.sln.iml
+
+# CodeRush
+.cr/
+
+# Python Tools for Visual Studio (PTVS)
+__pycache__/
+*.pyc
+
+# Cake - Uncomment if you are using it
+# tools/