Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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;

    }
like image 769
Daniel Mirzakandov Avatar asked Sep 01 '19 15:09

Daniel Mirzakandov


1 Answers

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;
        }
    }
like image 141
meh-uk Avatar answered Nov 08 '22 03:11

meh-uk