예제 #1
0
 public static RedisVersionDb Instance(
     int partitionCount      = 1,
     string[] readWriteHosts = null,
     RedisVersionDbMode mode = RedisVersionDbMode.Cluster)
 {
     if (RedisVersionDb.instance == null)
     {
         lock (RedisVersionDb.initLock)
         {
             if (RedisVersionDb.instance == null)
             {
                 if (readWriteHosts == null || readWriteHosts.Length == 0)
                 {
                     RedisVersionDb.instance = new RedisVersionDb(
                         1, new string[] { RedisVersionDb.DEFAULT_REDIS_HOST });
                 }
                 else
                 {
                     RedisVersionDb.instance = new RedisVersionDb(partitionCount, readWriteHosts, mode);
                 }
             }
         }
     }
     return(RedisVersionDb.instance);
 }
예제 #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;
            }
        }