zunionstore異常:CROSSSLOT Keys in request don't hash to the same slot
阿新 • • 發佈:2019-01-10
這裡需要注意的是需要組成並集的各個集合的key必須是對應到redis叢集中的同一個slot上,否則將會出現一個異常:CROSSSLOT Keys in request don’t hash to the same slot。所以redis提供了一種特定的標籤{},這個{}內的字串才參與計算hash slot.列如:{user}:aaa與{user}:bbb 這兩個集合可以確保在同一個slot上,可以使用zunionstore求它們的並集。所以,在處理這種需要合併redis歷史資料時,如果是在redis叢集環境下,需要特別注意。
在cluster上所有的多key操作都會報同樣的錯誤
172.16 .0.130:6379> zadd {user}:ccc 1 petter
-> Redirected to slot [5474] located at 172.16.0.135:6379
(integer) 1
172.16.0.135:6379> zrange {user}:ccc 0 -1
1) "petter"
172.16.0.135:6379> zadd {user}:ddd 2 jack
(integer) 1
172.16.0.135:6379> zrange {user}:ddd 0 -1
1) "jack"
172.16.0.135:6379> zunionstore {user}:sum 2 {user}:ccc {user}:ddd
(integer) 2
172.16.0.135:6379> zrange {user}:sum 0 -1
1) "petter"
2) "jack"
172.16.0.135:6379>