go-redis icon indicating copy to clipboard operation
go-redis copied to clipboard

READONLY You can't write against a read only replica.

Open thaitanloi365 opened this issue 3 years ago • 2 comments

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.

thaitanloi365 avatar Feb 01 '21 12:02 thaitanloi365

this is not an error of redis.Client, please read the redis documentation: https://redis.io/topics/replication#read-only-replica

monkey92t avatar Feb 02 '21 02:02 monkey92t

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 avatar Aug 25 '22 11:08 bhuiyanmobasshir94

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.

Queetinliu avatar Nov 02 '22 03:11 Queetinliu

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

hadpro24 avatar Feb 06 '23 04:02 hadpro24

any solution ?

SiddheshKukade avatar Feb 18 '23 15:02 SiddheshKukade

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.

rhengles avatar Feb 18 '23 16:02 rhengles