首页 新闻 会员 周边 捐助

redis 集群 rename key 的问题

0
悬赏园豆:30 [已解决问题] 解决于 2022-06-11 18:24

使用 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

请问如何解决?

dudu的主页 dudu | 高人七级 | 园豆:29568
提问于:2022-06-11 17:22
< >
分享
最佳答案
0

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

dudu | 高人七级 |园豆:29568 | 2022-06-11 18:24
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册