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

Simple test for SADDEX #348

Merged
merged 3 commits into from
Dec 15, 2024
Merged
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: 11 additions & 7 deletions fakeredis/_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import re
import sys
import time
from typing import Iterable, Tuple, Union, Optional, Any, Type, List, Callable, Sequence, Dict, Set
from typing import Iterable, Tuple, Union, Optional, Any, Type, List, Callable, Sequence, Dict, Set, Collection

from . import _msgs as msgs
from ._helpers import null_terminate, SimpleError, Database, current_time
Expand Down Expand Up @@ -107,7 +107,7 @@ def __bool__(self) -> bool:
__nonzero__ = __bool__ # For Python 2


class Hash: # type:ignore
class Hash:
DECODE_ERROR = msgs.INVALID_HASH_MSG
redis_type = b"hash"

Expand All @@ -116,7 +116,7 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
self._expirations: Dict[bytes, int] = dict()
self._values: Dict[bytes, Any] = dict()

def _expire_keys(self):
def _expire_keys(self) -> None:
removed = []
now = current_time()
for k in self._expirations:
Expand Down Expand Up @@ -154,14 +154,14 @@ def __setitem__(self, key: bytes, value: Any) -> None:
self._expirations.pop(key, None)
self._values[key] = value

def __delitem__(self, key):
def __delitem__(self, key: bytes) -> None:
self._values.pop(key, None)
self._expirations.pop(key, None)

def __len__(self):
def __len__(self) -> int:
return len(self._values)

def __iter__(self):
def __iter__(self) -> Iterable[bytes]:
return iter(self._values)

def get(self, key: bytes, default: Any = None) -> Any:
Expand Down Expand Up @@ -425,7 +425,11 @@ def __init__(
repeat: Tuple[Type[Union[RedisType, bytes]]] = (), # type:ignore
args: Tuple[str] = (), # type:ignore
flags: str = "",
server_types: Tuple[str] = ("redis", "valkey", "dragonfly"), # supported server types: redis, dragonfly, valkey
server_types: Collection[str] = (
"redis",
"valkey",
"dragonfly",
), # supported server types: redis, dragonfly, valkey
):
self.name = name
self.func_name = func_name
Expand Down
9 changes: 9 additions & 0 deletions test/test_mixins/test_set_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@
from test import testtools


@pytest.mark.slow
@pytest.mark.unsupported_server_types("redis", "valkey")
def test_saddex(r: redis.Redis):
set_name = "foo"
assert testtools.raw_command(r, "saddex", set_name, 1, "m1", "m2") == 2
sleep(1.01)
assert set(r.smembers("foo")) == set()


@testtools.run_test_if_redispy_ver("gte", "5.1")
def test_sadd(r: redis.Redis):
assert r.sadd("foo", "member1") == 1
Expand Down
Loading