File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed
Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -1185,3 +1185,34 @@ async def zadd_incr(
11851185 Optional [float ],
11861186 await self ._execute_command (RequestType .Zadd , args ),
11871187 )
1188+
1189+ async def zrem (
1190+ self ,
1191+ key : str ,
1192+ members : List [str ],
1193+ ) -> int :
1194+ """
1195+ Removes the specified members from the sorted set stored at `key`.
1196+ Specified members that are not a member of this set are ignored.
1197+
1198+ See https://redis.io/commands/zrem/ for more details.
1199+
1200+ Args:
1201+ key (str): The key of the sorted set.
1202+ members (List[str]): A list of members to remove from the sorted set.
1203+
1204+ Returns:
1205+ int: The number of members that were removed from the sorted set, not including non-existing members.
1206+ If `key` does not exist, it is treated as an empty sorted set, and this command returns 0.
1207+ If `key` holds a value that is not a sorted set, an error is returned.
1208+
1209+ Examples:
1210+ >>> await zrem("my_sorted_set", ["member1", "member2"])
1211+ 2 # Indicates that two members have been removed from the sorted set "my_sorted_set."
1212+ >>> await zrem("non_existing_sorted_set", ["member1", "member2"])
1213+ 0 # Indicates that no members were removed as the sorted set "non_existing_sorted_set" does not exist.
1214+ """
1215+ return cast (
1216+ int ,
1217+ await self ._execute_command (RequestType .Zrem , [key ] + members ),
1218+ )
Original file line number Diff line number Diff line change @@ -1044,6 +1044,17 @@ async def test_zadd_gt_lt(self, redis_client: TRedisClient):
10441044 == None
10451045 )
10461046
1047+ @pytest .mark .parametrize ("cluster_mode" , [True , False ])
1048+ async def test_zrem (self , redis_client : TRedisClient ):
1049+ key = get_random_string (10 )
1050+ members_scores = {"one" : 1 , "two" : 2 , "three" : 3 }
1051+ assert await redis_client .zadd (key , members_scores = members_scores ) == 3
1052+
1053+ assert await redis_client .zrem (key , ["one" ]) == 1
1054+ assert await redis_client .zrem (key , ["one" , "two" , "three" ]) == 2
1055+
1056+ assert await redis_client .zrem ("non_existing_set" , ["member" ]) == 0
1057+
10471058
10481059class TestCommandsUnitTests :
10491060 def test_expiry_cmd_args (self ):
You can’t perform that action at this time.
0 commit comments