diff --git a/ds-wms-service/DS.Module.RedisModule/RedisModuleInstall.cs b/ds-wms-service/DS.Module.RedisModule/RedisModuleInstall.cs index b5dca069..8a823a7d 100644 --- a/ds-wms-service/DS.Module.RedisModule/RedisModuleInstall.cs +++ b/ds-wms-service/DS.Module.RedisModule/RedisModuleInstall.cs @@ -16,6 +16,7 @@ public static class RedisModuleInstall { if (services == null) throw new ArgumentNullException(nameof(services)); - services.AddScoped(); + //services.AddScoped(); + services.AddSingleton(); } } \ No newline at end of file diff --git a/ds-wms-service/DS.Module.RedisModule/RedisService.cs b/ds-wms-service/DS.Module.RedisModule/RedisService.cs index 300eb15c..11168df4 100644 --- a/ds-wms-service/DS.Module.RedisModule/RedisService.cs +++ b/ds-wms-service/DS.Module.RedisModule/RedisService.cs @@ -34,7 +34,7 @@ namespace DS.Module.RedisModule { try { - csRedis.Set(key, value); + RedisHelper.Set(key, value); return true; } catch (Exception ex) @@ -55,7 +55,7 @@ namespace DS.Module.RedisModule { try { - csRedis.Set(key, value, outSecond); + RedisHelper.Set(key, value, outSecond); return true; } catch (Exception ex) @@ -75,13 +75,13 @@ namespace DS.Module.RedisModule { try { - if (csRedis.Exists(key)) + if (RedisHelper.Exists(key)) { - long time = csRedis.Ttl(key); - csRedis.Set(key, value, Convert.ToInt32(time)); + long time = RedisHelper.Ttl(key); + RedisHelper.Set(key, value, Convert.ToInt32(time)); } else - csRedis.Set(key, value); + RedisHelper.Set(key, value); return true; } @@ -101,7 +101,7 @@ namespace DS.Module.RedisModule { try { - return csRedis.Exists(key); + return RedisHelper.Exists(key); } catch (Exception ex) { @@ -120,10 +120,10 @@ namespace DS.Module.RedisModule { try { - if (csRedis.Exists(key)) + if (RedisHelper.Exists(key)) { - long time = csRedis.Ttl(key); - csRedis.Set(key, value, Convert.ToInt32(time)); + long time = RedisHelper.Ttl(key); + RedisHelper.Set(key, value, Convert.ToInt32(time)); return true; } return false; @@ -140,7 +140,7 @@ namespace DS.Module.RedisModule { try { - return csRedis.Get(key); + return RedisHelper.Get(key); } catch (Exception ex) { @@ -159,7 +159,7 @@ namespace DS.Module.RedisModule { try { - var data = csRedis.Get(key); + var data = RedisHelper.Get(key); return JsonConvert.DeserializeObject(data); } catch (Exception ex) @@ -173,7 +173,7 @@ namespace DS.Module.RedisModule { try { - var data = csRedis.Get(key); + var data = RedisHelper.Get(key); return JsonConvert.DeserializeObject(data); } catch (Exception ex) @@ -187,7 +187,7 @@ namespace DS.Module.RedisModule { try { - var dataList = csRedis.Keys(key + "*"); + var dataList = RedisHelper.Keys(key + "*"); List list = new List(); foreach (string item in dataList) { @@ -210,7 +210,7 @@ namespace DS.Module.RedisModule { try { - csRedis.Del(key); + RedisHelper.Del(key); } catch (Exception ex) { @@ -222,7 +222,7 @@ namespace DS.Module.RedisModule { try { - var dataList = csRedis.Keys(key + "*"); + var dataList = RedisHelper.Keys(key + "*"); foreach (string item in dataList) { @@ -239,12 +239,12 @@ namespace DS.Module.RedisModule private bool AcquireLock(string lockKey, string lockValue, int lockTimeoutSeconds) { // 尝试获取锁 - bool lockAcquired = csRedis.SetNx(lockKey, lockValue); + bool lockAcquired = RedisHelper.SetNx(lockKey, lockValue); // 如果成功获取锁,设置锁的超时时间 if (lockAcquired) { - csRedis.Expire(lockKey, lockTimeoutSeconds); + RedisHelper.Expire(lockKey, lockTimeoutSeconds); } return lockAcquired; @@ -261,7 +261,7 @@ namespace DS.Module.RedisModule return 0 end"; - csRedis.Eval(luaScript, lockKey, new[] { lockValue }); + RedisHelper.Eval(luaScript, lockKey, new[] { lockValue }); } /// /// 释放Redis链接