I'm trying to use Redis as a cache for blacklisting JWTs, to implement logout with JWT.
I have downloaded redis on my windows 10 machine and run "redis-server.exe"
and it says :
[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
which indicates that it is working correctly.
I'm using .NetCore 3.1 , and I have Microsoft.Extensions.Caching.Redis
v2.2.0 Nuget package installed.
in my startup.cs
I added
services.AddDistributedRedisCache(r =>
{
r.Configuration = Configuration["Redis:ConnectionString"];
});
and in my appsettings.json
I have
"Redis": {
"ConnectionString": "localhsot"
}
but at any request I'm sending I'm getting the following exception :
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)
what I'm I doing wrong? why am I getting this exception?? btw I was following this tutorial on cancelling JWTs
I can't believe I'm saying this, but it turned out that the problem that caused this exception that drove me crazy was in the connection string.
instead of "localhost"
, I typed "localhsot"
. once I fixed it, everything worked as expected.