Skip to content
Open
Show file tree
Hide file tree
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
18 changes: 15 additions & 3 deletions .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,21 @@ lint.select = [
]

lint.ignore = [
"COM812", # missing trailing comma, covered by black
"ANN101", # ignore missing type annotation in self parameter
"S311", # ignore Standard pseudo-random generators because they are not used for cryptographic purposes
# missing trailing comma, covered by black
# docs: https://docs.astral.sh/ruff/rules/missing-trailing-comma/
"COM812",
# ignore missing type annotation in self parameter
# docs: https://docs.astral.sh/ruff/rules/missing-type-self/#missing-type-self-ann101
"ANN101",
# ignore builtin import shadowing
# docs: https://docs.astral.sh/ruff/rules/builtin-import-shadowing/#builtin-import-shadowing-a004
"A004",
# ignore Standard pseudo-random generators because they are not used for cryptographic purposes
# docs: https://docs.astral.sh/ruff/rules/suspicious-non-cryptographic-random-usage/#suspicious-non-cryptographic-random-usage-s311
"S311",
# ignore stdlib module shadowing
# docs: https://docs.astral.sh/ruff/rules/stdlib-module-shadowing/
"A005",
]

fix = true
Expand Down
1 change: 1 addition & 0 deletions changelog.d/765.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix incorrect namespacing applied to Redis hash field keys
39 changes: 24 additions & 15 deletions django_redis/client/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -1099,8 +1099,8 @@ def touch(

def hset(
self,
name: str,
key: KeyT,
name: KeyT,
key: str,
value: EncodableT,
version: Optional[int] = None,
client: Optional[Redis] = None,
Expand All @@ -1111,14 +1111,15 @@ def hset(
"""
if client is None:
client = self.get_client(write=True)
nkey = self.make_key(key, version=version)

name = self.make_key(name, version=version)
nvalue = self.encode(value)
return int(client.hset(name, nkey, nvalue))
return int(client.hset(name, key, nvalue))

def hdel(
self,
name: str,
key: KeyT,
name: KeyT,
key: str,
version: Optional[int] = None,
client: Optional[Redis] = None,
) -> int:
Expand All @@ -1128,40 +1129,47 @@ def hdel(
"""
if client is None:
client = self.get_client(write=True)
nkey = self.make_key(key, version=version)
return int(client.hdel(name, nkey))

name = self.make_key(name, version=version)
return int(client.hdel(name, key))

def hlen(
self,
name: str,
name: KeyT,
version: Optional[int] = None,
client: Optional[Redis] = None,
) -> int:
"""
Return the number of items in hash name.
"""
if client is None:
client = self.get_client(write=False)

name = self.make_key(name, version=version)
return int(client.hlen(name))

def hkeys(
self,
name: str,
name: KeyT,
version: Optional[int] = None,
client: Optional[Redis] = None,
) -> List[Any]:
"""
Return a list of keys in hash name.
"""
if client is None:
client = self.get_client(write=False)

name = self.make_key(name, version=version)
try:
return [self.reverse_key(k.decode()) for k in client.hkeys(name)]
return [k.decode() for k in client.hkeys(name)]
except _main_exceptions as e:
raise ConnectionInterrupted(connection=client) from e

def hexists(
self,
name: str,
key: KeyT,
name: KeyT,
key: str,
version: Optional[int] = None,
client: Optional[Redis] = None,
) -> bool:
Expand All @@ -1170,5 +1178,6 @@ def hexists(
"""
if client is None:
client = self.get_client(write=False)
nkey = self.make_key(key, version=version)
return bool(client.hexists(name, nkey))

name = self.make_key(name, version=version)
return bool(client.hexists(name, key))
Loading