Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyT for set operations #3190

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 11 additions & 11 deletions redis/commands/core.py
Expand Up @@ -3306,15 +3306,15 @@ class SetCommands(CommandsProtocol):
see: https://redis.io/topics/data-types#sets
"""

def sadd(self, name: str, *values: FieldT) -> Union[Awaitable[int], int]:
def sadd(self, name: KeyT, *values: FieldT) -> Union[Awaitable[int], int]:
"""
Add ``value(s)`` to set ``name``

For more information see https://redis.io/commands/sadd
"""
return self.execute_command("SADD", name, *values)

def scard(self, name: str) -> Union[Awaitable[int], int]:
def scard(self, name: KeyT) -> Union[Awaitable[int], int]:
"""
Return the number of elements in set ``name``

Expand Down Expand Up @@ -3353,7 +3353,7 @@ def sinter(self, keys: List, *args: List) -> Union[Awaitable[list], list]:
return self.execute_command("SINTER", *args, keys=args)

def sintercard(
self, numkeys: int, keys: List[str], limit: int = 0
self, numkeys: int, keys: List[KeyT], limit: int = 0
) -> Union[Awaitable[int], int]:
"""
Return the cardinality of the intersect of multiple sets specified by ``keys`.
Expand All @@ -3380,7 +3380,7 @@ def sinterstore(
return self.execute_command("SINTERSTORE", dest, *args)

def sismember(
self, name: str, value: str
self, name: KeyT, value: str
) -> Union[Awaitable[Union[Literal[0], Literal[1]]], Union[Literal[0], Literal[1]]]:
"""
Return whether ``value`` is a member of set ``name``:
Expand All @@ -3391,7 +3391,7 @@ def sismember(
"""
return self.execute_command("SISMEMBER", name, value, keys=[name])

def smembers(self, name: str) -> Union[Awaitable[Set], Set]:
def smembers(self, name: KeyT) -> Union[Awaitable[Set], Set]:
"""
Return all members of the set ``name``

Expand All @@ -3400,7 +3400,7 @@ def smembers(self, name: str) -> Union[Awaitable[Set], Set]:
return self.execute_command("SMEMBERS", name, keys=[name])

def smismember(
self, name: str, values: List, *args: List
self, name: KeyT, values: List, *args: List
) -> Union[
Awaitable[List[Union[Literal[0], Literal[1]]]],
List[Union[Literal[0], Literal[1]]],
Expand All @@ -3416,15 +3416,15 @@ def smismember(
args = list_or_args(values, args)
return self.execute_command("SMISMEMBER", name, *args, keys=[name])

def smove(self, src: str, dst: str, value: str) -> Union[Awaitable[bool], bool]:
def smove(self, src: KeyT, dst: KeyT, value: str) -> Union[Awaitable[bool], bool]:
"""
Move ``value`` from set ``src`` to set ``dst`` atomically

For more information see https://redis.io/commands/smove
"""
return self.execute_command("SMOVE", src, dst, value)

def spop(self, name: str, count: Optional[int] = None) -> Union[str, List, None]:
def spop(self, name: KeyT, count: Optional[int] = None) -> Union[str, List, None]:
"""
Remove and return a random member of set ``name``

Expand All @@ -3434,7 +3434,7 @@ def spop(self, name: str, count: Optional[int] = None) -> Union[str, List, None]
return self.execute_command("SPOP", name, *args)

def srandmember(
self, name: str, number: Optional[int] = None
self, name: KeyT, number: Optional[int] = None
) -> Union[str, List, None]:
"""
If ``number`` is None, returns a random member of set ``name``.
Expand All @@ -3448,7 +3448,7 @@ def srandmember(
args = (number is not None) and [number] or []
return self.execute_command("SRANDMEMBER", name, *args)

def srem(self, name: str, *values: FieldT) -> Union[Awaitable[int], int]:
def srem(self, name: KeyT, *values: FieldT) -> Union[Awaitable[int], int]:
"""
Remove ``values`` from set ``name``

Expand All @@ -3466,7 +3466,7 @@ def sunion(self, keys: List, *args: List) -> Union[Awaitable[List], List]:
return self.execute_command("SUNION", *args, keys=args)

def sunionstore(
self, dest: str, keys: List, *args: List
self, dest: KeyT, keys: List, *args: List
) -> Union[Awaitable[int], int]:
"""
Store the union of sets specified by ``keys`` into a new
Expand Down