Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete a Redis Stream?

Tags:

redis

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
like image 670
Mike Curtiss Avatar asked Feb 20 '19 20:02

Mike Curtiss


People also ask

How do I clear Redis Streams?

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.

How do I delete a record in Redis?

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.

What is Redis stream?

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.

Are Redis Streams in-memory?

Redis, which stands for Remote Dictionary Server, is a fast, open source, in-memory, key-value data store.


1 Answers

Just use the DEL command:

DEL mystream
like image 95
Mike Curtiss Avatar answered Oct 07 '22 12:10

Mike Curtiss