@@ -22,13 +22,14 @@ import (
2222var sampleConfig string
2323
2424type RedisTimeSeries struct {
25- Address string `toml:"address"`
26- Username config.Secret `toml:"username"`
27- Password config.Secret `toml:"password"`
28- Database int `toml:"database"`
29- ConvertStringFields bool `toml:"convert_string_fields"`
30- Timeout config.Duration `toml:"timeout"`
31- Log telegraf.Logger `toml:"-"`
25+ Address string `toml:"address"`
26+ Username config.Secret `toml:"username"`
27+ Password config.Secret `toml:"password"`
28+ Database int `toml:"database"`
29+ ConvertStringFields bool `toml:"convert_string_fields"`
30+ Timeout config.Duration `toml:"timeout"`
31+ Expire * config.Duration `toml:"expire"`
32+ Log telegraf.Logger `toml:"-"`
3233 tls.ClientConfig
3334 client * redis.Client
3435}
@@ -104,8 +105,14 @@ func (r *RedisTimeSeries) Write(metrics []telegraf.Metric) error {
104105 }
105106 }
106107
107- resp := r .client .TSAddWithArgs (ctx , key , m .Time ().UnixMilli (), value , & redis.TSOptions {Labels : m .Tags ()})
108- if err := resp .Err (); err != nil {
108+ var err error
109+ pipe := r .client .Pipeline ()
110+ pipe .TSAddWithArgs (ctx , key , m .Time ().UnixMilli (), value , & redis.TSOptions {Labels : m .Tags ()})
111+ if r .Expire != nil {
112+ pipe .Expire (ctx , key , time .Duration (* r .Expire ))
113+ }
114+ _ , err = pipe .Exec (ctx )
115+ if err != nil {
109116 return fmt .Errorf ("adding sample %q failed: %w" , key , err )
110117 }
111118 }
0 commit comments