コード例 #1
0
 private bool ReConnectRedis()
 {
     if (RedisHost.ReConnectRedis())
     {
         //_redisServer = RedisHost.GetRedisServer();
         return(true);
     }
     else
     {
         return(false);
     }
 }
コード例 #2
0
        public List <T> GetList(string tableName, int dbIndex)
        {
            List <T> datas = new List <T>();

            try
            {
                if (!IsConnected && !ReConnectRedis())
                {
                    return(new List <T>());
                }


                //System.Console.WriteLine("{0} Start At {1}", tableName, DateTime.Now.ToString("mm:ss fff"));
                var keys = RedisHost.GetRedisServer().Keys(dbIndex, tableName + "*");

                foreach (var key in keys)
                {
                    string str = GetDatabase(dbIndex).StringGet(key);
                    try
                    {
                        if (string.IsNullOrEmpty(str))
                        {
                            Logger.LogError(string.Format("_redisDb.StringGet({0}) 返回值为空!", key));
                        }
                        else
                        {
                            datas.Add(JsonConvert.DeserializeObject <T>(str));
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.LogError4Exception(ex, new string[] { "AppLogger", "RedisLogger" });
                        ReConnectRedis();
                    }
                }
                //System.Console.WriteLine("{0} End At {1}", keys.ToList().Count, DateTime.Now.ToString("mm:ss fff"));
            }
            catch (RedisConnectionException ex)
            {
                Logger.LogError4Exception(ex, new string[] { "AppLogger", "RedisLogger" });
                ReConnectRedis();
            }
            catch (Exception ex)
            {
                Logger.LogError4Exception(ex, new string[] { "AppLogger", "RedisLogger" });
                ReConnectRedis();
            }

            return(datas);
        }
コード例 #3
0
 private IDatabase GetDatabase(int dbIndex)
 {
     return(RedisHost.GetDataBase(dbIndex));
 }