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

Revert some typing commits #163

Merged
merged 4 commits into from
Dec 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 25 additions & 20 deletions valkey/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
AsyncIterator,
Awaitable,
Callable,
Dict,
Iterable,
Iterator,
List,
Expand Down Expand Up @@ -2153,7 +2152,7 @@ def pttl(self, name: KeyT) -> ResponseT:

def hrandfield(
self, key: str, count: int = None, withvalues: bool = False
) -> Union[bytes, List[bytes], None]:
) -> ResponseT:
"""
Return a random field from the hash value stored at key.

Expand Down Expand Up @@ -2995,7 +2994,7 @@ def scan(
count: Union[int, None] = None,
_type: Union[str, None] = None,
**kwargs,
) -> Tuple[int, List[bytes]]:
) -> ResponseT:
"""
Incrementally return lists of key names. Also return a cursor
indicating the scan position.
Expand Down Expand Up @@ -3055,7 +3054,7 @@ def sscan(
cursor: int = 0,
match: Union[PatternT, None] = None,
count: Union[int, None] = None,
) -> Tuple[int, List[bytes]]:
) -> ResponseT:
"""
Incrementally return lists of elements in a set. Also return a cursor
indicating the scan position.
Expand Down Expand Up @@ -3099,7 +3098,7 @@ def hscan(
match: Union[PatternT, None] = None,
count: Union[int, None] = None,
no_values: Union[bool, None] = None,
) -> Tuple[int, Dict[bytes, bytes]]:
) -> ResponseT:
"""
Incrementally return key/value slices in a hash. Also return a cursor
indicating the scan position.
Expand Down Expand Up @@ -3155,7 +3154,7 @@ def zscan(
match: Union[PatternT, None] = None,
count: Union[int, None] = None,
score_cast_func: Union[type, Callable] = float,
) -> Tuple[int, List[Tuple[bytes, float]]]:
) -> ResponseT:
"""
Incrementally return lists of elements in a sorted set. Also return a
cursor indicating the scan position.
Expand Down Expand Up @@ -4944,63 +4943,69 @@ class HashCommands(CommandsProtocol):
see: https://valkey.io/topics/data-types-intro#valkey-hashes
"""

def hdel(self, name: str, *keys: str) -> int:
def hdel(self, name: str, *keys: str) -> Union[Awaitable[int], int]:
"""
Delete ``keys`` from hash ``name``

For more information see https://valkey.io/commands/hdel
"""
return self.execute_command("HDEL", name, *keys)

def hexists(self, name: str, key: str) -> bool:
def hexists(self, name: str, key: str) -> Union[Awaitable[bool], bool]:
"""
Returns a boolean indicating if ``key`` exists within hash ``name``

For more information see https://valkey.io/commands/hexists
"""
return self.execute_command("HEXISTS", name, key, keys=[name])

def hget(self, name: str, key: str) -> Optional[bytes]:
def hget(
self, name: str, key: str
) -> Union[Awaitable[Optional[str]], Optional[str]]:
"""
Return the value of ``key`` within the hash ``name``

For more information see https://valkey.io/commands/hget
"""
return self.execute_command("HGET", name, key, keys=[name])

def hgetall(self, name: str) -> dict:
def hgetall(self, name: str) -> Union[Awaitable[dict], dict]:
"""
Return a Python dict of the hash's name/value pairs

For more information see https://valkey.io/commands/hgetall
"""
return self.execute_command("HGETALL", name, keys=[name])

def hincrby(self, name: str, key: str, amount: int = 1) -> int:
def hincrby(
self, name: str, key: str, amount: int = 1
) -> Union[Awaitable[int], int]:
"""
Increment the value of ``key`` in hash ``name`` by ``amount``

For more information see https://valkey.io/commands/hincrby
"""
return self.execute_command("HINCRBY", name, key, amount)

def hincrbyfloat(self, name: str, key: str, amount: float = 1.0) -> float:
def hincrbyfloat(
self, name: str, key: str, amount: float = 1.0
) -> Union[Awaitable[float], float]:
"""
Increment the value of ``key`` in hash ``name`` by floating ``amount``

For more information see https://valkey.io/commands/hincrbyfloat
"""
return self.execute_command("HINCRBYFLOAT", name, key, amount)

def hkeys(self, name: str) -> List[bytes]:
def hkeys(self, name: str) -> Union[Awaitable[List], List]:
"""
Return the list of keys within hash ``name``

For more information see https://valkey.io/commands/hkeys
"""
return self.execute_command("HKEYS", name, keys=[name])

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

Expand All @@ -5015,7 +5020,7 @@ def hset(
value: Optional[str] = None,
mapping: Optional[dict] = None,
items: Optional[list] = None,
) -> int:
) -> Union[Awaitable[int], int]:
"""
Set ``key`` to ``value`` within hash ``name``,
``mapping`` accepts a dict of key/value pairs that will be
Expand All @@ -5039,7 +5044,7 @@ def hset(

return self.execute_command("HSET", name, *pieces)

def hsetnx(self, name: str, key: str, value: str) -> int:
def hsetnx(self, name: str, key: str, value: str) -> Union[Awaitable[bool], bool]:
"""
Set ``key`` to ``value`` within hash ``name`` if ``key`` does not
exist. Returns 1 if HSETNX created a field, otherwise 0.
Expand All @@ -5048,7 +5053,7 @@ def hsetnx(self, name: str, key: str, value: str) -> int:
"""
return self.execute_command("HSETNX", name, key, value)

def hmset(self, name: str, mapping: dict) -> bool:
def hmset(self, name: str, mapping: dict) -> Union[Awaitable[str], str]:
"""
Set key to value within hash ``name`` for each corresponding
key and value from the ``mapping`` dict.
Expand All @@ -5068,7 +5073,7 @@ def hmset(self, name: str, mapping: dict) -> bool:
items.extend(pair)
return self.execute_command("HMSET", name, *items)

def hmget(self, name: str, keys: List, *args: List) -> List[bytes]:
def hmget(self, name: str, keys: List, *args: List) -> Union[Awaitable[List], List]:
"""
Returns a list of values ordered identically to ``keys``

Expand All @@ -5077,15 +5082,15 @@ def hmget(self, name: str, keys: List, *args: List) -> List[bytes]:
args = list_or_args(keys, args)
return self.execute_command("HMGET", name, *args, keys=[name])

def hvals(self, name: str) -> List[bytes]:
def hvals(self, name: str) -> Union[Awaitable[List], List]:
"""
Return the list of values within hash ``name``

For more information see https://valkey.io/commands/hvals
"""
return self.execute_command("HVALS", name, keys=[name])

def hstrlen(self, name: str, key: str) -> int:
def hstrlen(self, name: str, key: str) -> Union[Awaitable[int], int]:
"""
Return the number of bytes stored in the value of ``key``
within hash ``name``
Expand Down
Loading