修改缓存

usertest
jianghaiqing 4 months ago
parent ad51e6bdfc
commit 9f115f2bda

@ -16,6 +16,7 @@ public static class RedisModuleInstall
{
if (services == null) throw new ArgumentNullException(nameof(services));
services.AddScoped<IRedisService, RedisService>();
//services.AddScoped<IRedisService, RedisService>();
services.AddSingleton<IRedisService, RedisService>();
}
}

@ -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<T>(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<T>(data);
}
catch (Exception ex)
@ -187,7 +187,7 @@ namespace DS.Module.RedisModule
{
try
{
var dataList = csRedis.Keys(key + "*");
var dataList = RedisHelper.Keys(key + "*");
List<T> list = new List<T>();
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 });
}
/// <summary>
/// 释放Redis链接

Loading…
Cancel
Save