Skip to content

Commit ebdf9c9

Browse files
author
Mikhail Koviazin
authored
Merge pull request #154 from amirreza8002/htypes
fixed type hints of hash methods
2 parents d5bb6bf + c006c85 commit ebdf9c9

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

valkey/commands/core.py

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4944,69 +4944,63 @@ class HashCommands(CommandsProtocol):
49444944
see: https://valkey.io/topics/data-types-intro#valkey-hashes
49454945
"""
49464946

4947-
def hdel(self, name: str, *keys: str) -> Union[Awaitable[int], int]:
4947+
def hdel(self, name: str, *keys: str) -> int:
49484948
"""
49494949
Delete ``keys`` from hash ``name``
49504950
49514951
For more information see https://valkey.io/commands/hdel
49524952
"""
49534953
return self.execute_command("HDEL", name, *keys)
49544954

4955-
def hexists(self, name: str, key: str) -> Union[Awaitable[bool], bool]:
4955+
def hexists(self, name: str, key: str) -> bool:
49564956
"""
49574957
Returns a boolean indicating if ``key`` exists within hash ``name``
49584958
49594959
For more information see https://valkey.io/commands/hexists
49604960
"""
49614961
return self.execute_command("HEXISTS", name, key, keys=[name])
49624962

4963-
def hget(
4964-
self, name: str, key: str
4965-
) -> Union[Awaitable[Optional[str]], Optional[str]]:
4963+
def hget(self, name: str, key: str) -> Optional[bytes]:
49664964
"""
49674965
Return the value of ``key`` within the hash ``name``
49684966
49694967
For more information see https://valkey.io/commands/hget
49704968
"""
49714969
return self.execute_command("HGET", name, key, keys=[name])
49724970

4973-
def hgetall(self, name: str) -> Union[Awaitable[dict], dict]:
4971+
def hgetall(self, name: str) -> dict:
49744972
"""
49754973
Return a Python dict of the hash's name/value pairs
49764974
49774975
For more information see https://valkey.io/commands/hgetall
49784976
"""
49794977
return self.execute_command("HGETALL", name, keys=[name])
49804978

4981-
def hincrby(
4982-
self, name: str, key: str, amount: int = 1
4983-
) -> Union[Awaitable[int], int]:
4979+
def hincrby(self, name: str, key: str, amount: int = 1) -> int:
49844980
"""
49854981
Increment the value of ``key`` in hash ``name`` by ``amount``
49864982
49874983
For more information see https://valkey.io/commands/hincrby
49884984
"""
49894985
return self.execute_command("HINCRBY", name, key, amount)
49904986

4991-
def hincrbyfloat(
4992-
self, name: str, key: str, amount: float = 1.0
4993-
) -> Union[Awaitable[float], float]:
4987+
def hincrbyfloat(self, name: str, key: str, amount: float = 1.0) -> float:
49944988
"""
49954989
Increment the value of ``key`` in hash ``name`` by floating ``amount``
49964990
49974991
For more information see https://valkey.io/commands/hincrbyfloat
49984992
"""
49994993
return self.execute_command("HINCRBYFLOAT", name, key, amount)
50004994

5001-
def hkeys(self, name: str) -> Union[Awaitable[List], List]:
4995+
def hkeys(self, name: str) -> List[bytes]:
50024996
"""
50034997
Return the list of keys within hash ``name``
50044998
50054999
For more information see https://valkey.io/commands/hkeys
50065000
"""
50075001
return self.execute_command("HKEYS", name, keys=[name])
50085002

5009-
def hlen(self, name: str) -> Union[Awaitable[int], int]:
5003+
def hlen(self, name: str) -> int:
50105004
"""
50115005
Return the number of elements in hash ``name``
50125006
@@ -5021,7 +5015,7 @@ def hset(
50215015
value: Optional[str] = None,
50225016
mapping: Optional[dict] = None,
50235017
items: Optional[list] = None,
5024-
) -> Union[Awaitable[int], int]:
5018+
) -> int:
50255019
"""
50265020
Set ``key`` to ``value`` within hash ``name``,
50275021
``mapping`` accepts a dict of key/value pairs that will be
@@ -5045,7 +5039,7 @@ def hset(
50455039

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

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

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

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

5086-
def hvals(self, name: str) -> Union[Awaitable[List], List]:
5080+
def hvals(self, name: str) -> List[bytes]:
50875081
"""
50885082
Return the list of values within hash ``name``
50895083
50905084
For more information see https://valkey.io/commands/hvals
50915085
"""
50925086
return self.execute_command("HVALS", name, keys=[name])
50935087

5094-
def hstrlen(self, name: str, key: str) -> Union[Awaitable[int], int]:
5088+
def hstrlen(self, name: str, key: str) -> int:
50955089
"""
50965090
Return the number of bytes stored in the value of ``key``
50975091
within hash ``name``

0 commit comments

Comments
 (0)