set

英[set] 美[sɛt]

vt. Set; place, arrange; put in a certain situation; place tableware

vi. Setting off; setting off; condensation

n.Gathering; a set; a set; a TV set

adj. Fixed; located in...; stubborn; arranged The

third person singular: sets plural: sets present participle: setting past tense: set past participle: set

redis SETEX command syntax

Function:Associate the value value to key and set the key's survival time to seconds (in seconds). If key already exists, the SETEX command will overwrite the old value.

Syntax: SETEX key seconds value

Description: SETEX is an atomic operation, with two associated values ​​and set survival time The action will be completed at the same time. This command is very useful when Redis is used as a cache.

Available versions: >= 2.0.0

Time complexity: O(1)

Return: Return OK when setting is successful. When the seconds parameter is illegal, an error is returned.

redis SETEX command example

# 在 key 不存在时进行 SETEX
redis> SETEX cache_user_id 60 10086
OK
redis> GET cache_user_id  # 值
"10086"
redis> TTL cache_user_id  # 剩余生存时间
(integer) 49
# key 已经存在时,SETEX 覆盖旧值
redis> SET cd "timeless"
OK
redis> SETEX cd 3000 "goodbye my love"
OK
redis> GET cd
"goodbye my love"
redis> TTL cd
(integer) 2997