Exemplo n.º 1
0
        public KeyConfig CopyOne(string state)
        {
            var one = new KeyConfig();

            one.DBName     = this.DBName;
            one.Key        = this.Key + state;
            one.ExpireTime = this.ExpireTime;
            return(one);
        }
Exemplo n.º 2
0
 public virtual void WriteHash(KeyConfig keyConfig, string hashKey, string value)
 {
     try
     {
         IDatabase db = _redisMultiplexer.GetDatabase(keyConfig.DBName);
         db.HashSet(keyConfig.Key, hashKey, value);
     }
     catch (Exception ex)
     {
         LogHelper.Error("WriteHash", ex, keyConfig);
     }
 }
Exemplo n.º 3
0
 public virtual Dictionary <RedisValue, RedisValue> ReadHash(KeyConfig keyConfig)
 {
     try
     {
         IDatabase db = _redisMultiplexer.GetDatabase(keyConfig.DBName);
         return(db.HashGetAll(keyConfig.Key).ToDictionary());
     }
     catch (Exception ex)
     {
         LogHelper.Error("ReadHash", ex, keyConfig);
         return(default(Dictionary <RedisValue, RedisValue>));
     }
 }
Exemplo n.º 4
0
 public void WriteObject(KeyConfig keyConfig, Object value)
 {
     try
     {
         IDatabase db = _redisMultiplexer.GetDatabase(keyConfig.DBName);
         db.StringSet(keyConfig.Key, Newtonsoft.Json.JsonConvert.SerializeObject(value), keyConfig.ExpireTime);
     }
     catch (Exception ex)
     {
         LogHelper.Error("WriteObject", ex, keyConfig);
         Console.WriteLine(ex.ToString());
     }
 }
Exemplo n.º 5
0
        public T ReadCache <T>(KeyConfig keyConfig)
        {
            try
            {
                IDatabase db   = _redisMultiplexer.GetDatabase(keyConfig.DBName);
                var       data = db.KeyExists(keyConfig.Key) == true?Newtonsoft.Json.JsonConvert.DeserializeObject <T>(db.StringGet(keyConfig.Key).ToString()) : default(T);

                return(data);
            }
            catch (Exception ex)
            {
                LogHelper.Error("ReadCache", ex, keyConfig);
                Console.WriteLine(ex.ToString());
                return(default(T));
            }
        }