Daniel Mirzakandov
Daniel Mirzakandov

Reputation: 81

Migrating from StackExchangeRedisCacheClient to RedisCacheClient

I am building a project based on StackExchangeRedisCacheClient and obsolete has popped out: 'StackExchangeRedisCacheClient' is obsolete: 'This interface will be removed with the next major. Please use RedisCacheClient instead.'

so i'm trying to move from StackExchangeRedisCacheClient to RedisCacheClient unfortunately there is no documentation or some helpful info for doing that.

how do i create a cache client? with RedisCacheClient ? the require args are 'RedisCacheClient(IRedisCacheConnectionPoolManager, ISerializer, RedisConfiguration)'

i have looked at the following link and tried to implement a Single pool with no success https://github.com/imperugo/StackExchange.Redis.Extensions/issues/176# couldn't create a cacheClient after providing the connection string.

StackExchangeRedisCacheClient:(works fine)

  public CacheManager()
    {
        string connectionString = "localhost:300....."
        var serializer = new NewtonsoftSerializer();
        cacheClient = new StackExchangeRedisCacheClient(serializer, connectionString);
        clientName = cacheClient.Database.Multiplexer.ClientName;

    }

RedisCacheClient:

  public CacheManager()
    {
        string connectionString = "localhost:300....."
        var serializer = new NewtonsoftSerializer();
        cacheClient = new RedisCacheClient( *** ??? *** );
        clientName = cacheClient.Database.Multiplexer.ClientName;

    }

Upvotes: 8

Views: 4901

Answers (1)

meh-uk
meh-uk

Reputation: 2151

As per https://github.com/imperugo/StackExchange.Redis.Extensions/issues/176 if you don't care about having multiple connections you can use the following class:

internal class SinglePool : IRedisCacheConnectionPoolManager
    {
        private readonly IConnectionMultiplexer connection;

        public SinglePool(string connectionString)
        {
            this.connection = ConnectionMultiplexer.Connect(connectionString);
        }

        public IConnectionMultiplexer GetConnection()
        {
            return connection;
        }
    }

Upvotes: 1

Related Questions