From 37e7fe17f1995a950da4cb858e886d48f4b7fb60 Mon Sep 17 00:00:00 2001 From: ARUN SINGH Date: Wed, 28 Feb 2024 19:30:11 +0530 Subject: [PATCH] Added redis tag for redis key prefix to fix CROSSSLOT error in redis cluster. Added curly braces around the key prefix name makes it a redis-tag. redis-tag ensures that all the keys starting with this prefix are mapped to the same keyslot when redis which will fix CROSSSLOT error in redis cluster.In single instance mode all keyslots are present in same shard hence CROSSSLOT error will not happen. --- rate.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/rate.go b/rate.go index 1cfc36e..0041dda 100644 --- a/rate.go +++ b/rate.go @@ -8,8 +8,10 @@ import ( "github.com/redis/go-redis/v9" ) - -const redisPrefix = "rate:" +// Using curly braces around the key prefix name makes it a redis-tag. +// redis-tag ensures that all the keys starting with this prefix are mapped to the same keyslot when redis which will fix +// CROSSSLOT error in redis cluster.In single instance mode all keyslots are present in same shard hence CROSSSLOT error will not happen. +const redisPrefix = "{redis_rate}:" type rediser interface { Eval(ctx context.Context, script string, keys []string, args ...interface{}) *redis.Cmd