public void TryGetConnection_ConnectionSharing()
 {
     Utility.SetConfigUtilityToDefault();
     RedisSharedConnection redisSharedConnection = new RedisSharedConnection(RedisSessionStateProvider.configuration,
         () => new FakeRedisClientConnection());
     IRedisClientConnection connection = redisSharedConnection.TryGetConnection();
     IRedisClientConnection connection2 = redisSharedConnection.TryGetConnection();
     Assert.Equal(connection, connection2);
 }
Example #2
0
        public void TryGetConnection_ConnectionSharing()
        {
            Utility.SetConfigUtilityToDefault();
            RedisSharedConnection redisSharedConnection = new RedisSharedConnection(RedisSessionStateProvider.configuration,
                                                                                    () => new FakeRedisClientConnection());
            IRedisClientConnection connection  = redisSharedConnection.TryGetConnection();
            IRedisClientConnection connection2 = redisSharedConnection.TryGetConnection();

            Assert.Equal(connection, connection2);
        }
 public void TryGetConnection_CreateNewConnection()
 {
     Utility.SetConfigUtilityToDefault();
     RedisSharedConnection redisSharedConnection = new RedisSharedConnection(RedisSessionStateProvider.configuration,
         () => new FakeRedisClientConnection());
     Assert.Null(redisSharedConnection.connection);
     IRedisClientConnection connection = redisSharedConnection.TryGetConnection();
     Assert.NotNull(connection);
     Assert.NotNull(redisSharedConnection.connection);
 }
Example #4
0
        public void TryGetConnection_CreateNewConnection()
        {
            Utility.SetConfigUtilityToDefault();
            RedisSharedConnection redisSharedConnection = new RedisSharedConnection(RedisSessionStateProvider.configuration,
                                                                                    () => new FakeRedisClientConnection());

            Assert.Null(redisSharedConnection.connection);
            IRedisClientConnection connection = redisSharedConnection.TryGetConnection();

            Assert.NotNull(connection);
            Assert.NotNull(redisSharedConnection.connection);
        }
        public RedisConnectionWrapper(ProviderConfiguration configuration, string id)
        {
            this.configuration = configuration;
            Keys = new KeyGenerator(id, configuration.ApplicationName);

            // Pool is created by server when it starts. don't want to lock everytime when check pool == null.
            // so that is why pool == null exists twice.
            if (sharedConnection == null)
            {
                lock (lockForSharedConnection)
                {
                    if (sharedConnection == null)
                    {
                        sharedConnection = new RedisSharedConnection(configuration, () => new StackExchangeClientConnection(configuration));
                        redisUtility     = new RedisUtility(configuration);
                    }
                }
            }
            redisConnection = sharedConnection.TryGetConnection();
        }