设置给定哈希键的一个或多个字段的值,并可选择设置其过期时间或存活时间(TTL)。如果给定键已持有值,它将被覆盖,并且与键关联的任何先前 TTL 将被丢弃。
*选项
HSETEX 命令支持一组选项:
FNX-- 仅当所有字段都不存在时才设置字段。FXX-- 仅当所有字段都已存在时才设置字段。EX seconds-- 设置指定的过期时间(秒)。PX milliseconds-- 设置指定的过期时间(毫秒)。EXAT unix-time-seconds-- 设置字段将过期的指定 Unix 时间(秒)。PXAT unix-time-milliseconds-- 设置字段将过期的指定 Unix 时间(毫秒)。KEEPTTL-- 保留与字段关联的 TTL。
EX、PX、EXAT、PXAT 和 KEEPTTL 选项互斥。
*示例
redis> HSETEX mykey EXAT 1740470400 FIELDS 2 field1 "Hello" field2 "World"
(integer) 1
redis> HTTL mykey FIELDS 2 field1 field2
1) (integer) 55627
2) (integer) 55627
redis> HSETEX mykey FNX EX 60 FIELDS 2 field1 "Hello" field2 "World"
(integer) 0
redis> HSETEX mykey FXX EX 60 KEEPTTL FIELDS 2 field1 "hello" field2 "world"
(error) ERR Only one of EX, PX, EXAT, PXAT or KEEPTTL arguments can be specified
redis> HSETEX mykey FXX KEEPTTL FIELDS 2 field1 "hello" field2 "world"
(integer) 1
redis> HTTL mykey FIELDS 2 field1 field2
1) (integer) 55481
2) (integer) 55481