stackexchange.redis.redisconnectionexception

whlutmcx  于 2021-06-09  发布在  Redis
关注(0)|答案(1)|浏览(622)

我尝试使用redis作为jwt黑名单的缓存,用jwt实现注销。我已经下载了redis在我的windows10机器上运行 "redis-server.exe" 上面写着:

[6112] 28 Nov 16:28:51.791 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 3.0.504 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 6112
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

[6112] 28 Nov 16:28:51.798 # Server started, Redis version 3.0.504
[6112] 28 Nov 16:28:51.799 * DB loaded from disk: 0.001 seconds
[6112] 28 Nov 16:28:51.800 * The server is now ready to accept connections on port 6379

     Redis 3.0.504 (00000000/0) 64 bit

        Running in standalone mode

     The server is now ready to accept connections on port 6379

这表明它工作正常。
我用的是.netcore 3.1 Microsoft.Extensions.Caching.Redis 已安装v2.2.0 nuget包。
在我的 startup.cs 我补充道

services.AddDistributedRedisCache(r =>
            {
                r.Configuration = Configuration["Redis:ConnectionString"];
            });

在我的心里 appsettings.json 我有

"Redis": {
    "ConnectionString": "localhsot"
  }

但在我发出的任何请求中,我都会得到以下例外:

StackExchange.Redis.RedisConnectionException: It was not possible to connect to the redis server(s); to create a disconnected multiplexer, disable AbortOnConnectFail. SocketFailure on PING
   at StackExchange.Redis.ConnectionMultiplexer.ConnectAsync(String configuration, TextWriter log) in c:\code\StackExchange.Redis\StackExchange.Redis\StackExchange\Redis\ConnectionMultiplexer.cs:line 801
   at Microsoft.Extensions.Caching.Redis.RedisCache.ConnectAsync(CancellationToken token)
   at Microsoft.Extensions.Caching.Redis.RedisCache.GetAndRefreshAsync(String key, Boolean getData, CancellationToken token)
   at Microsoft.Extensions.Caching.Redis.RedisCache.GetAsync(String key, CancellationToken token)
   at Microsoft.Extensions.Caching.Distributed.DistributedCacheExtensions.GetStringAsync(IDistributedCache cache, String key, CancellationToken token)

我做错什么了?为什么我会得到这个例外??顺便说一句,我是按照这个教程取消jwts

gajydyqb

gajydyqb1#

我不敢相信我会这么说,但事实证明,导致这个异常的问题,让我发疯的是在连接字符串中。而不是 "localhost" ,我打字 "localhsot" . 一旦我修好了,一切都如期进行。

相关问题