public static string[] GetValue(string table, string[] fields) { SessionFactory.Verify(); var parms = fields.Select(o => (RedisValue)o).ToArray(); return(_redisDb.HashGet(table, parms).Select(o => o.ToString()).ToArray()); }
public static long Decrement(string counterName, string field, long value = 1) { SessionFactory.Verify(); long count = _redisDb.HashDecrement(counterName, field, value); return(count); }
public static string Pop(string queueName) { SessionFactory.Verify(); var value = _redisDb.ListLeftPop(queueName); return(value); }
/// <summary> /// 向队列中添加数据 /// </summary> /// <param name="value"></param> public static void Push(string queueName, string value) { SessionFactory.Verify(); if (!string.IsNullOrWhiteSpace(value)) { _redisDb.ListRightPush(queueName, value); } }
/// <summary> /// 初始化计数器(如果已存在,不修改原来计数器的任何状态,包括过期时间) /// </summary> /// <param name="table"></param> /// <param name="expiry"></param> public static void Init(string counterName, TimeSpan?expiry) { SessionFactory.Verify(); if (!_redisDb.KeyExists(counterName)) { if (expiry.HasValue) { string timeout = expiry.Value.ToString(); _redisDb.StringSet(string.Join("_", counterName, "timeout"), timeout, expiry); } } }
public static bool SetValue(string table, string field, string value) { SessionFactory.Verify(); var result = _redisDb.HashSet(table, field, value); string timeoutKey = string.Join("_", table, "timeout"); if (_redisDb.KeyExists(timeoutKey)) { SetExpiry(table, TimeSpan.Parse(_redisDb.StringGet(timeoutKey))); _redisDb.KeyDelete(timeoutKey); } return(result); }
public static long Increment(string counterName, string field, long value = 1) { SessionFactory.Verify(); long count = _redisDb.HashIncrement(counterName, field, value); string timeoutKey = string.Join("_", counterName, "timeout"); if (_redisDb.KeyExists(timeoutKey)) { SetExpiry(counterName, TimeSpan.Parse(_redisDb.StringGet(timeoutKey))); _redisDb.KeyDelete(timeoutKey); } return(count); }
public static void SetValue(string table, Dictionary <string, string> hashEntry) { SessionFactory.Verify(); var entries = hashEntry.Select(o => new HashEntry(o.Key, o.Value)).ToArray(); _redisDb.HashSet(table, entries); string timeoutKey = string.Join("_", table, "timeout"); if (_redisDb.KeyExists(timeoutKey)) { SetExpiry(table, TimeSpan.Parse(_redisDb.StringGet(timeoutKey))); _redisDb.KeyDelete(timeoutKey); } }
public static bool Delete(string counterName, string field) { SessionFactory.Verify(); return(_redisDb.HashDelete(counterName, field)); }
public static long Get(string counterName, string field) { SessionFactory.Verify(); return((long)_redisDb.HashGet(counterName, field)); }
public static void SetExpiry(string counterName, TimeSpan expiry) { SessionFactory.Verify(); _redisDb.KeyExpire(counterName, expiry); }
public static string GetValue(string table, string field) { SessionFactory.Verify(); return(_redisDb.HashGet(table, field)); }
public static void SetExpiry(string table, TimeSpan expiry) { SessionFactory.Verify(); _redisDb.KeyExpire(table, expiry); }