Beispiel #1
0
        public override bool Equals(object obj)
        {
            RedisConnectionKey other = obj as RedisConnectionKey;

            if (obj == null)
            {
                return(false);
            }

            return(this.RedisDbIndex == other.RedisDbIndex &&
                   this.RedisInstanceIndex == other.RedisInstanceIndex);
        }
        /// <summary>
        /// Start a new redis client pool, which will create an instance of RedisClientPool
        /// and start a new daemon thread to send requests and collect results
        /// </summary>
        /// <param name="redisDbIndex"></param>
        private void StartNewRedisClientPool(RedisConnectionKey key)
        {
            RedisConnectionPool pool = new RedisConnectionPool(
                this.readWriteHosts[key.RedisInstanceIndex], key.RedisDbIndex, this.redisLuaScriptManager);

            this.clientPools.Add(key, pool);

            // If the redis version db in pipeline mode, start a daemon thread
            // if (key.RedisDbIndex != 0)
            // {
            //     Thread t = new Thread(new ThreadStart(pool.Monitor));
            //     t.Start();
            // }
        }
        internal RedisClient GetClient(long redisDbIndex, int partition)
        {
            RedisConnectionKey key = new RedisConnectionKey(partition, redisDbIndex);

            if (!this.clientPools.ContainsKey(key))
            {
                lock (this.dictLock)
                {
                    if (!this.clientPools.ContainsKey(key))
                    {
                        this.StartNewRedisClientPool(key);
                    }
                }
            }
            return(this.clientPools[key].GetRedisClient());
        }