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

xgroup_createconsumer #1553

Merged
merged 1 commit into from
Aug 30, 2021
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
12 changes: 12 additions & 0 deletions redis/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1807,6 +1807,18 @@ def xgroup_destroy(self, name, groupname):
"""
return self.execute_command('XGROUP DESTROY', name, groupname)

def xgroup_createconsumer(self, name, groupname, consumername):
"""
Consumers in a consumer group are auto-created every time a new
consumer name is mentioned by some command.
They can be explicitly created by using this command.
name: name of the stream.
groupname: name of the consumer group.
consumername: name of consumer to create.
"""
return self.execute_command('XGROUP CREATECONSUMER', name, groupname,
consumername)

def xgroup_setid(self, name, groupname, id):
"""
Set the consumer group last delivered ID to something else.
Expand Down
16 changes: 16 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2598,6 +2598,22 @@ def test_xgroup_delconsumer(self, r):
# deleting the consumer should return 2 pending messages
assert r.xgroup_delconsumer(stream, group, consumer) == 2

@skip_if_server_version_lt('6.2.0')
def test_xgroup_createconsumer(self, r):
stream = 'stream'
group = 'group'
consumer = 'consumer'
r.xadd(stream, {'foo': 'bar'})
r.xadd(stream, {'foo': 'bar'})
r.xgroup_create(stream, group, 0)
assert r.xgroup_createconsumer(stream, group, consumer) == 1

# read all messages from the group
r.xreadgroup(group, consumer, streams={stream: '>'})

# deleting the consumer should return 2 pending messages
assert r.xgroup_delconsumer(stream, group, consumer) == 2

@skip_if_server_version_lt('5.0.0')
def test_xgroup_destroy(self, r):
stream = 'stream'
Expand Down