Introduction
Sometimes you want to keep a key forever in Redis without it disappearing after a set time. PERSIST helps by removing any expiration time from a key.
PERSIST key
PERSIST mykey
PERSIST session123
SET tempkey "hello" EXPIRE tempkey 10 TTL tempkey PERSIST tempkey TTL tempkey
PERSIST key do?session123?PERSIST key. So for key 'session123', it is PERSIST session123.SET mykey "hello" EXPIRE mykey 10 TTL mykey PERSIST mykey TTL mykey
TTL commands?PERSIST mykey but it returns 0. What is the most likely reason?cache:item with an expiry of 30 seconds. You want to keep it permanently only if its current TTL is more than 10 seconds. Which sequence of commands achieves this safely?TTL cache:item to get remaining expiry time in seconds.PERSIST cache:item to remove expiry and keep key permanently.Pass the test and this pattern moves unknown