redis 集群 rename key 的问题

使用 StackExchange.Redis 对 redis 集群中的一个 key 进行重名

await _redisDatabase.Database.KeyRenameAsync(oldkey, newkey, When.NotExists);

出现下面的错误

StackExchange.Redis.RedisCommandException: Multi-key operations must involve a single slot; keys can use 'hash tags' to help this, i.e. '{/users/12345}/account' and '{/users/12345}/contacts' will always be in the same slot
at StackExchange.Redis.ServerSelectionStrategy.Select(Message message, Boolean allowDisconnected) in /_/src/StackExchange.Redis/ServerSelectionStrategy.cs:line 115
at StackExchange.Redis.ConnectionMultiplexer.PrepareToPushMessageToBridge[T](Message message, ResultProcessor`1 processor, IResultBox`1 resultBox, ServerEndPoint& server) in /_/src/StackExchange.Redis/ConnectionMultiplexer.cs:line 1780
at StackExchange.Redis.ConnectionMultiplexer.ExecuteAsyncImpl[T](Message message, ResultProcessor`1 processor, Object state, ServerEndPoint server) in /_/src/StackExchange.Redis/ConnectionMultiplexer.cs:line 1871
at StackExchange.Redis.RedisDatabase.KeyRenameAsync(RedisKey key, RedisKey newKey, When when, CommandFlags flags) in /_/src/StackExchange.Redis/RedisDatabase.cs:line 829

请问如何解决?

回答

用 redis hash tags 解决了,就是在 oldkey 与 newkey 中包含相同的 "{...}" 部分,比如 {whitelist}-staging{whitelist}

以上是redis 集群 rename key 的问题的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>