Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent Redis stream memory increases infinitely?

I just realized that the XACK do not auto delete message when only one consumer group exist.

I thought that when all consumer groups ack the same message, the message will be deleted by Redis-server, but seemed that this is not the case.

So, the Redis stream memory increases infinitely because of no messages will be deleted.

Maybe the only way to preventing this is manually XDEL message? But how can I know all consumer groups have acked the message?

Need some help, thanks!

like image 588
UNSTABLE Avatar asked Feb 28 '20 10:02

UNSTABLE


People also ask

How can I reduce my memory use in Redis?

In this chapter, we’ll cover three important methods to help reduce your memory use in Redis. By reducing the amount of memory you use in Redis, you can reduce the time it takes to create or load a snapshot, rewrite or load an append-only file, reduce slave synchronization time, 1 and store more data in Redis without additional hardware.

What is Redis Stream data type?

The Redis stream data type was introduced in Redis 5.0. Streams model a log data structure but also implement several operations to overcome some of the limits of a typical append-only log. These include random access in O (1) time and complex consumption strategies, such as consumer groups. Streams are an append-only data structure.

What is the best way to store data in Redis?

Using something like JSON or Protobuf is often a good idea. If the data you're storing is large enough and contains a lot of text you can often reduce memory usage by adding compression. LZO or Snappy are good options for this use case. Many times you don't need to store all the data in Redis.

Why did Stream-Framework move from Redis to Cassandra?

Most of Stream-Framework 's users start out with Redis and eventually move to Cassandra because Redis becomes too expensive to host. Stream, our hosted API for building scalable newsfeeds & activity streams is also based on Cassandra. There are quite a few things you can do to reduce Redis' memory usage though.


1 Answers

Redis streams are primarily an append-only data structure. It's possible to remove an entry using the XDEL command, however that doesn't necessarily free up the memory used by the entry:

> XDEL mystream 1538561700640-0
(integer) 1

You could also cap the stream with an arbitrary threshold using the MAXLEN option to XADD or use the XTRIM command explicitly:

> XADD mystream MAXLEN 1000 * value 1
1526654998691-0
...
> XLEN mystream
(integer) 1000

But how can I know all consumer groups have acked the message?

You can inspect the list of pending messages for each consumer group using the XPENDING command:

> XPENDING mystream mygroup
1) (integer) 1
2) 1526984818136-0
3) 1526984818136-0
4) 1) 1) "consumer-1"
      2) "1"
like image 182
Eugene Yarmash Avatar answered Sep 18 '22 15:09

Eugene Yarmash