|
|
@ -34,7 +34,7 @@ namespace DS.Module.RedisModule
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
csRedis.Set(key, value);
|
|
|
|
RedisHelper.Set(key, value);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
catch (Exception ex)
|
|
|
@ -55,7 +55,7 @@ namespace DS.Module.RedisModule
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
csRedis.Set(key, value, outSecond);
|
|
|
|
RedisHelper.Set(key, value, outSecond);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
catch (Exception ex)
|
|
|
@ -75,13 +75,13 @@ namespace DS.Module.RedisModule
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (csRedis.Exists(key))
|
|
|
|
if (RedisHelper.Exists(key))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
long time = csRedis.Ttl(key);
|
|
|
|
long time = RedisHelper.Ttl(key);
|
|
|
|
csRedis.Set(key, value, Convert.ToInt32(time));
|
|
|
|
RedisHelper.Set(key, value, Convert.ToInt32(time));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
csRedis.Set(key, value);
|
|
|
|
RedisHelper.Set(key, value);
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -101,7 +101,7 @@ namespace DS.Module.RedisModule
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return csRedis.Exists(key);
|
|
|
|
return RedisHelper.Exists(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -120,10 +120,10 @@ namespace DS.Module.RedisModule
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (csRedis.Exists(key))
|
|
|
|
if (RedisHelper.Exists(key))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
long time = csRedis.Ttl(key);
|
|
|
|
long time = RedisHelper.Ttl(key);
|
|
|
|
csRedis.Set(key, value, Convert.ToInt32(time));
|
|
|
|
RedisHelper.Set(key, value, Convert.ToInt32(time));
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
@ -140,7 +140,7 @@ namespace DS.Module.RedisModule
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return csRedis.Get(key);
|
|
|
|
return RedisHelper.Get(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -159,7 +159,7 @@ namespace DS.Module.RedisModule
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var data = csRedis.Get(key);
|
|
|
|
var data = RedisHelper.Get(key);
|
|
|
|
return JsonConvert.DeserializeObject<T>(data);
|
|
|
|
return JsonConvert.DeserializeObject<T>(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
catch (Exception ex)
|
|
|
@ -173,7 +173,7 @@ namespace DS.Module.RedisModule
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var data = csRedis.Get(key);
|
|
|
|
var data = RedisHelper.Get(key);
|
|
|
|
return JsonConvert.DeserializeObject<T>(data);
|
|
|
|
return JsonConvert.DeserializeObject<T>(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
catch (Exception ex)
|
|
|
@ -187,7 +187,7 @@ namespace DS.Module.RedisModule
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var dataList = csRedis.Keys(key + "*");
|
|
|
|
var dataList = RedisHelper.Keys(key + "*");
|
|
|
|
List<T> list = new List<T>();
|
|
|
|
List<T> list = new List<T>();
|
|
|
|
foreach (string item in dataList)
|
|
|
|
foreach (string item in dataList)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -210,7 +210,7 @@ namespace DS.Module.RedisModule
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
csRedis.Del(key);
|
|
|
|
RedisHelper.Del(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -222,7 +222,7 @@ namespace DS.Module.RedisModule
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var dataList = csRedis.Keys(key + "*");
|
|
|
|
var dataList = RedisHelper.Keys(key + "*");
|
|
|
|
|
|
|
|
|
|
|
|
foreach (string item in dataList)
|
|
|
|
foreach (string item in dataList)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -239,12 +239,12 @@ namespace DS.Module.RedisModule
|
|
|
|
private bool AcquireLock(string lockKey, string lockValue, int lockTimeoutSeconds)
|
|
|
|
private bool AcquireLock(string lockKey, string lockValue, int lockTimeoutSeconds)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// 尝试获取锁
|
|
|
|
// 尝试获取锁
|
|
|
|
bool lockAcquired = csRedis.SetNx(lockKey, lockValue);
|
|
|
|
bool lockAcquired = RedisHelper.SetNx(lockKey, lockValue);
|
|
|
|
|
|
|
|
|
|
|
|
// 如果成功获取锁,设置锁的超时时间
|
|
|
|
// 如果成功获取锁,设置锁的超时时间
|
|
|
|
if (lockAcquired)
|
|
|
|
if (lockAcquired)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
csRedis.Expire(lockKey, lockTimeoutSeconds);
|
|
|
|
RedisHelper.Expire(lockKey, lockTimeoutSeconds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return lockAcquired;
|
|
|
|
return lockAcquired;
|
|
|
@ -261,7 +261,7 @@ namespace DS.Module.RedisModule
|
|
|
|
return 0
|
|
|
|
return 0
|
|
|
|
end";
|
|
|
|
end";
|
|
|
|
|
|
|
|
|
|
|
|
csRedis.Eval(luaScript, lockKey, new[] { lockValue });
|
|
|
|
RedisHelper.Eval(luaScript, lockKey, new[] { lockValue });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 释放Redis链接
|
|
|
|
/// 释放Redis链接
|
|
|
|