HSETEX

语法
HSETEX key [FNX | FXX] [EX seconds | PX milliseconds |
  EXAT unix-time-seconds | PXAT unix-time-milliseconds | KEEPTTL]
  FIELDS numfields field value [field value ...]
可用版本
Redis 开源版 8.0.0
时间复杂度
O(N),其中 N 是要设置的字段数量。
ACL 类别
@write, @hash, @fast,

设置给定哈希键的一个或多个字段的值,并可选地设置它们的过期时间或生存时间 (TTL)。

选项

HGETEX 命令支持一组选项

  • 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

RESP2/RESP3 回复

以下之一


评价此页面
返回顶部 ↑