w3resource

Redis String: PSETEX key milliseconds value

Redis PSETEX Command

Redis PSETEX command is used to set the value of key, with the expiration of time in milliseconds instead of seconds.

Here are some common uses and scenarios for the "PSETEX" command:

  • Cache Management: Store values with a precise expiration time for efficient caching.
  • Session Handling: Manage temporary session data with millisecond-level timeouts.
  • Timeouts: Implement time-based locks or operation timeouts.
  • Data Cleanup: Automatically remove temporary data after a specific duration.
  • Transient Data: Store data temporarily without manually managing TTL separately.

Syntax:

Basic syntax of redis PSETEX command is shown below:

redis 127.0.0.1:6379> PSETEX key1 EXPIRY_IN_MILLISECONDS value1

Available since

2.6.0.

Return Value

Simple string reply OK

Return Value Type

String

Example:

redis 127.0.0.1:6379> PSETEX mykey 1000 "Hello"
OK
redis 127.0.0.1:6379> PTTL mykey
999
redis 127.0.0.1:6379> GET mykey
1) "Hello"

Previous: MSETNX
Next: INCR



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/redis/redis-psetex-key-milliseconds-value.php