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

Add support for key prefixes

Open willroberts opened this issue 7 years ago • 23 comments

Reviving this issue: https://github.com/go-redis/redis/issues/563

SELECT doesn't work with clustered Redis, so it's not an appropriate replacement for key prefixing in that case.

willroberts avatar Jul 27 '17 23:07 willroberts

prefix is needed if multi project use a same redis-server

wybosys avatar Dec 28 '18 09:12 wybosys

also need

ljnszu avatar May 08 '20 09:05 ljnszu

I do think this should be done in your application level, not in basic redis client level Such as create an function like this

var (
    prefix string = "AAA_"
)
func Key(s string)string{
  return prefix + s
}
// then
redisClient.Get(Key(xxx))

wziww avatar May 08 '20 10:05 wziww

This would be useful for multi tenancy application too

goxiaoy avatar Nov 29 '20 02:11 goxiaoy

+10086

mengdodo avatar Mar 22 '21 10:03 mengdodo

need

andbridge avatar Apr 26 '21 07:04 andbridge

it would be useful for multi micro service, when they are use the same redis cluster too

Sitrone avatar Jun 28 '21 14:06 Sitrone

need

joewongex avatar Feb 24 '22 02:02 joewongex

This would also be excellent for my use case! When using non-clustered redis, it is trivial to switch between logical databases. However, clustered redis makes it difficult for multi-tenancy within the same redis instance, which would be excellent to implement at the client level rather than in application code.

logyball avatar Mar 15 '22 17:03 logyball

你好,你的邮件我已收到

joewongex avatar Mar 15 '22 17:03 joewongex

we need it

ruanlianjun avatar Aug 30 '22 03:08 ruanlianjun

We just ran into this as well; the redis client should support selecting a key prefix.

Another reason why redis databases are not cutting it (other than them being deprecated) is around ACL. I can define multiple users in my redis cluster and provide different access e.g. by using an access string like on ~TENANT_NAME:* &* -@all +@connection +@read +@write

This allows me to have multiple users on the same redis instance with separated access rights.

Other redis clients, e.g. https://www.npmjs.com/package/ioredis are implementing this feature as well

florian-besser avatar May 04 '23 09:05 florian-besser

need

richelieu-yang avatar Oct 18 '23 06:10 richelieu-yang

I do think this should be done in your application level, not in basic redis client level Such as create an function like this

var (
    prefix string = "AAA_"
)
func Key(s string)string{
  return prefix + s
}
// then
redisClient.Get(Key(xxx))

your own code works well. BUT when you use a library, which use go-redis, you cannot change the library code...

realpg avatar Nov 13 '23 07:11 realpg

你好,你的邮件我已收到

joewongex avatar Nov 13 '23 07:11 joewongex

Absolutely needed. There is a common practice to use the same redis cluster around multiple microservices. Especially we had to make a wrapper to use key prefixes as "namespaces", but now it requires additional work for keeping the wrapper up to date with redis library and generally looks weird in usage as it still also needs some user-land code that constructs the key and then passes it to redis client methods.

heffcodex avatar Nov 21 '23 11:11 heffcodex