ソースを参照

忽略文件和redis缓存

zhoufan 7 年 前
コミット
b11d08dbc8

+ 27 - 0
.gitignore

@@ -0,0 +1,27 @@
1
+################################################################################
2
+# 此 .gitignore 文件已由 Microsoft(R) Visual Studio 自动创建。
3
+################################################################################
4
+
5
+/.vs
6
+/CallCenterApi/CallCenterApi.BLL/obj
7
+/CallCenterApi/CallCenterApi.BLL/bin
8
+/CallCenterApi/CallCenterApi.Common/obj
9
+/CallCenterApi/CallCenterApi.Common/bin
10
+/CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/obj
11
+/CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/bin
12
+/CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/CallCenterApi.Interface.csproj.user
13
+/CallCenterApi/CallCenterApi.DB/obj
14
+/CallCenterApi/CallCenterApi.DB/bin
15
+/CallCenterApi/CallCenterApi.DAL/obj
16
+/CallCenterApi/CallCenterApi.DAL/bin
17
+/CallCenterApi/CallCenterAPI.WechatSDK/obj
18
+/CallCenterApi/CallCenterAPI.WechatSDK/bin
19
+/CallCenterApi/CallCenterApi.Model/obj
20
+/CallCenterApi/CallCenterApi.Model/bin
21
+/CallCenterCommon/CallCenter.Utility/obj
22
+/CallCenterCommon/CallCenter.Utility/bin
23
+/CallCenterCommon/CallCenter.QuartzService/obj
24
+/CallCenterCommon/CallCenter.QuartzService/bin
25
+/CallCenterCommon/CallCenter.WebChatServer/obj
26
+/CallCenterCommon/CallCenter.WebChatServer/bin
27
+/packages

+ 26 - 18
CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/App_Start/AuthorizeAttribute.cs

@@ -29,24 +29,32 @@ namespace CallCenterApi.Interface
29 29
                 var action = actionDescriptor.ActionName;
30 30
                 var token = filterContext.HttpContext.Request["token"];
31 31
 
32
-                var userData = CacheHelper.Get<Dictionary<string, string>>(token);
33
-                var roleId = Utils.StrToInt(userData["F_RoleID"], 0);
34
-                //var role = new BLL.T_Sys_RoleInfo().GetModel(roleId);
35
-                //if (role != null)
36
-                //{
37
-                //    isAuth = true;
38
-                //    //var roleFunctionList = roleFunctionBLL.GetModelList(" F_RoleId=" + role.F_RoleId);
39
-                //    ////var str = string.Join(",", roleFunctionList.Select(x => x.F_FunctionId).ToArray());
40
-                //    //var moduleFunction = new BLL.T_Sys_Function().GetModel(roleId);
41
-                //    //if (moduleFunction != null)
42
-                //    //{
43
-                //    //    var single = roleFunctionList.SingleOrDefault(x => x.F_FunctionId == moduleFunction.F_FunctionId);
44
-                //    //    if (single != null)
45
-                //    //    {
46
-                //    //        isAuth = true;
47
-                //    //    }
48
-                //    //}
49
-                //}
32
+                //var userData = CacheHelper.Get<Dictionary<string, string>>(token);
33
+                var userDatastr = RedisHelper.StringGet(token);
34
+                if (userDatastr != null)
35
+                {
36
+                    Dictionary<string, string> userData = new Dictionary<string, string>();
37
+                    userData = userDatastr.ToString().ToObject<Dictionary<string, string>>();
38
+                    var roleId = Utils.StrToInt(userData["F_RoleID"], 0);
39
+
40
+                    //var roleId = Utils.StrToInt(userData["F_RoleID"], 0);
41
+                    //var role = new BLL.T_Sys_RoleInfo().GetModel(roleId);
42
+                    //if (role != null)
43
+                    //{
44
+                    //    isAuth = true;
45
+                    //    //var roleFunctionList = roleFunctionBLL.GetModelList(" F_RoleId=" + role.F_RoleId);
46
+                    //    ////var str = string.Join(",", roleFunctionList.Select(x => x.F_FunctionId).ToArray());
47
+                    //    //var moduleFunction = new BLL.T_Sys_Function().GetModel(roleId);
48
+                    //    //if (moduleFunction != null)
49
+                    //    //{
50
+                    //    //    var single = roleFunctionList.SingleOrDefault(x => x.F_FunctionId == moduleFunction.F_FunctionId);
51
+                    //    //    if (single != null)
52
+                    //    //    {
53
+                    //    //        isAuth = true;
54
+                    //    //    }
55
+                    //    //}
56
+                    //}
57
+                }
50 58
             }
51 59
             else
52 60
             {

+ 3 - 0
CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/Configs/system.config

@@ -44,6 +44,9 @@
44 44
   <add key="WeiBoAppSercet" value="eaab3093e1c01f6c9079b13419d89594" />
45 45
   <!--应用的access_token-->
46 46
   <add key="WeiBoAccessToken" value="2.00VbCStC01bkzx7bc0709d60OZTfkC" />
47
+  <!-- ================== 5:Redis配置 ================== -->
48
+  <add key="Redis_Server" value="192.168.4.18"/>
49
+  <add key="Redis_Port" value="6379"/>
47 50
   <!-- ================== 6:商丘市政务服务网和12345系统对接接口-添加工单 ================== -->
48 51
   <add key="SecurityCode" value="shangqiu12345%#@6" />
49 52
   <add key="ReplyInfoUrl" value="http://wszw.shangqiu.gov.cn/dzjcRest/saveReplyInfo.do" />

+ 38 - 3
CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/Controllers/HomeController.cs

@@ -252,6 +252,44 @@ namespace CallCenterApi.Interface.Controllers
252 252
             return View("Index");
253 253
         }
254 254
 
255
+        public ActionResult GetRedis(string key)
256
+        {
257
+            List<object> caches = new List<object>();
258
+            var keys = RedisHelper.GetKeyList(string.IsNullOrEmpty(key) ? "" : key);
259
+
260
+            foreach (var k in keys)
261
+            {
262
+                caches.Add(new
263
+                {
264
+                    key = k,
265
+                    value = RedisHelper.StringGet(k),
266
+                    outtime=RedisHelper.GetKeyOutTime(k)
267
+                });
268
+            }
269
+            return Success("成功", caches);
270
+        }
271
+
272
+        public ActionResult UpdateRedis(string key, string value, int second = 10)
273
+        {
274
+            List<object> caches = new List<object>();
275
+            var keys = RedisHelper.GetKeyList(string.IsNullOrEmpty(key) ? "" : key);
276
+
277
+            foreach (var k in keys)
278
+            {
279
+                RedisHelper.StringSet(k, value, new TimeSpan(0, 0, second));
280
+            }
281
+            return Success("成功");
282
+        }
283
+
284
+        public ActionResult DeleteRedis(string key)
285
+        {
286
+            List<object> caches = new List<object>();
287
+            var keys = RedisHelper.GetKeyList(string.IsNullOrEmpty(key) ? "" : key);
288
+
289
+            long n = RedisHelper.KeysDelete(keys);
290
+            return Success("成功", n);
291
+        }
292
+
255 293
         public ActionResult GetAllCache()
256 294
         {
257 295
             System.Web.Caching.Cache cache = HttpRuntime.Cache;
@@ -275,9 +313,6 @@ namespace CallCenterApi.Interface.Controllers
275 313
                 sb.Append($"F_UserCode={dic["F_UserCode"]}, ");
276 314
                 sb.Append($"F_UserName={dic["F_UserName"]} ");
277 315
 
278
-
279
-
280
-
281 316
                 caches.Add(new cacheobj
282 317
                 {
283 318
                     key = cacheEnum.Key.ToString().Substring(0, 20),

+ 13 - 8
CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/Controllers/IndexController.cs

@@ -700,14 +700,16 @@ namespace CallCenterApi.Interface.Controllers
700 700
         [Authority]
701 701
         public ActionResult GetRoleList()
702 702
         {
703
-            DataTable dt = new DataTable();
704
-            dt = rolebll.GetAllList().Tables[0];
705
-            var dtCache = CacheHelper.Get<DataTable>($"RoleList");
703
+            //var dtCache = CacheHelper.Get<DataTable>($"RoleList");
704
+            var dtCache = RedisHelper.StringGet("RoleList");
706 705
             if (dtCache != null)
707 706
             {
708
-                return Success("获取成功", dtCache);
707
+                return Success("获取成功", dtCache.ToString().ToObject<DataTable>());
709 708
             }
710
-            CacheHelper.Insert($"RoleList", dt, 10);
709
+            DataTable dt = new DataTable();
710
+            dt = rolebll.GetAllList().Tables[0];
711
+            //CacheHelper.Insert($"RoleList", dt, 10);
712
+            RedisHelper.StringSet("RoleList", dt.ToJson(), new TimeSpan(0, 10, 0));
711 713
             return Success("获取成功", dt);
712 714
         }
713 715
 
@@ -729,9 +731,11 @@ namespace CallCenterApi.Interface.Controllers
729 731
             string sql1 = "SELECT FromUserId,COUNT(1)AS counts FROM T_Msg_Chat_Map WHERE ToUserId = " + userId + " AND ISNULL(IsRead,0) = 0 AND CreateDate > '" + start + "' group by FromUserId order by FromUserId";
730 732
             var dt1 = DbHelperSQL.Query(sql1).Tables[0];
731 733
             //缓存
732
-            var dtCache = CacheHelper.Get<DataTable>($"UserList{roleid}");
733
-            if (dtCache != null)
734
+            //var dtCache = CacheHelper.Get<DataTable>($"UserList{roleid}");
735
+            var objCache = RedisHelper.StringGet($"UserList{roleid}");
736
+            if (objCache != null)
734 737
             {
738
+                var dtCache = objCache.ToString().ToObject<DataTable>();
735 739
                 #region 提示统计
736 740
                 if (!string.IsNullOrEmpty(keyword))
737 741
                 {
@@ -764,7 +768,8 @@ namespace CallCenterApi.Interface.Controllers
764 768
                 dr["counts"] = list.Count() > 0 ? list[0]["counts"].ToString() : "0";
765 769
             }
766 770
             //缓存保存
767
-            CacheHelper.Insert($"UserList{roleid}", dt, 10);
771
+            //CacheHelper.Insert($"UserList{roleid}", dt, 10);
772
+            RedisHelper.StringSet($"UserList{roleid}",dt.ToJson(), new TimeSpan(0, 10, 0));
768 773
             if (!string.IsNullOrEmpty(keyword))
769 774
             {
770 775
                 dt = ToDataTable1(dt.Select("F_UserName LIKE '%" + keyword + "%' OR F_UserCode LIKE '%" + keyword + "%'"));

+ 11 - 6
CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/Controllers/Login/LoginController.cs

@@ -98,9 +98,11 @@ namespace CallCenterApi.Interface.Controllers
98 98
                                 F_State = 0
99 99
                             });
100 100
                             var token = FormsPrincipal<Dictionary<string, string>>.GetCookieValue(Dic["F_UserCode"], Dic);
101
-                           
102
-                            //放入缓存
103
-                            CacheHelper.Insert(token, Dic, 1440, System.Web.Caching.CacheItemPriority.NotRemovable, onRemove);
101
+
102
+                            ////放入缓存
103
+                            //CacheHelper.Insert(token, Dic, 1440, System.Web.Caching.CacheItemPriority.NotRemovable, onRemove);
104
+                            //放入redis缓存
105
+                            RedisHelper.StringSet(token,Dic.ToJson(),new TimeSpan(24,0,0));
104 106
 
105 107
                             return Success("登录成功", new
106 108
                             {
@@ -250,8 +252,10 @@ namespace CallCenterApi.Interface.Controllers
250 252
                           
251 253
                             var token = FormsPrincipal<Dictionary<string, string>>.GetCookieValue(Dic["F_UserCode"], Dic);
252 254
 
253
-                            //放入缓存
254
-                            CacheHelper.Insert(token, Dic, 1440, System.Web.Caching.CacheItemPriority.NotRemovable);
255
+                            ////放入缓存
256
+                            //CacheHelper.Insert(token, Dic, 1440, System.Web.Caching.CacheItemPriority.NotRemovable);
257
+                            //放入redis缓存
258
+                            RedisHelper.StringSet(token, Dic.ToJson(), new TimeSpan(24, 0, 0));
255 259
                             return Success("登录成功", new
256 260
                             {
257 261
                                 token = token
@@ -318,7 +322,8 @@ namespace CallCenterApi.Interface.Controllers
318 322
         {
319 323
             if (Request.IsAuthenticated)
320 324
             {
321
-                CacheHelper.Remove(token);
325
+                //CacheHelper.Remove(token);
326
+                RedisHelper.KeyDelete(token);
322 327
             }
323 328
             return Success("退出成功");
324 329
         }

+ 45 - 32
CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/Controllers/WebController.cs

@@ -384,9 +384,11 @@ namespace CallCenterApi.Interface.Controllers
384 384
                 if (newsBLL.Add(orderModel) > 0)
385 385
                 {
386 386
                     if (iszd > 0)
387
-                        CacheHelper.Remove($"ImgNewsList{type}1");
387
+                        //CacheHelper.Remove($"ImgNewsList{type}1");
388
+                        RedisHelper.KeyDelete($"ImgNewsList{type}1");
388 389
                     else
389
-                        CacheHelper.Remove($"NewsList{type}");
390
+                        //CacheHelper.Remove($"NewsList{type}");
391
+                        RedisHelper.KeyDelete($"NewsList{type}");
390 392
                     return Success("新闻添加成功");
391 393
                 }
392 394
                 else
@@ -408,10 +410,13 @@ namespace CallCenterApi.Interface.Controllers
408 410
                     if (newsBLL.Update(orderModel))
409 411
                     {
410 412
                         if (iszd > 0)
411
-                            CacheHelper.Remove($"ImgNewsList{type}1");
413
+                            //CacheHelper.Remove($"ImgNewsList{type}1");
414
+                            RedisHelper.KeyDelete($"ImgNewsList{type}1");
412 415
                         else
413
-                            CacheHelper.Remove($"NewsList{type}");
414
-                        CacheHelper.Remove($"WebNews{orderModel.id}");
416
+                            //CacheHelper.Remove($"NewsList{type}");
417
+                            RedisHelper.KeyDelete($"NewsList{type}");
418
+                        //CacheHelper.Remove($"WebNews{orderModel.id}");
419
+                        RedisHelper.KeyDelete($"WebNews{orderModel.id}");
415 420
                         return Success("新闻修改成功");
416 421
                     }
417 422
                     else
@@ -444,22 +449,25 @@ namespace CallCenterApi.Interface.Controllers
444 449
             {
445 450
                 foreach (var id in ids)
446 451
                 {
447
-                    CacheHelper.Remove($"WebNews{id}");
452
+                    //CacheHelper.Remove($"WebNews{id}");
453
+                    RedisHelper.KeyDelete($"WebNews{id}");
448 454
                 }
449 455
 
450
-                System.Web.Caching.Cache cache = HttpRuntime.Cache;
451
-                IDictionaryEnumerator cacheEnum = cache.GetEnumerator();
452
-                List<string> keys = new List<string>();
453
-                while (cacheEnum.MoveNext())
454
-                {
455
-                    keys.Add(cacheEnum.Key.ToString());
456
-                }
457
-
458
-                var query = keys.Where(x => x.Contains("ImgNewsList") || x.Contains("NewsList")).ToList();
459
-                foreach (var key in query)
460
-                {
461
-                    CacheHelper.Remove(key);
462
-                }
456
+                //System.Web.Caching.Cache cache = HttpRuntime.Cache;
457
+                //IDictionaryEnumerator cacheEnum = cache.GetEnumerator();
458
+                //List<string> keys = new List<string>();
459
+                //while (cacheEnum.MoveNext())
460
+                //{
461
+                //    keys.Add(cacheEnum.Key.ToString());
462
+                //}
463
+
464
+                //var query = keys.Where(x => x.Contains("ImgNewsList") || x.Contains("NewsList")).ToList();
465
+                //foreach (var key in query)
466
+                //{
467
+                //    CacheHelper.Remove(key);
468
+                //}
469
+                RedisHelper.KeysDelete(RedisHelper.GetKeyList("ImgNewsList"));
470
+                RedisHelper.KeysDelete(RedisHelper.GetKeyList("NewsList"));
463 471
                 return Success("删除成功");
464 472
             }
465 473
             else
@@ -696,10 +704,11 @@ namespace CallCenterApi.Interface.Controllers
696 704
         {
697 705
             int type = RequestString.GetInt("type", 0);
698 706
             int num = RequestString.GetInt("num", 6);
699
-            var dtCache = CacheHelper.Get<DataTable>($"ImgNewsList{type}1");
707
+            //var dtCache = CacheHelper.Get<DataTable>($"ImgNewsList{type}1");
708
+            var dtCache = RedisHelper.StringGet($"ImgNewsList{type}1");
700 709
             if (dtCache != null)
701 710
             {
702
-                return Success("成功", dtCache);
711
+                return Success("成功", dtCache.ToString().ToObject<DataTable>());
703 712
             }
704 713
             var sql = " select top " + num + " * from T_Web_News where iszd=1 ";
705 714
             Dictionary<string, string> paras = new Dictionary<string, string>();
@@ -728,8 +737,9 @@ namespace CallCenterApi.Interface.Controllers
728 737
                     dr["urlname"] = configfj.F_ParamValue + smallurl;
729 738
                 }
730 739
             }
731
-            // key=ImgNewsList+type+iszd
732
-            CacheHelper.Insert($"ImgNewsList{type}1", dt, 10);
740
+            //// key=ImgNewsList+type+iszd
741
+            //CacheHelper.Insert($"ImgNewsList{type}1", dt, 10);
742
+            RedisHelper.StringSet($"ImgNewsList{type}1", dt.ToJson(), new TimeSpan(0, 10, 0));
733 743
             return Success("成功", dt);
734 744
         }
735 745
 
@@ -741,10 +751,11 @@ namespace CallCenterApi.Interface.Controllers
741 751
         {
742 752
             int type = RequestString.GetInt("type", 0);
743 753
             int num = RequestString.GetInt("num", 8);
744
-            var dtCache = CacheHelper.Get<DataTable>($"NewsList{type}");
754
+            //var dtCache = CacheHelper.Get<DataTable>($"NewsList{type}");
755
+            var dtCache = RedisHelper.StringGet($"NewsList{type}");
745 756
             if (dtCache != null)
746 757
             {
747
-                return Success("成功", dtCache);
758
+                return Success("成功", dtCache.ToString().ToObject<DataTable>());
748 759
             }
749 760
             var sql = " select top " + num + " * from T_Web_News where 1=1 ";
750 761
             Dictionary<string, string> paras = new Dictionary<string, string>();
@@ -773,9 +784,9 @@ namespace CallCenterApi.Interface.Controllers
773 784
                     dr["urlname"] = configfj.F_ParamValue + smallurl;
774 785
                 }
775 786
             }
776
-            // key=NewsList+type
777
-            CacheHelper.Insert($"NewsList{type}", dt, 10);
778
-
787
+            //// key=NewsList+type
788
+            //CacheHelper.Insert($"NewsList{type}", dt, 10);
789
+            RedisHelper.StringSet($"NewsList{type}",dt.ToJson(), new TimeSpan(0, 10, 0));
779 790
             return Success("成功", dt);
780 791
         }
781 792
 
@@ -789,10 +800,11 @@ namespace CallCenterApi.Interface.Controllers
789 800
 
790 801
             int id = RequestString.GetInt("id", 0);
791 802
 
792
-            var newsCache = CacheHelper.Get<Model.T_Web_News>($"WebNews{id}");
803
+            //var newsCache = CacheHelper.Get<Model.T_Web_News>($"WebNews{id}");
804
+            var newsCache = RedisHelper.StringGet($"WebNews{id}");
793 805
             if (newsCache != null)
794 806
             {
795
-                return Success("成功", newsCache);
807
+                return Success("成功", newsCache.ToString().ToObject<Model.T_Web_News>());
796 808
             }
797 809
             var configfj = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='FileUrlPath' ").FirstOrDefault();
798 810
             var configfjedit = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='EditFilePath' ").FirstOrDefault();
@@ -813,8 +825,9 @@ namespace CallCenterApi.Interface.Controllers
813 825
 
814 826
                     baseModel.nr = baseModel.nr.Replace("\"/js/kindeditor", "\"" + uri.Scheme + "://" + uri.Authority + "/js/kindeditor");
815 827
                 }
816
-                // key=action+id
817
-                CacheHelper.Insert($"WebNews{id}", baseModel, 10);
828
+                //// key=action+id
829
+                //CacheHelper.Insert($"WebNews{id}", baseModel, 10);
830
+                RedisHelper.StringSet($"WebNews{id}",baseModel.ToJson(), new TimeSpan(0, 10, 0));
818 831
                 return Success("加载成功", baseModel);
819 832
             }
820 833
             else

+ 5 - 2
CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/Global.asax.cs

@@ -84,8 +84,11 @@ namespace CallCenterApi.Interface
84 84
             }
85 85
             try
86 86
             {
87
-                //获取缓存
88
-                var dict = CacheHelper.Get(token);
87
+                ////获取缓存
88
+                //var dict = CacheHelper.Get(token);
89
+                //获取redis缓存
90
+                var dict = RedisHelper.StringGet(token);
91
+
89 92
                 if (dict == null)
90 93
                 {
91 94
                     //log.Debug(Params.ToJson());

+ 5 - 0
CallCenterCommon/CallCenter.Utility/CallCenter.Utility.csproj

@@ -55,10 +55,14 @@
55 55
       <HintPath>..\..\packages\NPOI.2.3.0\lib\net40\NPOI.OpenXmlFormats.dll</HintPath>
56 56
       <Private>True</Private>
57 57
     </Reference>
58
+    <Reference Include="StackExchange.Redis, Version=1.2.6.0, Culture=neutral, processorArchitecture=MSIL">
59
+      <HintPath>..\..\packages\StackExchange.Redis.1.2.6\lib\net45\StackExchange.Redis.dll</HintPath>
60
+    </Reference>
58 61
     <Reference Include="System" />
59 62
     <Reference Include="System.Configuration" />
60 63
     <Reference Include="System.Core" />
61 64
     <Reference Include="System.Drawing" />
65
+    <Reference Include="System.IO.Compression" />
62 66
     <Reference Include="System.Management" />
63 67
     <Reference Include="System.Web" />
64 68
     <Reference Include="System.Xml.Linq" />
@@ -79,6 +83,7 @@
79 83
     <Compile Include="Linq\LinqExtend.cs" />
80 84
     <Compile Include="Linq\PredicateExtensionses.cs" />
81 85
     <Compile Include="log\LogInterface.cs" />
86
+    <Compile Include="RedisHelper.cs" />
82 87
     <Compile Include="SaltAndHashHelper.cs" />
83 88
     <Compile Include="SysInformationHelper.cs" />
84 89
     <Compile Include="Time\DateTimeConvert.cs" />

+ 790 - 0
CallCenterCommon/CallCenter.Utility/RedisHelper.cs

@@ -0,0 +1,790 @@
1
+using System;
2
+using StackExchange.Redis;
3
+using System.Collections.Generic;
4
+using System.Linq;
5
+using Newtonsoft.Json;
6
+using System.Collections;
7
+
8
+namespace CallCenter.Utility
9
+{
10
+    public class RedisHelper
11
+    {
12
+        #region 
13
+        //执行顺序---静态字段---静态构造函数---构造函数
14
+        private static ConnectionMultiplexer redis;
15
+
16
+        static RedisHelper()
17
+        {
18
+            if (redis == null || !redis.IsConnected)
19
+            {
20
+                redis = ConnectionMultiplexer.Connect(Configs.GetValue("Redis_Server")+":"+Configs.GetValue("Redis_Port"));
21
+                //redis = ConnectionMultiplexer.Connect("192.168.4.18, abortConnect=false");
22
+            }
23
+        }
24
+
25
+        #endregion
26
+
27
+        #region redis 字符串(string)操作
28
+
29
+        /// <summary>
30
+        /// 设置指定键的值
31
+        /// </summary>
32
+        /// <param name="key"></param>
33
+        /// <param name="value"></param>
34
+        /// <returns></returns>
35
+        public static bool StringSet(string key, string value)
36
+        {
37
+            return redis.GetDatabase().StringSet(key, value);
38
+        }
39
+
40
+        /// <summary>
41
+        /// 获取指定键的值
42
+        /// </summary>
43
+        /// <param name="key"></param>
44
+        /// <returns></returns>
45
+        public static object StringGet(string key)
46
+        {
47
+            var rt= redis.GetDatabase().StringGet(key);
48
+
49
+            if (rt.IsNull)
50
+            {
51
+                return null;
52
+            }
53
+            else
54
+            {
55
+                return rt;
56
+            }
57
+        }
58
+
59
+        /// <summary>
60
+        /// 获取存储在键上的字符串的子字符串
61
+        /// </summary>
62
+        /// <param name="key"></param>
63
+        /// <param name="start"></param>
64
+        /// <param name="end"></param>
65
+        /// <returns></returns>
66
+        public static object StringGet(string key, int start, int end)
67
+        {
68
+            var rt = redis.GetDatabase().StringGetRange(key, start, end);
69
+            if (rt.IsNull)
70
+            {
71
+                return null;
72
+            }
73
+            else
74
+            {
75
+                return rt;
76
+            }
77
+        }
78
+
79
+        /// <summary>
80
+        /// 设置键的字符串值并返回其旧值
81
+        /// </summary>
82
+        /// <param name="key"></param>
83
+        /// <param name="value"></param>
84
+        /// <returns></returns>
85
+        public static object StringGetAndSet(string key, string value)
86
+        {
87
+            var rt = redis.GetDatabase().StringGetSet(key, value);
88
+            if (rt.IsNull)
89
+            {
90
+                return null;
91
+            }
92
+            else
93
+            {
94
+                return rt;
95
+            }
96
+        }
97
+
98
+        /// <summary>
99
+        /// 返回在键处存储的字符串值中偏移处的位值
100
+        /// </summary>
101
+        /// <param name="key"></param>
102
+        /// <param name="offset"></param>
103
+        /// <returns></returns>
104
+        public static bool StringGetBit(string key, long offset)
105
+        {
106
+            return redis.GetDatabase().StringGetBit(key, offset);
107
+        }
108
+
109
+        /// <summary>
110
+        /// 获取所有给定键的值
111
+        /// </summary>
112
+        /// <param name="keys"></param>
113
+        /// <returns></returns>
114
+        public static List<object> StringMultiGet(string[] keys)
115
+        {
116
+            List<object> list = new List<object>();
117
+            for (int i = 0; i < keys.Length; i++)
118
+            {
119
+                list.Add(redis.GetDatabase().StringGet(keys[i]));
120
+            }
121
+            return list;
122
+        }
123
+
124
+        /// <summary>
125
+        /// 存储在键上的字符串值中设置或清除偏移处的位
126
+        /// </summary>
127
+        /// <param name="key"></param>
128
+        /// <param name="offset"></param>
129
+        /// <param name="value"></param>
130
+        /// <returns></returns>
131
+        public static bool StringSetBit(string key, long offset)
132
+        {
133
+            return redis.GetDatabase().StringSetBit(key, offset, true);
134
+        }
135
+
136
+        /// <summary>
137
+        /// 使用键和到期时间来设置值
138
+        /// </summary>
139
+        /// <param name="key"></param>
140
+        /// <param name="value"></param>
141
+        /// <param name="expiry"></param>
142
+        /// <returns></returns>
143
+        public static bool StringSet(string key, string value, TimeSpan expiry)
144
+        {
145
+            return redis.GetDatabase().StringSet(key, value, expiry);
146
+        }
147
+
148
+        /// <summary>
149
+        /// 设置键的值,仅当键不存在时
150
+        /// </summary>
151
+        /// <param name="key"></param>
152
+        /// <param name="value"></param>
153
+        /// <returns></returns>
154
+        public static void StringSetIfAbsent(string key, string value)
155
+        {
156
+            if (redis.GetDatabase().StringGet(key) == RedisValue.Null)
157
+            {
158
+                redis.GetDatabase().StringSet(key, value);
159
+            }
160
+        }
161
+
162
+        /// <summary>
163
+        /// 在指定偏移处开始的键处覆盖字符串的一部分
164
+        /// </summary>
165
+        /// <param name="key">键值</param>
166
+        /// <param name="value">值</param>
167
+        /// <param name="offset">偏移量</param>
168
+        /// <returns></returns>
169
+        public static object StringSet(string key, long offset, string value)
170
+        {
171
+            return redis.GetDatabase().StringSetRange(key, offset, value);
172
+        }
173
+
174
+        /// <summary>
175
+        /// 获取存储在键中的值的长度
176
+        /// </summary>
177
+        /// <param name="key">键值</param>
178
+        /// <returns></returns>
179
+        public static long StringSize(string key)
180
+        {
181
+            return redis.GetDatabase().StringLength(key);
182
+        }
183
+
184
+        /// <summary>
185
+        /// 为多个键分别设置它们的值
186
+        /// </summary>
187
+        /// <param name="keys"></param>
188
+        /// <returns></returns>
189
+        public static void StringMultiSet(Dictionary<string, string> dic)
190
+        {
191
+            foreach (KeyValuePair<string, string> key in dic)
192
+            {
193
+                redis.GetDatabase().StringSet(key.Key, key.Value);
194
+            }
195
+        }
196
+
197
+        /// <summary>
198
+        /// 为多个键分别设置它们的值,仅当键不存在时
199
+        /// </summary>
200
+        /// <param name="keys">键值集合</param>
201
+        /// <returns></returns>
202
+        public static void StringMultiSetIfAbsent(Dictionary<string, string> dic)
203
+        {
204
+            foreach (KeyValuePair<string, string> key in dic)
205
+            {
206
+                //判断键值是否存在
207
+                if (redis.GetDatabase().StringGet(key.Key) == RedisValue.Null)
208
+                {
209
+                    redis.GetDatabase().StringSet(key.Key, key.Value);
210
+                }
211
+            }
212
+        }
213
+
214
+        /// <summary>
215
+        /// 将键的整数值按给定的数值增加
216
+        /// </summary>
217
+        /// <param name="key">键值</param>
218
+        /// <param name="value">给定的数值</param>
219
+        /// <returns></returns>
220
+        public static double StringIncrement(string key, double value)
221
+        {
222
+            return redis.GetDatabase().StringIncrement(key, value);
223
+        }
224
+
225
+        /// <summary>
226
+        /// 在key键对应值的右面追加值value
227
+        /// </summary>
228
+        /// <param name="key"></param>
229
+        /// <param name="value"></param>
230
+        /// <returns></returns>
231
+        public static long StringAppend(string key, string value)
232
+        {
233
+            return redis.GetDatabase().StringAppend(key, value);
234
+        }
235
+
236
+        /// <summary>
237
+        /// 删除某个键值
238
+        /// </summary>
239
+        /// <param name="key"></param>
240
+        /// <returns></returns>
241
+        public static bool StringDelete(string key)
242
+        {
243
+            return false;
244
+        }
245
+
246
+        #endregion
247
+
248
+        #region redis 哈希/散列/字典(Hash)操作
249
+
250
+        /// <summary>
251
+        /// 删除指定的哈希字段
252
+        /// </summary>
253
+        /// <param name="key"></param>
254
+        /// <param name="field"></param>
255
+        /// <returns></returns>
256
+        public static bool HashDelete(string key, string field)
257
+        {
258
+            return redis.GetDatabase().HashDelete(key, field);
259
+        }
260
+
261
+        /// <summary>
262
+        /// 判断是否存在散列字段
263
+        /// </summary>
264
+        /// <param name=""></param>
265
+        /// <param name=""></param>
266
+        /// <returns></returns>
267
+        public static bool HashHasKey(string key, string field)
268
+        {
269
+            return redis.GetDatabase().HashExists(key, field);
270
+        }
271
+
272
+        /// <summary>
273
+        /// 获取存储在指定键的哈希字段的值
274
+        /// </summary>
275
+        /// <param name="key"></param>
276
+        /// <param name="field"></param>
277
+        /// <returns></returns>
278
+        public static object HashGet(string key, string field)
279
+        {
280
+            return redis.GetDatabase().HashGet(key, field);
281
+        }
282
+
283
+        /// <summary>
284
+        /// 获取存储在指定键的哈希中的所有字段和值
285
+        /// </summary>
286
+        /// <param name="key"></param>
287
+        /// <returns></returns>
288
+        public static Dictionary<string, object> HashGetAll(string key)
289
+        {
290
+            Dictionary<string, object> dic = new Dictionary<string, object>();
291
+            var collection = redis.GetDatabase().HashGetAll(key);
292
+            foreach (var item in collection)
293
+            {
294
+                dic.Add(item.Name, item.Value);
295
+            }
296
+            return dic;
297
+        }
298
+
299
+        /// <summary>
300
+        /// 将哈希字段的浮点值按给定数值增加
301
+        /// </summary>
302
+        /// <param name="key"></param>
303
+        /// <param name="field"></param>
304
+        /// <param name="value">给定的数值</param>
305
+        /// <returns></returns>
306
+        public static double HashIncrement(string key, string field, double value)
307
+        {
308
+            return redis.GetDatabase().HashIncrement(key, field, value);
309
+        }
310
+
311
+        /// <summary>
312
+        /// 获取哈希中的所有字段
313
+        /// </summary>
314
+        /// <param name="key"></param>
315
+        /// <returns></returns>
316
+        public static string[] HashKeys(string key)
317
+        {
318
+            return redis.GetDatabase().HashKeys(key).ToStringArray();
319
+        }
320
+
321
+        /// <summary>
322
+        /// 获取散列中的字段数量
323
+        /// </summary>
324
+        /// <param name="key"></param>
325
+        /// <returns></returns>
326
+        public static long HashSize(string key)
327
+        {
328
+            return redis.GetDatabase().HashLength(key);
329
+        }
330
+
331
+        /// <summary>
332
+        /// 获取所有给定哈希字段的值
333
+        /// </summary>
334
+        /// <param name="key"></param>
335
+        /// <param name="hashKeys"></param>
336
+        /// <returns></returns>
337
+        public static List<object> HashMultiGet(string key, List<string> hashKeys)
338
+        {
339
+            List<object> result = new List<object>();
340
+            foreach (string field in hashKeys)
341
+            {
342
+                result.Add(redis.GetDatabase().HashGet(key, field));
343
+            }
344
+            return result;
345
+        }
346
+
347
+        /// <summary>
348
+        /// 为多个哈希字段分别设置它们的值
349
+        /// </summary>
350
+        /// <param name="key"></param>
351
+        /// <param name="dic"></param>
352
+        /// <returns></returns>
353
+        public static void HashPutAll(string key, Dictionary<string, string> dic)
354
+        {
355
+            List<HashEntry> list = new List<HashEntry>();
356
+            for (int i = 0; i < dic.Count; i++)
357
+            {
358
+                KeyValuePair<string, string> param = dic.ElementAt(i);
359
+                list.Add(new HashEntry(param.Key, param.Value));
360
+            }
361
+            redis.GetDatabase().HashSet(key, list.ToArray());
362
+        }
363
+
364
+        /// <summary>
365
+        /// 设置散列字段的字符串值
366
+        /// </summary>
367
+        /// <param name="key"></param>
368
+        /// <param name="field"></param>
369
+        /// <param name="value"></param>
370
+        /// <returns></returns>
371
+        public static void HashPut(string key, string field, string value)
372
+        {
373
+            redis.GetDatabase().HashSet(key, new HashEntry[] { new HashEntry(field, value) });
374
+        }
375
+
376
+        /// <summary>
377
+        /// 仅当字段不存在时,才设置散列字段的值
378
+        /// </summary>
379
+        /// <param name="key"></param>
380
+        /// <param name="fiels"></param>
381
+        /// <param name="value"></param>
382
+        /// <returns></returns>
383
+        public static void HashPutIfAbsent(string key, string field, string value)
384
+        {
385
+            if (!HashHasKey(key, field))
386
+            {
387
+                redis.GetDatabase().HashSet(key, new HashEntry[] { new HashEntry(field, value) });
388
+            }
389
+        }
390
+
391
+        /// <summary>
392
+        /// 获取哈希中的所有值
393
+        /// </summary>
394
+        /// <param name="key"></param>
395
+        /// <returns></returns>
396
+        public static string[] HashValues(string key)
397
+        {
398
+            return redis.GetDatabase().HashValues(key).ToStringArray();
399
+        }
400
+
401
+        /// <summary>
402
+        /// redis中获取指定键的值并返回对象
403
+        /// </summary>
404
+        /// <typeparam name="T"></typeparam>
405
+        /// <param name="key"></param>
406
+        /// <returns></returns>
407
+        public static T GetHashValue<T>(string key)
408
+        {
409
+            HashEntry[] array = redis.GetDatabase().HashGetAll(key);
410
+            Dictionary<string, object> dic = new Dictionary<string, object>();
411
+            for (int i = 0; i < array.Length; i++)
412
+            {
413
+                dic.Add(array[i].Name, array[i].Value);
414
+            }
415
+            if (dic.Count > 0)
416
+            {
417
+                string strJson = JsonConvert.SerializeObject(dic);
418
+                return JsonConvert.DeserializeObject<T>(strJson);
419
+            }
420
+            else
421
+            {
422
+                return default(T);
423
+            }
424
+        }
425
+
426
+        /// <summary>
427
+        /// 把指定对象存储在键值为key的redis中
428
+        /// </summary>
429
+        /// <typeparam name="T"></typeparam>
430
+        /// <param name="t"></param>
431
+        /// <param name="key"></param>
432
+        public static void SetHashValue<T>(T t, string key)
433
+        {
434
+            string strJson = JsonConvert.SerializeObject(t);
435
+            Dictionary<string, string> param = JsonConvert.DeserializeObject<Dictionary<string, string>>(strJson);
436
+            HashPutAll(key, param);
437
+        }
438
+
439
+        #endregion
440
+
441
+        #region redis 列表(List)操作
442
+
443
+        /// <summary>
444
+        /// 从左向右存压栈
445
+        /// </summary>
446
+        /// <param name="key"></param>
447
+        /// <param name="value"></param>
448
+        /// <returns></returns>
449
+        public static long ListLeftPush(string key, string value)
450
+        {
451
+            return redis.GetDatabase().ListLeftPush(key, value);
452
+        }
453
+
454
+        /// <summary>
455
+        /// 从左出栈
456
+        /// </summary>
457
+        /// <param name="key"></param>
458
+        /// <returns></returns>
459
+        public static object ListLeftPop(string key)
460
+        {
461
+            return redis.GetDatabase().ListLeftPop(key);
462
+        }
463
+
464
+        /// <summary>
465
+        /// 队/栈长
466
+        /// </summary>
467
+        /// <param name="key"></param>
468
+        /// <returns></returns>
469
+        public static long ListSize(string key)
470
+        {
471
+            return redis.GetDatabase().ListLength(key);
472
+        }
473
+
474
+        /// <summary>
475
+        /// 范围检索,返回List
476
+        /// </summary>
477
+        /// <param name="key"></param>
478
+        /// <param name="start"></param>
479
+        /// <param name="end"></param>
480
+        /// <returns></returns>
481
+        public static string[] ListRange(string key, int start, int end)
482
+        {
483
+            return redis.GetDatabase().ListRange(key, start, end).ToStringArray();
484
+        }
485
+
486
+        /// <summary>
487
+        /// 移除key中值为value的i个,返回删除的个数;如果没有这个元素则返回0 
488
+        /// </summary>
489
+        /// <param name="key"></param>
490
+        /// <param name="i"></param>
491
+        /// <param name="value"></param>
492
+        /// <returns></returns>
493
+        public static long ListRemove(string key, string value)
494
+        {
495
+            return redis.GetDatabase().ListRemove(key, value);
496
+        }
497
+
498
+        /// <summary>
499
+        /// 检索
500
+        /// </summary>
501
+        /// <param name="key"></param>
502
+        /// <param name="index"></param>
503
+        /// <returns></returns>
504
+        public static object ListIndex(string key, long index)
505
+        {
506
+            return redis.GetDatabase().ListGetByIndex(key, index);
507
+        }
508
+
509
+        /// <summary>
510
+        /// 赋值
511
+        /// </summary>
512
+        /// <param name="key"></param>
513
+        /// <param name="index"></param>
514
+        /// <param name="value"></param>
515
+        /// <returns></returns>
516
+        public static void ListSet(string key, int index, string value)
517
+        {
518
+            redis.GetDatabase().ListSetByIndex(key, index, value);
519
+        }
520
+
521
+        /// <summary>
522
+        /// 裁剪,删除除了[start,end]以外的所有元素 
523
+        /// </summary>
524
+        /// <param name="key"></param>
525
+        /// <param name="start"></param>
526
+        /// <param name="end"></param>
527
+        /// <returns></returns>
528
+        public static void ListTrim(string key, int start, int end)
529
+        {
530
+            redis.GetDatabase().ListTrim(key, start, end);
531
+        }
532
+
533
+        /// <summary>
534
+        /// 将源key的队列的右边的一个值删除,然后塞入目标key的队列的左边,返回这个值
535
+        /// </summary>
536
+        /// <param name="sourceKey"></param>
537
+        /// <param name="destinationKey"></param>
538
+        /// <returns></returns>
539
+        public static object ListRightPopAndLeftPush(string sourceKey, string destinationKey)
540
+        {
541
+            return redis.GetDatabase().ListRightPopLeftPush(sourceKey, destinationKey);
542
+        }
543
+
544
+        #endregion
545
+
546
+        #region redis 集合(Set)操作
547
+
548
+        /// <summary>
549
+        /// 集合添加元素
550
+        /// </summary>
551
+        /// <param name="key"></param>
552
+        /// <param name="value"></param>
553
+        public static void SetAdd(string key, string value)
554
+        {
555
+            redis.GetDatabase().SetAdd(key, value);
556
+        }
557
+
558
+        /// <summary>
559
+        /// 集合组合操作
560
+        /// </summary>
561
+        /// <param name="point">操作标示:0--并集;1--交集;2--差集</param>
562
+        /// <param name="firstKey">第一个集合的键值</param>
563
+        /// <param name="secondKey">第二个集合的键值</param>
564
+        public static string[] SetCombine(int point, string firstKey, string secondKey)
565
+        {
566
+            RedisValue[] array;
567
+            switch (point)
568
+            {
569
+                case 0:
570
+                    array = redis.GetDatabase().SetCombine(SetOperation.Union, firstKey, secondKey);
571
+                    break;
572
+                case 1:
573
+                    array = redis.GetDatabase().SetCombine(SetOperation.Intersect, firstKey, secondKey);
574
+                    break;
575
+                case 2:
576
+                    array = redis.GetDatabase().SetCombine(SetOperation.Difference, firstKey, secondKey);
577
+                    break;
578
+                default:
579
+                    array = new RedisValue[0];
580
+                    break;
581
+            }
582
+            return array.ToStringArray();
583
+        }
584
+
585
+        /// <summary>
586
+        /// 
587
+        /// </summary>
588
+        /// <param name="key"></param>
589
+        /// <param name="value"></param>
590
+        /// <returns></returns>
591
+        public static bool SetContains(string key, string value)
592
+        {
593
+            return redis.GetDatabase().SetContains(key, value);
594
+        }
595
+
596
+        /// <summary>
597
+        /// 返回对应键值集合的长度
598
+        /// </summary>
599
+        /// <param name="key"></param>
600
+        /// <returns></returns>
601
+        public static long SetLength(string key)
602
+        {
603
+            return redis.GetDatabase().SetLength(key);
604
+        }
605
+
606
+        /// <summary>
607
+        /// 根据键值返回集合中所有的value
608
+        /// </summary>
609
+        /// <param name="key"></param>
610
+        /// <returns></returns>
611
+        public static string[] SetMembers(string key)
612
+        {
613
+            return redis.GetDatabase().SetMembers(key).ToStringArray();
614
+        }
615
+
616
+        /// <summary>
617
+        /// 将成员从源集移动到目标集
618
+        /// </summary>
619
+        /// <param name="sourceKey">源集key</param>
620
+        /// <param name="destinationKey">目标集key</param>
621
+        /// <param name="value"></param>
622
+        public static bool SetMove(string sourceKey, string destinationKey, string value)
623
+        {
624
+            return redis.GetDatabase().SetMove(sourceKey, destinationKey, value);
625
+        }
626
+
627
+        /// <summary>
628
+        /// 移除集合中指定键值随机元素
629
+        /// </summary>
630
+        /// <param name="key"></param>
631
+        public static string SetPop(string key)
632
+        {
633
+            return redis.GetDatabase().SetPop(key);
634
+        }
635
+
636
+        /// <summary>
637
+        /// 返回集合中指定键值随机元素
638
+        /// </summary>
639
+        /// <param name="key"></param>
640
+        /// <returns></returns>
641
+        public static string SetRandomMember(string key)
642
+        {
643
+            return redis.GetDatabase().SetRandomMember(key);
644
+        }
645
+
646
+        /// <summary>
647
+        /// 
648
+        /// </summary>
649
+        /// <param name="key"></param>
650
+        /// <param name="count"></param>
651
+        public static string[] SetRandomMembers(string key, long count)
652
+        {
653
+            return redis.GetDatabase().SetRandomMembers(key, count).ToStringArray();
654
+        }
655
+
656
+        /// <summary>
657
+        /// 移除集合中指定key值和value
658
+        /// </summary>
659
+        /// <param name="key"></param>
660
+        /// <param name="value"></param>
661
+        public static void SetRemove(string key, string value)
662
+        {
663
+            redis.GetDatabase().SetRemove(key, value);
664
+        }
665
+
666
+        /// <summary>
667
+        /// 
668
+        /// </summary>
669
+        /// <param name="key"></param>
670
+        public static void SetScan(string key)
671
+        {
672
+            redis.GetDatabase().SetScan(key);
673
+        }
674
+
675
+        #endregion
676
+
677
+        #region redis 有序集合(sorted set)操作
678
+
679
+        public static void Method(string key, string value, double score)
680
+        {
681
+            redis.GetDatabase().SortedSetAdd(key, new SortedSetEntry[] { new SortedSetEntry(value, score) });
682
+        }
683
+
684
+        #endregion
685
+
686
+        #region redis 键(Key)操作
687
+
688
+        /// <summary>
689
+        /// 获取 Key
690
+        /// </summary>
691
+        /// <param name="redisKey"></param>
692
+        /// <returns></returns>
693
+        //public static IEnumerable<RedisKey> GetKeyList(string redisKey)
694
+        //{
695
+        //    var server = redis.GetServer(Configs.GetValue("Redis_Server"), Configs.GetValue("Redis_Port"));
696
+        //    return server.Keys(pattern: "*"+ redisKey + "*");
697
+        //}
698
+        public static List<string> GetKeyList(string redisKey)
699
+        {
700
+            var server = redis.GetServer(Configs.GetValue("Redis_Server"), Int32.Parse( Configs.GetValue("Redis_Port")));
701
+            List<string> keylist = new List<string>();
702
+            var redisenum = server.Keys(pattern: "*" + redisKey + "*");
703
+            foreach (var r in redisenum.ToList())
704
+            {
705
+                keylist.Add(r.ToString());
706
+            }
707
+            return keylist;
708
+        }
709
+
710
+        /// <summary>
711
+        /// 移除指定 Key
712
+        /// </summary>
713
+        /// <param name="redisKey"></param>
714
+        /// <returns></returns>
715
+        public static bool KeyDelete(string redisKey)
716
+        {
717
+            return redis.GetDatabase().KeyDelete(redisKey);
718
+        }
719
+
720
+        /// <summary>
721
+        /// 移除指定 Key
722
+        /// </summary>
723
+        /// <param name="redisKey"></param>
724
+        /// <returns></returns>
725
+        //public static long KeysDelete(IEnumerable<RedisKey> redisKeys)
726
+        //{
727
+        //    return redis.GetDatabase().KeyDelete(redisKeys.ToArray());
728
+        //}
729
+        public static long KeysDelete(List<string> redisKeys)
730
+        {
731
+            int n = 0;
732
+            foreach (var r in redisKeys)
733
+            {
734
+                if (redis.GetDatabase().KeyDelete(r))
735
+                {
736
+                    n++;
737
+                }
738
+            }
739
+            return n;
740
+        }
741
+
742
+        /// <summary>
743
+        /// 校验 Key 是否存在
744
+        /// </summary>
745
+        /// <param name="redisKey"></param>
746
+        /// <returns></returns>
747
+        public static bool KeyExists(string redisKey)
748
+        {
749
+            return redis.GetDatabase().KeyExists(redisKey);
750
+        }
751
+
752
+        /// <summary>
753
+        /// 重命名 Key
754
+        /// </summary>
755
+        /// <param name="redisKey"></param>
756
+        /// <param name="redisNewKey"></param>
757
+        /// <returns></returns>
758
+        public static bool KeyRename(string redisKey, string redisNewKey)
759
+        {
760
+            return redis.GetDatabase().KeyRename(redisKey, redisNewKey);
761
+        }
762
+
763
+        /// <summary>
764
+        /// 设置 Key 的时间
765
+        /// </summary>
766
+        /// <param name="redisKey"></param>
767
+        /// <param name="expiry"></param>
768
+        /// <returns></returns>
769
+        public static bool KeyExpire(string redisKey, TimeSpan? expiry)
770
+        {
771
+            return redis.GetDatabase().KeyExpire(redisKey, expiry);
772
+        }
773
+
774
+        #endregion
775
+
776
+        /// <summary>
777
+        /// 获取key过期时间
778
+        /// </summary>
779
+        /// <param name="redisKey"></param>
780
+        /// <returns></returns>
781
+        public static string GetKeyOutTime(string redisKey)
782
+        {
783
+            var server = redis.GetServer(Configs.GetValue("Redis_Server"), Int32.Parse(Configs.GetValue("Redis_Port")));
784
+            var timeNow = server.Time().ToUniversalTime();
785
+            var time = redis.GetDatabase().KeyTimeToLive(redisKey);
786
+            var expire = time == null ? (DateTime?)null : timeNow.Add(time.Value); //返回UTC时间。
787
+            return expire.Value.AddHours(8).ToString("yyyy-MM-dd HH:mm:ss");
788
+        }
789
+    }
790
+}

+ 1 - 0
CallCenterCommon/CallCenter.Utility/packages.config

@@ -4,4 +4,5 @@
4 4
   <package id="Newtonsoft.Json" version="10.0.2" targetFramework="net45" />
5 5
   <package id="NPOI" version="2.3.0" targetFramework="net45" />
6 6
   <package id="SharpZipLib" version="0.86.0" targetFramework="net45" />
7
+  <package id="StackExchange.Redis" version="1.2.6" targetFramework="net45" />
7 8
 </packages>