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

Empty sets still exist #155

Closed
tapple opened this issue Jul 5, 2017 · 1 comment · Fixed by ska-sa/fakenewsredis#4
Closed

Empty sets still exist #155

tapple opened this issue Jul 5, 2017 · 1 comment · Fixed by ska-sa/fakenewsredis#4

Comments

@tapple
Copy link

tapple commented Jul 5, 2017

sets that have every element removed should answer False to exists, and should not be returned by keys or scan. However, they do. I don't know if sorted sets, lists, hashes, or strings also have this problem

In [1]: import fakeredis
In [2]: import redis
In [3]: r = fakeredis.FakeStrictRedis()
In [4]: r.sadd('s', 1)
Out[4]: 1
In [5]: assert r.exists('s')
In [8]: assert b's' in r.keys()
In [9]: r.srem('s', 1)
Out[9]: 1
In [10]: assert not r.exists('s')
Traceback (most recent call last):
File "", line 1, in
AssertionError

In [11]: assert b's' not in r.keys()
Traceback (most recent call last):
File "", line 1, in
AssertionError

In [12]: r = redis.StrictRedis()
In [13]: r.sadd('s', 1)
Out[13]: 1
In [14]: assert r.exists('s')
In [15]: assert b's' in r.keys()
In [16]: r.srem('s', 1)
Out[16]: 1
In [17]: assert not r.exists('s')
In [18]: assert b's' not in r.keys()
In [19]:

@fjsj
Copy link

fjsj commented Oct 25, 2017

Confirm the issue. This breaks one of my algorithms :(
Both redis-cli and StrictRedis return False for empty sets if you call exists.

The correct behavior:

$ redis-cli
127.0.0.1:6379> del my_set
(integer) 0
127.0.0.1:6379> sadd my_set 1
(integer) 1
127.0.0.1:6379> spop my_set
"1"
127.0.0.1:6379> exists my_set
(integer) 0

I guess this also needs to be solved for lists, sorted sets, hashes, etc.

bmerry added a commit to ska-sa/fakenewsredis that referenced this issue Jan 19, 2018
@bmerry bmerry closed this as completed in a1cd907 Mar 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants