public T Get(string key) { key = AddSysCustomKey(key); var redisConfig = ReadRedisConfig.GetRedisConfig(DB_Name); var db = redisConfig.GetDatabase(); return(ConvertObj <T>(db.StringGet(key))); }
public void Insert <T>(string key, T t, TimeSpan?span = default(TimeSpan?)) { key = AddSysCustomKey(key); string json = ConvertJson(t); var redisConfig = ReadRedisConfig.GetRedisConfig(DB_Name); var db = redisConfig.GetDatabase(); db.StringSet(key, json, span); }
/// <summary> /// 出队 /// </summary> /// <returns></returns> public T Pop() { var keyInfo = AddSysCustomKey(MessageQueueType); var redisConfig = ReadRedisConfig.GetRedisConfig(DB_Name); var lockdb = redisConfig.GetDatabase(-1); var db = redisConfig.GetDatabase(); if (IsTran) { var token = Environment.MachineName; if (lockdb.LockTake(keyInfo, token, TimeSpan.FromSeconds(20))) { try { var json = db.ListLeftPop(keyInfo); if (json == default(RedisValue)) { return(default(T)); } return(ConvertObj <T>(json)); } finally { lockdb.LockRelease(keyInfo, token); } } return(default(T)); } else { var json = db.ListLeftPop(keyInfo); if (json == default(RedisValue)) { return(default(T)); } return(ConvertObj <T>(json)); } }