Skip to content

Commit

Permalink
Merge pull request #154 from amirreza8002/htypes
Browse files Browse the repository at this point in the history
fixed type hints of hash methods
  • Loading branch information
mkmkme authored Dec 17, 2024
2 parents d5bb6bf + c006c85 commit ebdf9c9
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions valkey/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4944,69 +4944,63 @@ class HashCommands(CommandsProtocol):
see: https://valkey.io/topics/data-types-intro#valkey-hashes
"""

def hdel(self, name: str, *keys: str) -> Union[Awaitable[int], int]:
def hdel(self, name: str, *keys: str) -> 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) -> Union[Awaitable[bool], bool]:
def hexists(self, name: str, key: str) -> 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
) -> Union[Awaitable[Optional[str]], Optional[str]]:
def hget(self, name: str, key: str) -> Optional[bytes]:
"""
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) -> Union[Awaitable[dict], dict]:
def hgetall(self, name: str) -> 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
) -> Union[Awaitable[int], int]:
def hincrby(self, name: str, key: str, amount: int = 1) -> 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
) -> Union[Awaitable[float], float]:
def hincrbyfloat(self, name: str, key: str, amount: float = 1.0) -> 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) -> Union[Awaitable[List], List]:
def hkeys(self, name: str) -> List[bytes]:
"""
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) -> Union[Awaitable[int], int]:
def hlen(self, name: str) -> int:
"""
Return the number of elements in hash ``name``
Expand All @@ -5021,7 +5015,7 @@ def hset(
value: Optional[str] = None,
mapping: Optional[dict] = None,
items: Optional[list] = None,
) -> Union[Awaitable[int], int]:
) -> int:
"""
Set ``key`` to ``value`` within hash ``name``,
``mapping`` accepts a dict of key/value pairs that will be
Expand All @@ -5045,7 +5039,7 @@ def hset(

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

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

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

def hmget(self, name: str, keys: List, *args: List) -> Union[Awaitable[List], List]:
def hmget(self, name: str, keys: List, *args: List) -> List[bytes]:
"""
Returns a list of values ordered identically to ``keys``
Expand All @@ -5083,15 +5077,15 @@ def hmget(self, name: str, keys: List, *args: List) -> Union[Awaitable[List], Li
args = list_or_args(keys, args)
return self.execute_command("HMGET", name, *args, keys=[name])

def hvals(self, name: str) -> Union[Awaitable[List], List]:
def hvals(self, name: str) -> List[bytes]:
"""
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) -> Union[Awaitable[int], int]:
def hstrlen(self, name: str, key: str) -> int:
"""
Return the number of bytes stored in the value of ``key``
within hash ``name``
Expand Down

0 comments on commit ebdf9c9

Please sign in to comment.