Redis notifications: Get key and value on expiration

后端 未结 3 458
清酒与你
清酒与你 2021-01-30 14:45

we have the following use case: Every time a certain key expires, we need to get notified and do something, based on it\'s value. But when redis fires the expired e

3条回答
  •  没有蜡笔的小新
    2021-01-30 15:22

    If you're on 2.8, you can try out this new feature (also referenced at this page). It's definitely unstable and doesn't seem well tested, but if you're on 2.8 anyway...

    Short intro from the issue page:

    An interesting feature in databases with a key-value data model (Redis does not perfectly fit this definition as the values are complex data structure, but the outer layer of Redis is definitely a key-value business) is the ability to subscribe in some way to the stream of events targeting a given key.

    For instance I may be interested to see when the key foo is deleted or modified in some way, or to get the names of all the keys with an expire set (using the EXPIRE command) that Redis is evicting from the dataset because their time to live dropped to zero.

    This feature was requested many times by the Redis user base, however so far we never reached a point where the proposed API (including proposals made by myself) seemed to fit well into the Redis design. This feature request will try to describe a new design that is extremely simple to use, to implement, and that fits well in the Redis story.

提交回复
热议问题