Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cunla committed Sep 22, 2024
1 parent fb829ff commit 1468854
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 18 deletions.
4 changes: 2 additions & 2 deletions fakeredis/commands_mixins/hash_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ def _hexpire(self, key: CommandItem, when_ms: int, *args: bytes) -> List[int]:
if (
(nx and current_expiration is not None)
or (xx and current_expiration is None)
or (gt and when_ms <= current_expiration)
or (lt and when_ms >= current_expiration)
or (gt and (current_expiration is None or when_ms <= current_expiration))
or (lt and current_expiration is not None and when_ms >= current_expiration)
):
res.append(0)
continue
Expand Down
18 changes: 2 additions & 16 deletions test/test_mixins/test_hash_commands.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import datetime
from typing import Optional, Dict

import pytest
Expand Down Expand Up @@ -323,37 +322,24 @@ def test_hrandfield(r: redis.Redis):
[
# No flags
(100, None, dict(), 1),
(datetime.timedelta(seconds=100), None, dict(), 1),
(100, 50, dict(), 1),
(datetime.timedelta(seconds=100), 50, dict(), 1),
# NX
(100, None, dict(nx=True), 1),
(datetime.timedelta(seconds=100), None, dict(nx=True), 1),
(100, 50, dict(nx=True), 0),
(datetime.timedelta(seconds=100), 50, dict(nx=True), 0),
# XX
(100, None, dict(xx=True), 0),
(datetime.timedelta(seconds=100), None, dict(xx=True), 0),
(100, 50, dict(xx=True), 1),
(datetime.timedelta(seconds=100), 50, dict(xx=True), 1),
# GT
(100, None, dict(gt=True), 0),
(datetime.timedelta(seconds=100), None, dict(gt=True), 0),
(100, 50, dict(gt=True), 1),
(datetime.timedelta(seconds=100), 50, dict(gt=True), 1),
(100, 100, dict(gt=True), 0),
(datetime.timedelta(seconds=100), 100, dict(gt=True), 0),
(100, 200, dict(gt=True), 0),
(datetime.timedelta(seconds=100), 200, dict(gt=True), 0),
# LT
(100, None, dict(lt=True), 0),
(datetime.timedelta(seconds=100), None, dict(lt=True), 0),
(100, None, dict(lt=True), 1),
(100, 50, dict(lt=True), 0),
(datetime.timedelta(seconds=100), 50, dict(lt=True), 0),
(100, 100, dict(lt=True), 0),
(datetime.timedelta(seconds=100), 100, dict(lt=True), 0),
(100, 200, dict(lt=True), 1),
(datetime.timedelta(seconds=100), 200, dict(lt=True), 1),
],
)
def test_hexpire(
Expand Down

0 comments on commit 1468854

Please sign in to comment.