SET with EX allows you to set a TTL (time to live) value for key otp.
TTL otp checks the remaining seconds.
PERSIST otp removes the expiration. If it returns -1, it means there’s no TTL.
EXPIRE otp 30 sets a 30s TTL.
127.0.0.1:6379> SET otp 123456 EX 15
OK
127.0.0.1:6379> TTL otp
(integer) 13
127.0.0.1:6379> PERSIST otp
(integer) 1
127.0.0.1:6379> TTL otp
(integer) -1
127.0.0.1:6379> EXPIRE otp 30
(integer) 1
127.0.0.1:6379> TTL otp
(integer) 29
127.0.0.1:6379>