Warm tip: This article is reproduced from serverfault.com, please click

jwt-StackExchange.Redis.RedisConnectionException

(jwt - StackExchange.Redis.RedisConnectionException)

发布于 2020-11-28 14:56:05

我正在尝试将Redis用作将JWT列入黑名单的缓存,以实现JWT的注销。我已经在Windows 10机器上下载了Redis并运行"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)
   

我做错了什么?为什么我会收到此异常?顺便说一句,我正在关注取消JWT的本教程

Questioner
Ataa Aub
Viewed
11
Ataa Aub 2020-11-29 15:35:24

我不敢相信我是在说这句话,但事实证明,导致该异常使我发疯的问题是连接字符串中的问题。相反"localhost",我输入了"localhsot"一旦修复它,一切都会按预期进行。