|
@@ -16,7 +16,7 @@ namespace MySystem
|
|
|
#region 设置单个字段
|
|
|
public bool Set(string key, object value)
|
|
|
{
|
|
|
- return RedisHelper.Set(key, value);
|
|
|
+ return csredis.Set(key, value);
|
|
|
// return false;
|
|
|
}
|
|
|
#endregion
|
|
@@ -24,7 +24,7 @@ namespace MySystem
|
|
|
#region 整数累加
|
|
|
public long AddInt(string key, long value = 1)
|
|
|
{
|
|
|
- return RedisHelper.IncrBy(key, value);
|
|
|
+ return csredis.IncrBy(key, value);
|
|
|
// return 0;
|
|
|
}
|
|
|
#endregion
|
|
@@ -32,7 +32,7 @@ namespace MySystem
|
|
|
#region 数字累加
|
|
|
public decimal AddNumber(string key, decimal value = 1)
|
|
|
{
|
|
|
- return RedisHelper.IncrByFloat(key, value);
|
|
|
+ return csredis.IncrByFloat(key, value);
|
|
|
// return 0;
|
|
|
}
|
|
|
#endregion
|
|
@@ -40,14 +40,14 @@ namespace MySystem
|
|
|
#region 获取单个字段
|
|
|
public T Get<T>(string key)
|
|
|
{
|
|
|
- return RedisHelper.Get<T>(key);
|
|
|
+ return csredis.Get<T>(key);
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 设置散列字段
|
|
|
public bool HSet(string key, string field, object value)
|
|
|
{
|
|
|
- return RedisHelper.HSet(key, field, value);
|
|
|
+ return csredis.HSet(key, field, value);
|
|
|
// return false;
|
|
|
}
|
|
|
#endregion
|
|
@@ -55,7 +55,7 @@ namespace MySystem
|
|
|
#region 散列整数累加
|
|
|
public long HAddInt(string key, string field, long value = 1)
|
|
|
{
|
|
|
- return RedisHelper.HIncrBy(key, field, value);
|
|
|
+ return csredis.HIncrBy(key, field, value);
|
|
|
// return 0;
|
|
|
}
|
|
|
#endregion
|
|
@@ -63,7 +63,7 @@ namespace MySystem
|
|
|
#region 散列数字累加
|
|
|
public decimal HAddNumber(string key, string field, decimal value = 1)
|
|
|
{
|
|
|
- return RedisHelper.HIncrByFloat(key, field, value);
|
|
|
+ return csredis.HIncrByFloat(key, field, value);
|
|
|
// return 0;
|
|
|
}
|
|
|
#endregion
|
|
@@ -71,43 +71,43 @@ namespace MySystem
|
|
|
#region 获取散列元素
|
|
|
public T HGet<T>(string key, string field)
|
|
|
{
|
|
|
- return RedisHelper.HGet<T>(key, field);
|
|
|
+ return csredis.HGet<T>(key, field);
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 获取散列所有元素
|
|
|
public Dictionary<string, T> HGetAll<T>(string key)
|
|
|
{
|
|
|
- return RedisHelper.HGetAll<T>(key);
|
|
|
+ return csredis.HGetAll<T>(key);
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 添加列表对象
|
|
|
public long AddList(string key, object value)
|
|
|
{
|
|
|
- return RedisHelper.LPush(key, value);
|
|
|
+ return csredis.LPush(key, value);
|
|
|
// return 0;
|
|
|
}
|
|
|
public long AddList(string key, object[] value)
|
|
|
{
|
|
|
- return RedisHelper.LPush(key, value);
|
|
|
+ return csredis.LPush(key, value);
|
|
|
// return 0;
|
|
|
}
|
|
|
public T RPop<T>(string key)
|
|
|
{
|
|
|
- return RedisHelper.RPop<T>(key);
|
|
|
+ return csredis.RPop<T>(key);
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 添加集合对象
|
|
|
public long SAdd(string key, object value)
|
|
|
{
|
|
|
- return RedisHelper.SAdd(key, value);
|
|
|
+ return csredis.SAdd(key, value);
|
|
|
// return 0;
|
|
|
}
|
|
|
public long SAdd(string key, object[] value)
|
|
|
{
|
|
|
- return RedisHelper.SAdd(key, value);
|
|
|
+ return csredis.SAdd(key, value);
|
|
|
// return 0;
|
|
|
}
|
|
|
#endregion
|
|
@@ -115,15 +115,15 @@ namespace MySystem
|
|
|
#region 获取集合对象
|
|
|
public T[] SGetList<T>(string key)
|
|
|
{
|
|
|
- return RedisHelper.SMembers<T>(key);
|
|
|
+ return csredis.SMembers<T>(key);
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 修改列表对象
|
|
|
public bool SetList(string key, int index, object value)
|
|
|
{
|
|
|
- long itemindex = RedisHelper.LLen(key) - index - 1;
|
|
|
- return RedisHelper.LSet(key, itemindex, value);
|
|
|
+ long itemindex = csredis.LLen(key) - index - 1;
|
|
|
+ return csredis.LSet(key, itemindex, value);
|
|
|
// return false;
|
|
|
}
|
|
|
#endregion
|
|
@@ -133,7 +133,7 @@ namespace MySystem
|
|
|
{
|
|
|
int start = (pageNum - 1) * pageSize;
|
|
|
int end = start + pageSize - 1;
|
|
|
- string[] list = RedisHelper.LRange(key, start, end);
|
|
|
+ string[] list = csredis.LRange(key, start, end);
|
|
|
List<T> lists = new List<T>();
|
|
|
foreach (string record in list)
|
|
|
{
|
|
@@ -146,14 +146,14 @@ namespace MySystem
|
|
|
#region 移除列表
|
|
|
public long RemoveFromList(string key, object value, int count = 1)
|
|
|
{
|
|
|
- return RedisHelper.LRem(key, count, value);
|
|
|
+ return csredis.LRem(key, count, value);
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 添加排序列表对象
|
|
|
public long AddSort(string key, object value, decimal score)
|
|
|
{
|
|
|
- return RedisHelper.ZAdd(key, (score, value));
|
|
|
+ return csredis.ZAdd(key, (score, value));
|
|
|
// return 0;
|
|
|
}
|
|
|
#endregion
|
|
@@ -163,7 +163,7 @@ namespace MySystem
|
|
|
{
|
|
|
int start = (pageNum - 1) * pageSize;
|
|
|
int end = start + pageSize;
|
|
|
- string[] list = RedisHelper.ZRangeByScore(key, start, end);
|
|
|
+ string[] list = csredis.ZRangeByScore(key, start, end);
|
|
|
List<T> lists = new List<T>();
|
|
|
foreach (string record in list)
|
|
|
{
|
|
@@ -175,7 +175,7 @@ namespace MySystem
|
|
|
{
|
|
|
int start = (pageNum - 1) * pageSize;
|
|
|
int end = start + pageSize;
|
|
|
- string[] list = RedisHelper.ZRevRangeByScore(key, start, end);
|
|
|
+ string[] list = csredis.ZRevRangeByScore(key, start, end);
|
|
|
List<T> lists = new List<T>();
|
|
|
foreach (string record in list)
|
|
|
{
|
|
@@ -187,7 +187,7 @@ namespace MySystem
|
|
|
|
|
|
public bool Remove(string key, long start, long end)
|
|
|
{
|
|
|
- return RedisHelper.LTrim(key, start, end);
|
|
|
+ return csredis.LTrim(key, start, end);
|
|
|
}
|
|
|
|
|
|
public bool RemoveTop(string key, long count)
|
|
@@ -197,34 +197,34 @@ namespace MySystem
|
|
|
|
|
|
public long Count(string key)
|
|
|
{
|
|
|
- return RedisHelper.LLen(key);
|
|
|
+ return csredis.LLen(key);
|
|
|
}
|
|
|
|
|
|
public void Clear(string pattern)
|
|
|
{
|
|
|
- string[] keys = RedisHelper.Keys(pattern);
|
|
|
- RedisHelper.Del(keys);
|
|
|
+ string[] keys = csredis.Keys(pattern);
|
|
|
+ csredis.Del(keys);
|
|
|
}
|
|
|
|
|
|
public string[] GetKeys(string pattern)
|
|
|
{
|
|
|
- string[] keys = RedisHelper.Keys(pattern);
|
|
|
+ string[] keys = csredis.Keys(pattern);
|
|
|
return keys;
|
|
|
}
|
|
|
|
|
|
public void SetExpire(string key, int expire)
|
|
|
{
|
|
|
- RedisHelper.Expire(key, expire); //秒为单位
|
|
|
+ csredis.Expire(key, expire); //秒为单位
|
|
|
}
|
|
|
|
|
|
public bool Exists(string key)
|
|
|
{
|
|
|
- return RedisHelper.Exists(key);
|
|
|
+ return csredis.Exists(key);
|
|
|
}
|
|
|
|
|
|
public long AddRightList(string key, object value)
|
|
|
{
|
|
|
- return RedisHelper.RPush(key, value);
|
|
|
+ return csredis.RPush(key, value);
|
|
|
// return 0;
|
|
|
}
|
|
|
/// <summary>
|
|
@@ -253,7 +253,7 @@ namespace MySystem
|
|
|
// while (true)
|
|
|
// {
|
|
|
// //设置key Redis2.6.12以上版本,可以用set获取锁。set可以实现setnx和expire,这个是原子操作
|
|
|
- // if (RedisHelper.Set(lockKey, requestId, lockTime, RedisHelper.RedisExistence.Nx))
|
|
|
+ // if (csredis.Set(lockKey, requestId, lockTime, csredis.RedisExistence.Nx))
|
|
|
// {
|
|
|
// //设置成功后开启子线程为key续命
|
|
|
// CreateThredXm();
|
|
@@ -279,12 +279,12 @@ namespace MySystem
|
|
|
return;
|
|
|
}
|
|
|
//查询key还有多少秒释放
|
|
|
- var Seconds = RedisHelper.PTtl(lockKey) / 1000;
|
|
|
+ var Seconds = csredis.PTtl(lockKey) / 1000;
|
|
|
//key还剩1/3秒时重设过期时间
|
|
|
if (Seconds < (lockTime / 3))
|
|
|
{
|
|
|
//小于5秒则自动 重设过期时间
|
|
|
- RedisHelper.Expire(lockKey, lockTime);
|
|
|
+ csredis.Expire(lockKey, lockTime);
|
|
|
}
|
|
|
}
|
|
|
}, tokenSource.Token);
|
|
@@ -300,7 +300,7 @@ namespace MySystem
|
|
|
// string script = "if redis.call('get', KEYS[1]) == ARGV[1] then " +
|
|
|
// "return redis.call('del', KEYS[1]) " +
|
|
|
// "else return 0 end";
|
|
|
- // RedisHelper.Eval(script, lockKey, requestId);
|
|
|
+ // csredis.Eval(script, lockKey, requestId);
|
|
|
// //取消续命线程
|
|
|
// tokenSource.Cancel();
|
|
|
}
|