Generic

PEXPIRE

Sets a timeout on key. After the timeout has expired, the key will automatically be deleted.

Arguments

keybodystrrequired

The key to expire.

milliseconds | datetime.timedeltabodyintrequired

The timeout in milliseconds as int or datetime.timedelta

nxbodybool

Set expiry only when the key has no expiry

xxbodybool

Set expiry only when the key has an existing expiry

gtbodybool

Set expiry only when the new expiry is greater than current one

ltbodybool

Set expiry only when the new expiry is less than current one

Response

bool

True if the timeout was set

Example
# With millisecondsredis.set("mykey", "Hello")redis.expire("mykey", 500)# With a timedeltaredis.set("mykey", "Hello")redis.expire("mykey", datetime.timedelta(milliseconds=500))
Loading search…