@@ -1978,10 +1978,21 @@ def test_cluster_zrangestore(self, r):
1978
1978
1979
1979
@skip_if_server_version_lt ("6.2.0" )
1980
1980
def test_cluster_zunion (self , r ):
1981
+ assert r .zunion (["{foo}" + str (i ) for i in range (0 , 256 )]) == []
1982
+
1981
1983
r .zadd ("{foo}a" , {"a1" : 1 , "a2" : 1 , "a3" : 1 })
1982
1984
r .zadd ("{foo}b" , {"a1" : 2 , "a2" : 2 , "a3" : 2 })
1983
1985
r .zadd ("{foo}c" , {"a1" : 6 , "a3" : 5 , "a4" : 4 })
1986
+
1987
+ failed_keys = ["{foo1}a" , "{foo}b" , "{foo}c" ]
1988
+ with pytest .raises (
1989
+ RedisClusterException ,
1990
+ match = "ZUNION - all keys must map to the same key slot" ,
1991
+ ):
1992
+ r .zunion (failed_keys )
1993
+
1984
1994
# sum
1995
+ assert r .zunion (["{foo}a" ]) == [b"a1" , b"a2" , b"a3" ]
1985
1996
assert r .zunion (["{foo}a" , "{foo}b" , "{foo}c" ]) == [b"a2" , b"a4" , b"a3" , b"a1" ]
1986
1997
assert r .zunion (["{foo}a" , "{foo}b" , "{foo}c" ], withscores = True ) == [
1987
1998
(b"a2" , 3 ),
@@ -2006,10 +2017,30 @@ def test_cluster_zunion(self, r):
2006
2017
]
2007
2018
2008
2019
def test_cluster_zunionstore_sum (self , r ):
2020
+ assert r .zunionstore ("{foo}d" , ["{foo}" + str (i ) for i in range (0 , 256 )]) == 0
2021
+
2009
2022
r .zadd ("{foo}a" , {"a1" : 1 , "a2" : 1 , "a3" : 1 })
2010
2023
r .zadd ("{foo}b" , {"a1" : 2 , "a2" : 2 , "a3" : 2 })
2011
2024
r .zadd ("{foo}c" , {"a1" : 6 , "a3" : 5 , "a4" : 4 })
2025
+
2026
+ result_key = "{foo}d"
2027
+ failed_keys = ["{foo1}a" , "{foo}b" , "{foo}c" ]
2028
+ with pytest .raises (
2029
+ RedisClusterException ,
2030
+ match = "ZUNIONSTORE - all keys must map to the same key slot" ,
2031
+ ):
2032
+ r .zunionstore (result_key , failed_keys )
2033
+
2034
+ result_key = "{foo1}d"
2035
+ failed_keys = ["{foo}a" , "{foo}b" ]
2036
+ with pytest .raises (
2037
+ RedisClusterException ,
2038
+ match = "ZUNIONSTORE - all keys must map to the same key slot" ,
2039
+ ):
2040
+ r .zunionstore (result_key , failed_keys )
2041
+
2012
2042
assert r .zunionstore ("{foo}d" , ["{foo}a" , "{foo}b" , "{foo}c" ]) == 4
2043
+ assert r .zunionstore ("{foo}e" , ["{foo}a" ]) == 3
2013
2044
assert r .zrange ("{foo}d" , 0 , - 1 , withscores = True ) == [
2014
2045
(b"a2" , 3 ),
2015
2046
(b"a4" , 4 ),
0 commit comments