How to set a key with Expiry using redisgo Api

467 Views Asked by At

How use below Redis command in GoLang using redisgo.

127.0.0.1:6379> set hello 1 EX 10 
OK
127.0.0.1:6379>

I have tried using below,

_, err = conn.Do("EXPIRE", key, ttl)

Is there any way to set ttl, when setting the key?

1

There are 1 best solutions below

1
On BEST ANSWER

conn.Do("SETEX", "mykey", time, value) Ex. conn.Do("SETEX", "mykey", 600, value)