-1

I'm using Redis to store json messages, which need to be consumed by other services. I want the data to store in Redis for 2 days and the data need to be deleted after the 2 days.

Is there any approach to achieve it?

James Z
  • 12,209
  • 10
  • 24
  • 44

2 Answers2

0

You can set a timeout on key using the EXPIRE command. See the doc for details.

jellycsc
  • 10,904
  • 2
  • 15
  • 32
0

Assuming that you are storing the data in a String—which is likely if you're using ElastiCache—you can SET the value and EXPIRE it in a single command:

SETEX foo 172800 value
Guy Royse
  • 2,739
  • 12
  • 9