Skip to content

Conversation

@tezc
Copy link
Collaborator

@tezc tezc commented Feb 11, 2025

This PR adds three new hash commands: HGETDEL, HGETEX and HSETEX. These commands enable user to do multiple operations in one step atomically e.g. set a hash field and update its TTL with a single command. Previously, it was only possible to do it by calling hset and hexpire commands subsequently.

  • HGETDEL command

    HGETDEL <key> FIELDS <numfields> field [field ...]
    

    Description
    Get and delete the value of one or more fields of a given hash key

    Reply
    Array reply: list of the value associated with each field or nil if the field doesn’t exist.

  • HGETEX command

     HGETEX <key>  
       [EX seconds | PX milliseconds | EXAT unix-time-seconds | PXAT unix-time-milliseconds | PERSIST] 
       FIELDS <numfields> field [field ...]
    

    Description
    Get the value of one or more fields of a given hash key, and optionally set their expiration

    Options:
    EX seconds: Set the specified expiration time, in seconds.
    PX milliseconds: Set the specified expiration time, in milliseconds.
    EXAT timestamp-seconds: Set the specified Unix time at which the field will expire, in seconds.
    PXAT timestamp-milliseconds: Set the specified Unix time at which the field will expire, in milliseconds.
    PERSIST: Remove the time to live associated with the field.

    Reply
    Array reply: list of the value associated with each field or nil if the field doesn’t exist.

  • HSETEX command

    HSETEX <key>
       [FNX | FXX]
       [EX seconds | PX milliseconds | EXAT unix-time-seconds | PXAT unix-time-milliseconds | KEEPTTL] 
       FIELDS <numfields> field value [field value...]
    

    Description
    Set the value of one or more fields of a given hash key, and optionally set their expiration

    Options:
    FNX: Only set the fields if all do not already exist.
    FXX: Only set the fields if all already exist.

    EX seconds: Set the specified expiration time, in seconds.
    PX milliseconds: Set the specified expiration time, in milliseconds.
    EXAT timestamp-seconds: Set the specified Unix time at which the field will expire, in seconds.
    PXAT timestamp-milliseconds: Set the specified Unix time at which the field will expire, in milliseconds.
    KEEPTTL: Retain the time to live associated with the field.

    Note: If no option is provided, any associated expiration time will be discarded similar to how SET command behaves.

    Reply
    Integer reply: 0 if no fields were set
    Integer reply: 1 if all the fields were set


Co-authored-by: samanebi ebrahimpoorsalimi.saman@gmail.com

Copy link
Collaborator

@moticless moticless left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just started to review :)

@moticless
Copy link
Collaborator

LGTM. Excellent job!

Copy link
Collaborator

@sundb sundb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only reviewed the code related to notification, LGTM.

@sundb sundb requested a review from ShooterIT February 13, 2025 12:48
@tezc tezc added release-notes indication that this issue needs to be mentioned in the release notes state:needs-doc-pr requires a PR to redis-doc repository labels Feb 13, 2025
@ShooterIT
Copy link
Member

don't read line by line, but generally LGTM

@ShooterIT
Copy link
Member

not related to your PR, from https://github.com/redis/redis/blob/unstable/src/t_hash.c#L3300 there are several commands descriptions miss the FIElDS option word, maybe you can fix in this PR. of course, another PR is OK

@samanebi
Copy link

samanebi commented Apr 22, 2025

isn't it duplicate to #13577 ? my code has conflict with this @sundb

@sundb
Copy link
Collaborator

sundb commented Apr 22, 2025

@samanebi add you as the coauther in the top comment, still thank a lot for your efforts.

@sundb sundb added this to Redis 8.0 Aug 15, 2025
@sundb sundb moved this from Todo to Done in Redis 8.0 Aug 15, 2025
funny-dog pushed a commit to funny-dog/redis that referenced this pull request Sep 17, 2025
This PR adds three new hash commands: HGETDEL, HGETEX and HSETEX. These
commands enable user to do multiple operations in one step atomically
e.g. set a hash field and update its TTL with a single command.
Previously, it was only possible to do it by calling hset and hexpire
commands subsequently.

- **HGETDEL command**

  ```
  HGETDEL <key> FIELDS <numfields> field [field ...]
  ```
  
  **Description**  
  Get and delete the value of one or more fields of a given hash key
  
  **Reply**  
Array reply: list of the value associated with each field or nil if the
field doesn’t exist.

- **HGETEX command**

  ```
   HGETEX <key>  
[EX seconds | PX milliseconds | EXAT unix-time-seconds | PXAT
unix-time-milliseconds | PERSIST]
     FIELDS <numfields> field [field ...]
  ```

  **Description**
Get the value of one or more fields of a given hash key, and optionally
set their expiration

  **Options:**
  EX seconds: Set the specified expiration time, in seconds.
  PX milliseconds: Set the specified expiration time, in milliseconds.
EXAT timestamp-seconds: Set the specified Unix time at which the field
will expire, in seconds.
PXAT timestamp-milliseconds: Set the specified Unix time at which the
field will expire, in milliseconds.
  PERSIST: Remove the time to live associated with the field.

  **Reply** 
Array reply: list of the value associated with each field or nil if the
field doesn’t exist.

- **HSETEX command**

  ```
  HSETEX <key>
     [FNX | FXX]
[EX seconds | PX milliseconds | EXAT unix-time-seconds | PXAT
unix-time-milliseconds | KEEPTTL]
     FIELDS <numfields> field value [field value...]
  ```
  **Description**
Set the value of one or more fields of a given hash key, and optionally
set their expiration

  **Options:**
  FNX: Only set the fields if all do not already exist.
  FXX: Only set the fields if all already exist.

  EX seconds: Set the specified expiration time, in seconds.
  PX milliseconds: Set the specified expiration time, in milliseconds.
EXAT timestamp-seconds: Set the specified Unix time at which the field
will expire, in seconds.
PXAT timestamp-milliseconds: Set the specified Unix time at which the
field will expire, in milliseconds.
  KEEPTTL: Retain the time to live associated with the field.

  
Note: If no option is provided, any associated expiration time will be
discarded similar to how SET command behaves.

  **Reply**
  Integer reply: 0 if no fields were set
  Integer reply: 1 if all the fields were set
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-notes indication that this issue needs to be mentioned in the release notes state:needs-doc-pr requires a PR to redis-doc repository

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants