diff options
author | Avital Fine <79420960+AvitalFineRedis@users.noreply.github.com> | 2021-08-29 11:21:58 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-29 11:21:58 +0300 |
commit | 295b547fb0fe67cef7c21f84f98bbfad4ca80d08 (patch) | |
tree | ab4b50107a3c72fd84b68ddd7cf2518bae81e1ef /tests/test_commands.py | |
parent | 7c77883596e9e28c2d04298bf15ad9f947dd907f (diff) | |
download | redis-py-295b547fb0fe67cef7c21f84f98bbfad4ca80d08.tar.gz |
Support MINID and LIMIT on XADD (#1548)
* MINID and LIMIT
Diffstat (limited to 'tests/test_commands.py')
-rw-r--r-- | tests/test_commands.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/test_commands.py b/tests/test_commands.py index 3c87dd9..d22d72a 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -2423,6 +2423,56 @@ class TestRedisCommands: assert r.xlen(stream) == 3 @skip_if_server_version_lt('6.2.0') + def test_xadd_minlen_and_limit(self, r): + stream = 'stream' + + r.xadd(stream, {'foo': 'bar'}) + r.xadd(stream, {'foo': 'bar'}) + r.xadd(stream, {'foo': 'bar'}) + r.xadd(stream, {'foo': 'bar'}) + + # Future self: No limits without approximate, according to the api + with pytest.raises(redis.ResponseError): + assert r.xadd(stream, {'foo': 'bar'}, maxlen=3, + approximate=False, limit=2) + + # limit can not be provided without maxlen or minid + with pytest.raises(redis.ResponseError): + assert r.xadd(stream, {'foo': 'bar'}, limit=2) + + # maxlen with a limit + assert r.xadd(stream, {'foo': 'bar'}, maxlen=3, + approximate=True, limit=2) + r.delete(stream) + + # maxlen and minid can not be provided together + with pytest.raises(redis.DataError): + assert r.xadd(stream, {'foo': 'bar'}, maxlen=3, + minid="sometestvalue") + + # minid with a limit + m1 = r.xadd(stream, {'foo': 'bar'}) + r.xadd(stream, {'foo': 'bar'}) + r.xadd(stream, {'foo': 'bar'}) + r.xadd(stream, {'foo': 'bar'}) + assert r.xadd(stream, {'foo': 'bar'}, approximate=True, + minid=m1, limit=3) + + # pure minid + r.xadd(stream, {'foo': 'bar'}) + r.xadd(stream, {'foo': 'bar'}) + r.xadd(stream, {'foo': 'bar'}) + m4 = r.xadd(stream, {'foo': 'bar'}) + assert r.xadd(stream, {'foo': 'bar'}, approximate=False, minid=m4) + + # minid approximate + r.xadd(stream, {'foo': 'bar'}) + r.xadd(stream, {'foo': 'bar'}) + m3 = r.xadd(stream, {'foo': 'bar'}) + r.xadd(stream, {'foo': 'bar'}) + assert r.xadd(stream, {'foo': 'bar'}, approximate=True, minid=m3) + + @skip_if_server_version_lt('6.2.0') def test_xautoclaim(self, r): stream = 'stream' group = 'group' |