Пример #1
0
        public RedisConnectionPool(string redisConnectionString, long database, RedisLuaScriptManager luaScriptManager)
        {
            // Init the pooledRedisClient Manager
            RedisClientManagerConfig config = new RedisClientManagerConfig();

            config.DefaultDb        = database;
            config.MaxReadPoolSize  = RedisConnectionPool.DEFAULT_MAX_READ_POOL_SIZE;
            config.MaxWritePoolSize = RedisConnectionPool.DEFAULT_MAX_WRITE_POOL_SIZE;

            this.redisManagerPool =
                new PooledRedisClientManager(
                    new string[] { redisConnectionString },
                    new string[] { redisConnectionString },
                    config);

            this.RequestBatchSize = RedisConnectionPool.DEFAULT_BATCH_SIZE;
            this.WindowMicroSec   = RedisConnectionPool.DEFAULT_WINDOW_MICRO_SEC;
            this.Active           = true;

            this.redisRequestQueue = new Queue <RedisRequest>(this.RequestBatchSize);

            this.redisResponseVisitor = new RedisResponseVisitor();
            this.txEntryVisitor       = new RedisTxEntryRequestVisitor(luaScriptManager);
            this.versionEntryVisitor  = new RedisVersionEntryRequestVisitor(luaScriptManager);

            this.spinLock = new SpinLock();

            lastFlushTime = DateTime.Now.Ticks / 10;
        }
Пример #2
0
        public RedisVersionDbVisitor(
            RedisConnectionPool clientPool,
            RedisLuaScriptManager redisLuaScriptManager,
            RedisResponseVisitor redisResponseVisitor,
            RedisVersionDbMode mode)
        {
            this.clientPool            = clientPool;
            this.redisClient           = clientPool.GetRedisClient();
            this.redisLuaScriptManager = redisLuaScriptManager;
            this.RedisResponseVisitor  = redisResponseVisitor;
            this.redisVersionDbMode    = mode;

            this.redisRequests = new List <RedisRequest>();
            this.reqIndex      = 0;
        }
Пример #3
0
        private RedisVersionDb(int partitionCount, string[] readWriteHosts, RedisVersionDbMode mode = RedisVersionDbMode.Cluster)
            : base(partitionCount)
        {
            this.PartitionCount = partitionCount;

            if (readWriteHosts == null)
            {
                throw new ArgumentException("readWriteHosts must be a null array");
            }
            this.readWriteHosts = readWriteHosts;
            this.Mode           = mode;

            this.tableLock       = new object();
            this.responseVisitor = new RedisResponseVisitor();

            this.Setup();

            this.txEntryRequestQueues = new Queue <TxEntryRequest> [partitionCount];
            this.flushQueues          = new Queue <TxEntryRequest> [partitionCount];
            this.queueLatches         = new int[partitionCount];

            for (int pid = 0; pid < this.PartitionCount; pid++)
            {
                RedisConnectionPool clientPool = null;
                if (this.Mode == RedisVersionDbMode.Cluster)
                {
                    clientPool = SingletonConnPool;
                }
                else
                {
                    clientPool = this.RedisManager.GetClientPool(
                        RedisVersionDb.TX_DB_INDEX, RedisVersionDb.GetRedisInstanceIndex(pid));
                }
                this.dbVisitors[pid] = new RedisVersionDbVisitor(
                    clientPool, this.RedisLuaManager, this.responseVisitor, this.Mode);

                this.txEntryRequestQueues[pid] = new Queue <TxEntryRequest>(VersionDb.REQUEST_QUEUE_CAPACITY);
                this.flushQueues[pid]          = new Queue <TxEntryRequest>(VersionDb.REQUEST_QUEUE_CAPACITY);
                this.queueLatches[pid]         = 0;
            }
        }
Пример #4
0
        public RedisVersionTable(VersionDb versionDb, string tableId, long redisDbIndex)
            : base(versionDb, tableId, versionDb.PartitionCount)
        {
            this.redisDbIndex       = redisDbIndex;
            this.responseVisitor    = new RedisResponseVisitor();
            this.redisVersionDb     = ((RedisVersionDb)this.VersionDb);
            this.RedisManager       = redisVersionDb.RedisManager;
            this.LuaManager         = redisVersionDb.RedisLuaManager;
            this.singletonConnPool  = redisVersionDb.SingletonConnPool;
            this.redisVersionDbMode = redisVersionDb.Mode;

            this.requestQueues = new Queue <VersionEntryRequest> [this.PartitionCount];
            this.flushQueues   = new Queue <VersionEntryRequest> [this.PartitionCount];
            this.queueLatches  = new int[this.PartitionCount];

            RedisConnectionPool clientPool = null;

            for (int pid = 0; pid < this.PartitionCount; pid++)
            {
                if (this.redisVersionDbMode == RedisVersionDbMode.Cluster)
                {
                    clientPool = this.singletonConnPool;
                }
                else
                {
                    clientPool = this.RedisManager.GetClientPool(
                        this.redisDbIndex, RedisVersionDb.GetRedisInstanceIndex(pid));
                }
                this.tableVisitors[pid] = new RedisVersionTableVisitor(
                    clientPool, this.LuaManager, this.responseVisitor, this.redisVersionDbMode);

                this.requestQueues[pid] = new Queue <VersionEntryRequest>(VersionDb.REQUEST_QUEUE_CAPACITY);
                this.flushQueues[pid]   = new Queue <VersionEntryRequest>(VersionDb.REQUEST_QUEUE_CAPACITY);
                this.queueLatches[pid]  = 0;
            }
        }
Пример #5
0
 public RedisRequest(RedisResponseVisitor redisResponseVisitor)
 {
     this.ResponseVisitor = redisResponseVisitor;
 }