# Logstash Redis Output - Expire Keys?

**URL:** <https://discuss.elastic.co/t/logstash-redis-output-expire-keys/172020>\
**Category:** Logstash\
**Created:** [March 12, 2019, 6:08pm UTC](https://discuss.elastic.co/t/logstash-redis-output-expire-keys/172020 "2019-03-12T18:08:38Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![titan1978](https://avatars.discourse-cdn.com/v4/letter/t/c37758/32.png) [@titan1978](https://discuss.elastic.co/u/titan1978)\
**Post date:** [March 12, 2019, 6:08pm UTC](https://discuss.elastic.co/t/logstash-redis-output-expire-keys/172020/1 "2019-03-12T18:08:38Z")

</div>

We are building a Redis output configuration that pushes a large stack of data to Redis. The volume is so large that we want to set an EXPIRY for each key that is pushed to Redis. This is very important from both costs and maintanence perspective. I could not locate a setting in Logstash (6.4) on how I can do this.

Can someone point on how I can achieve this?

---

<div class="post-metadata">

**Author:** ![pjanzen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pjanzen/32/13756_2.png) [@pjanzen](https://discuss.elastic.co/u/pjanzen)\
**Post date:** [March 12, 2019, 6:56pm UTC](https://discuss.elastic.co/t/logstash-redis-output-expire-keys/172020/2 "2019-03-12T18:56:36Z")

</div>

The redis output plugin doesn't support this option and redis doesn't either. So I would say create a feature request.. I don's see any option to set a ttl on a key...

(to be complete)  
redis does not support a default TTL on a db key set via a config file. of course it support the TTL on a per key basis..

---

<div class="post-metadata">

**Author:** ![titan1978](https://avatars.discourse-cdn.com/v4/letter/t/c37758/32.png) [@titan1978](https://discuss.elastic.co/u/titan1978)\
**Post date:** [March 12, 2019, 7:02pm UTC](https://discuss.elastic.co/t/logstash-redis-output-expire-keys/172020/3 "2019-03-12T19:02:53Z")

</div>

yep Redis does support on a per-key basis. The scenario we're looking is pretty much like this - We're looking to expire ALL Keys over X days old (can be done on Redis) :

> RPUSH somekey 12345 9999  
> EXPIRE somekey X

---

<div class="post-metadata">

**Author:** ![pjanzen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pjanzen/32/13756_2.png) [@pjanzen](https://discuss.elastic.co/u/pjanzen)\
**Post date:** [March 12, 2019, 7:12pm UTC](https://discuss.elastic.co/t/logstash-redis-output-expire-keys/172020/4 "2019-03-12T19:12:20Z")

</div>

yeah I don't know how to do that without scan all the keys and update them with a expire setting. But reading your initial post that will be very costly in resources.

---

<div class="post-metadata">

**Author:** ![titan1978](https://avatars.discourse-cdn.com/v4/letter/t/c37758/32.png) [@titan1978](https://discuss.elastic.co/u/titan1978)\
**Post date:** [March 12, 2019, 7:26pm UTC](https://discuss.elastic.co/t/logstash-redis-output-expire-keys/172020/5 "2019-03-12T19:26:50Z")

</div>

shouldn't it be as simple as if there is a config called 'expiry'

> if @config\_expiry:  
> @redis.rpush(key, payload)  
> @redis.expire(key,exipireVal)  
> else:  
> @redis.rpush(key, payload)

---

<div class="post-metadata">

**Author:** ![pjanzen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pjanzen/32/13756_2.png) [@pjanzen](https://discuss.elastic.co/u/pjanzen)\
**Post date:** [March 12, 2019, 7:28pm UTC](https://discuss.elastic.co/t/logstash-redis-output-expire-keys/172020/6 "2019-03-12T19:28:00Z")

</div>

yeah I guess so 🙂

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [March 12, 2019, 7:28pm UTC](https://discuss.elastic.co/t/logstash-redis-output-expire-keys/172020/7 "2019-03-12T19:28:59Z")

</div>

The Redis plugin writes to either a list or a channel, which as far as I know do not support TTL.

---

<div class="post-metadata">

**Author:** ![pjanzen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pjanzen/32/13756_2.png) [@pjanzen](https://discuss.elastic.co/u/pjanzen)\
**Post date:** [March 12, 2019, 7:32pm UTC](https://discuss.elastic.co/t/logstash-redis-output-expire-keys/172020/8 "2019-03-12T19:32:01Z")

</div>

You could always fork the logstash-output-redis on github and extend the code..

> <https://github.com/logstash-plugins/logstash-output-redis/blob/master/lib/logstash/outputs/redis.rb#L217>

---

<div class="post-metadata">

**Author:** ![titan1978](https://avatars.discourse-cdn.com/v4/letter/t/c37758/32.png) [@titan1978](https://discuss.elastic.co/u/titan1978)\
**Post date:** [March 13, 2019, 12:50pm UTC](https://discuss.elastic.co/t/logstash-redis-output-expire-keys/172020/9 "2019-03-13T12:50:37Z")

</div>

yeah that was the exact place i was thinking of doing this. Though It would be preferable to get this as part of an official release? since we'll have to rebuild the plugin each time we upgrade.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 10, 2019, 12:52pm UTC](https://discuss.elastic.co/t/logstash-redis-output-expire-keys/172020/10 "2019-04-10T12:52:20Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
