I've created a Redis stream:
XADD mystream * foo bar
And I've associated it with a consumer group:
XGROUP CREATE mystream mygroup $
Now I want to delete it, so that Redis acts as though the stream had never existed. How do I delete it?
I've tried using XTRIM:
XTRIM mystream MAXLEN 0
This successfully puts the length of the stream to zero. But it doesn't fully delete the stream, as attempts to XREADGROUP
still succeed and do not return the typical error when this method is called without the group existing:
XREADGROUP GROUP mygroup myconsumer COUNT 1 STREAMS mystream >
Actual output:
(nil)
Expected output:
NOGROUP No such key 'mystream' or consumer group 'mygroup' in XREADGROUP with GROUP option
Redis Commands There are two major commands to delete the keys present in Redis: FLUSHDB and FLUSHALL. We can use the Redis CLI to execute these commands. The FLUSHDB command deletes the keys in a database. And the FLUSHALL command deletes all keys in all databases.
Deleting Keys Deleting a key in Redis is as simple as creating one. We use the DEL command followed by the name of the key we wish to remove. Redis will drop the key and its associated data if the specified key exists in the data store.
Conceptually, a Stream in Redis is a list where you can append entries. Each entry has a unique ID and a value. The ID is auto-generated by default, and it includes a timestamp. The value is a hash. You can query ranges or use blocking commands to read entries as they come.
Redis, which stands for Remote Dictionary Server, is a fast, open source, in-memory, key-value data store.
Just use the DEL command:
DEL mystream
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With