7

我正在构建一个基于StackExchangeRedisCacheClient的项目,并且已经过时了:'StackExchangeRedisCacheClient' 已过时:'此接口将在下一个专业中删除。请改用 RedisCacheClient。

所以我试图从 StackExchangeRedisCacheClient 移动RedisCacheClient不幸 的是没有文档或一些有用的信息可以做到这一点。

如何创建缓存客户端?与RedisCacheClient?需要的参数是'RedisCacheClient(IRedisCacheConnectionPoolManagerISerializerRedisConfiguration)'

我查看了以下链接并尝试实现单个池但没有成功https://github.com/imperugo/StackExchange.Redis.Extensions/issues/176# 在提供连接字符串后无法创建缓存客户端。

StackExchangeRedisCacheClient:(工作正常)

  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;

    }
4

1 回答 1

1

根据https://github.com/imperugo/StackExchange.Redis.Extensions/issues/176如果您不关心有多个连接,您可以使用以下类:

internal class SinglePool : IRedisCacheConnectionPoolManager
    {
        private readonly IConnectionMultiplexer connection;

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

        public IConnectionMultiplexer GetConnection()
        {
            return connection;
        }
    }
于 2019-12-12T13:12:34.947 回答