go-redis
go-redis copied to clipboard
READONLY You can't write against a read only replica.
Hi, I'm using this library in many projects. Sometimes I was getting this error. I only used this library for caching purposes with basic Get,Set function. Here is my redis configuration:
var cache = redis.New(&redis.Config{
Namespace: config.RedisNamespace,
DefaultExpiration: time.Hour * 2,
Options: &goredis.Options{
Addr: config.RedisAddress,
DB: config.RedisDBMode,
Password: config.RedisPassword,
PoolSize: 1000,
PoolTimeout: 2 * time.Minute,
IdleTimeout: 10 * time.Minute,
ReadTimeout: 2 * time.Minute,
WriteTimeout: 1 * time.Minute,
},
})
Please help me to troubleshoot this issue. Thanks.
this is not an error of redis.Client, please read the redis documentation: https://redis.io/topics/replication#read-only-replica
I think salves are by default readonly, so you can remove this error by changing their readonly status.
redis-cli -h 127.0.0.1 -p 6379 slaveof no one
According to the redis document,it's best that slave read only.I faced to this problem because there is no master role in my redis.After fix redis replication problem,then I can write in redis sentinel mode.
I think salves are by default readonly, so you can remove this error by changing their readonly status.
redis-cli -h 127.0.0.1 -p 6379 slaveof no one
@bhuiyanmobasshir94 This command works but the problem comes back after some time
any solution ?
This was my solution: https://discord.com/channels/564160730845151244/1075915896536698912/1076239855798993048 https://stackoverflow.com/questions/72521353/redis-issue-with-readonly-you-cant-write-against-a-read-only-replica-but-only-r My problem was that the Redis port was exposed to the internet and I wasn't aware.