I'm working on adding streams support to aioredis. It appears that using XGROUP CREATE with stream key that does not exist results in an ERR no such key.
I propose that either:
XGROUP CREATEshould create the key if it does not exist, or- There should be way to create an empty stream without having to use
XADD(which, AFAIK, there is not right now)
Reason
In the library I am creating it is quite possible that a process will wish to listen on a stream before the stream has received any messages. This is because the process reasonably expects a message to appear in the future.
From what I can see the current implementation does not support this. A somewhat cumbersome workaround would be to add a noop message to the stream.
Thank you for all the excellent work on streams, I'm really looking forward to the release.
Comment From: mp911de
Same here. Would be good to either implicitly create a key with XGROUP CREATE.
Creating an empty stream (Via a XADD for an empty stream) contradicts somewhat with Redis notion of empty/absence. Empty lists/sets are not listed via KEYS/SCAN.
Looking from an ops perspective, group creation could be a task done by operators which are not necessarily involved in stream/message creation.
Comment From: dremekie
Agreed. The ability to create an empty stream (#4833) would be great.
Comment From: 0xtonyxia
Hi @antirez , please spare your time checking this issue and related PR if it's reasonable to support creating an empty stream directly using xadd command. Thanks.
Comment From: MaerF0x0
It looks like you cannot do an empty XADD, but you could use a sentry value like:
XADD mystream * messageType sentry
And then just ignore sentry messages in the consumers.
Its a bit messier than adding XCREATE
Comment From: hlavacek
Hi, when you try the XGROUP CREATE command inside the redis cli on nonexisting stream, it will actually give you a hint that you can use MKSTREAM option to create the stream:
redis:6379> XGROUP CREATE tst tst_group $
(error) ERR The XGROUP subcommand requires the key to exist. Note that for CREATE you may want to use the MKSTREAM option to create an empty stream automatically.
redis:6379> XGROUP CREATE tst tst_group $ MKSTREAM
OK
Comment From: itamarhaber
Indeed - the MKSTREAM option was introduced just before GA and is currently not documented (https://github.com/antirez/redis-doc/issues/1007).
Comment From: itamarhaber
@adamcharnock @antirez - this can be closed imo.