HPEXPIRE
HPEXPIRE key milliseconds [NX | XX | GT | LT] FIELDS numfields field [field ...]
hpexpire(
name: KeyT,
milliseconds: ExpiryT,
*fields: str,
nx: bool = False,
xx: bool = False,
gt: bool = False,
lt: bool = False
) → ResponseT
Possible errors
- ERR wrong number of arguments:
ResponseError
See Redis error messages for what each error means. Other errors, such as connection errors, aren't listed.
HPEXPIRE(
key: RedisArgument,
fields: RedisVariadicArgument,
ms: number,
mode?: 'NX' | 'XX' | 'GT' | 'LT'
) → Any
Possible errors
- ERR wrong number of arguments:
SimpleError
See Redis error messages for what each error means. Other errors, such as connection errors, aren't listed.
hpexpire(
key: byte[],
milliseconds: long,
fields: byte[]...
) → List<Long>
hpexpire(
key: byte[],
milliseconds: long,
condition: ExpiryOption,
fields: byte[]...
) → List<Long>
hpexpire(
key: String,
milliseconds: long,
fields: String...
) → List<Long>
hpexpire(
key: String,
milliseconds: long,
condition: ExpiryOption,
fields: String...
) → List<Long>
Possible errors
- ERR wrong number of arguments:
JedisDataException
See Redis error messages for what each error means. Other errors, such as connection errors, aren't listed.
hpexpire(
key: K, // the key.
milliseconds: long, // the milliseconds.
fields: K... // one or more fields to set the TTL for.
) → List<Long> // a list of Long values for each of the fields provided: 2 indicating the specific field is deleted already due to expiration, or provided expiry interval is 0; 1 indicating expiration time is set/updated; 0 indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not met); -2 indicating there is no such field @since 6.4
hpexpire(
key: K, // the key.
milliseconds: long, // the milliseconds.
expireArgs: ExpireArgs, // the expiry arguments.
fields: K... // one or more fields to set the TTL for.
) → List<Long> // a list of Long values for each of the fields provided: 2 indicating the specific field is deleted already due to expiration, or provided expiry interval is 0; 1 indicating expiration time is set/updated; 0 indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not met); -2 indicating there is no such field @since 6.4
hpexpire(
key: K, // the key.
milliseconds: Duration, // the milliseconds.
fields: K... // one or more fields to set the TTL for.
) → List<Long> // a list of Long values for each of the fields provided: 2 indicating the specific field is deleted already due to expiration, or provided expiry interval is 0; 1 indicating expiration time is set/updated; 0 indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not met); -2 indicating there is no such field @since 6.4
hpexpire(
key: K, // the key.
milliseconds: Duration, // the milliseconds.
expireArgs: ExpireArgs, // the expiry arguments.
fields: K... // one or more fields to set the TTL for.
) → List<Long> // a list of Long values for each of the fields provided: 2 indicating the specific field is deleted already due to expiration, or provided expiry interval is 0; 1 indicating expiration time is set/updated; 0 indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not met); -2 indicating there is no such field @since 6.4
Possible errors
- ERR wrong number of arguments:
RedisCommandExecutionException
See Redis error messages for what each error means. Other errors, such as connection errors, aren't listed.
hpexpire(
key: K, // the key.
milliseconds: long, // the milliseconds.
fields: K... // one or more fields to set the TTL for.
) → RedisFuture<List<Long>> // a list of Long values for each of the fields provided: 2 indicating the specific field is deleted already due to expiration, or provided expiry interval is 0; 1 indicating expiration time is set/updated; 0 indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not met); -2 indicating there is no such field @since 6.4
hpexpire(
key: K, // the key.
milliseconds: long, // the milliseconds.
expireArgs: ExpireArgs, // the expiry arguments.
fields: K... // one or more fields to set the TTL for.
) → RedisFuture<List<Long>> // a list of Long values for each of the fields provided: 2 indicating the specific field is deleted already due to expiration, or provided expiry interval is 0; 1 indicating expiration time is set/updated; 0 indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not met); -2 indicating there is no such field @since 6.4
hpexpire(
key: K, // the key.
milliseconds: Duration, // the milliseconds.
fields: K... // one or more fields to set the TTL for.
) → RedisFuture<List<Long>> // a list of Long values for each of the fields provided: 2 indicating the specific field is deleted already due to expiration, or provided expiry interval is 0; 1 indicating expiration time is set/updated; 0 indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not met); -2 indicating there is no such field @since 6.4
hpexpire(
key: K, // the key.
milliseconds: Duration, // the milliseconds.
expireArgs: ExpireArgs, // the expiry arguments.
fields: K... // one or more fields to set the TTL for.
) → RedisFuture<List<Long>> // a list of Long values for each of the fields provided: 2 indicating the specific field is deleted already due to expiration, or provided expiry interval is 0; 1 indicating expiration time is set/updated; 0 indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not met); -2 indicating there is no such field @since 6.4
Possible errors
- ERR wrong number of arguments:
RedisCommandExecutionException
See Redis error messages for what each error means. Other errors, such as connection errors, aren't listed.
hpexpire(
key: K, // the key.
milliseconds: long, // the milliseconds.
fields: K... // one or more fields to set the TTL for.
) → Flux<Long> // a list of Long values for each of the fields provided: 2 indicating the specific field is deleted already due to expiration, or provided expiry interval is 0; 1 indicating expiration time is set/updated; 0 indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not met); -2 indicating there is no such field @since 6.4
hpexpire(
key: K, // the key.
milliseconds: long, // the milliseconds.
expireArgs: ExpireArgs, // the expiry arguments.
fields: K... // one or more fields to set the TTL for.
) → Flux<Long> // a list of Long values for each of the fields provided: 2 indicating the specific field is deleted already due to expiration, or provided expiry interval is 0; 1 indicating expiration time is set/updated; 0 indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not met); -2 indicating there is no such field @since 6.4
hpexpire(
key: K, // the key.
milliseconds: Duration, // the milliseconds.
fields: K... // one or more fields to set the TTL for.
) → Flux<Long> // a list of Long values for each of the fields provided: 2 indicating the specific field is deleted already due to expiration, or provided expiry interval is 0; 1 indicating expiration time is set/updated; 0 indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not met); -2 indicating there is no such field @since 6.4
hpexpire(
key: K, // the key.
milliseconds: Duration, // the milliseconds.
expireArgs: ExpireArgs, // the expiry arguments.
fields: K... // one or more fields to set the TTL for.
) → Flux<Long> // a list of Long values for each of the fields provided: 2 indicating the specific field is deleted already due to expiration, or provided expiry interval is 0; 1 indicating expiration time is set/updated; 0 indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not met); -2 indicating there is no such field @since 6.4
Possible errors
- ERR wrong number of arguments:
RedisCommandExecutionException
See Redis error messages for what each error means. Other errors, such as connection errors, aren't listed.
HPExpire(
ctx: context.Context,
key: string,
expiration: time.Duration,
fields: ...string
) → *IntSliceCmd
Possible errors
- ERR wrong number of arguments:
redis.Error
See Redis error messages for what each error means. Other errors, such as connection errors, aren't listed.
HashFieldExpire(
key: RedisKey, // The key of the hash.
hashFields: RedisValue[], // The fields in the hash to set expire time.
expiry: TimeSpan, // The exact date to expiry to set.
when: ExpireWhen, // under which condition the expiration will be set using ExpireWhen.
flags: CommandFlags // The flags to use for this operation.
) → ExpireResult[] // Empty array if the key does not exist. Otherwise, returns an array where each item is the result of operation for given fields: <list type="table"> <listheader> <term>Result</term> <description>Description</description> </listheader> <item> <term>2</term> <description>Field deleted because the specified expiration time is due.</description> </item> <item> <term>1</term> <description>Expiration time set/updated.</description> </item> <item> <term>0</term> <description>Expiration time is not set/update (a specified ExpireWhen condition is not met).</description> </item> <item> <term>-1</term> <description>No such field exists.</description> </item> </list>
HashFieldExpire(
key: RedisKey, // The key of the hash.
hashFields: RedisValue[], // The fields in the hash to set expire time.
expiry: DateTime, // The exact date to expiry to set.
when: ExpireWhen, // under which condition the expiration will be set using ExpireWhen.
flags: CommandFlags // The flags to use for this operation.
) → ExpireResult[] // Empty array if the key does not exist. Otherwise, returns an array where each item is the result of operation for given fields: <list type="table"> <listheader> <term>Result</term> <description>Description</description> </listheader> <item> <term>2</term> <description>Field deleted because the specified expiration time is due.</description> </item> <item> <term>1</term> <description>Expiration time set/updated.</description> </item> <item> <term>0</term> <description>Expiration time is not set/update (a specified ExpireWhen condition is not met).</description> </item> <item> <term>-1</term> <description>No such field exists.</description> </item> </list>
HashFieldExpire(
key: RedisKey, // The key of the hash.
hashFields: RedisValue[], // The fields in the hash to set expire time.
expiry: TimeSpan, // The exact date to expiry to set.
when: ExpireWhen, // under which condition the expiration will be set using ExpireWhen.
flags: CommandFlags // The flags to use for this operation.
) → ExpireResult[] // Empty array if the key does not exist. Otherwise, returns an array where each item is the result of operation for given fields: <list type="table"> <listheader> <term>Result</term> <description>Description</description> </listheader> <item> <term>2</term> <description>Field deleted because the specified expiration time is due.</description> </item> <item> <term>1</term> <description>Expiration time set/updated.</description> </item> <item> <term>0</term> <description>Expiration time is not set/update (a specified ExpireWhen condition is not met).</description> </item> <item> <term>-1</term> <description>No such field exists.</description> </item> </list>
HashFieldExpire(
key: RedisKey, // The key of the hash.
hashFields: RedisValue[], // The fields in the hash to set expire time.
expiry: DateTime, // The exact date to expiry to set.
when: ExpireWhen, // under which condition the expiration will be set using ExpireWhen.
flags: CommandFlags // The flags to use for this operation.
) → ExpireResult[] // Empty array if the key does not exist. Otherwise, returns an array where each item is the result of operation for given fields: <list type="table"> <listheader> <term>Result</term> <description>Description</description> </listheader> <item> <term>2</term> <description>Field deleted because the specified expiration time is due.</description> </item> <item> <term>1</term> <description>Expiration time set/updated.</description> </item> <item> <term>0</term> <description>Expiration time is not set/update (a specified ExpireWhen condition is not met).</description> </item> <item> <term>-1</term> <description>No such field exists.</description> </item> </list>
Possible errors
- ERR wrong number of arguments:
RedisServerException
See Redis error messages for what each error means. Other errors, such as connection errors, aren't listed.
HashFieldExpireAsync(
key: RedisKey, // The key of the hash.
hashFields: RedisValue[], // The fields in the hash to set expire time.
expiry: TimeSpan, // The exact date to expiry to set.
when: ExpireWhen, // under which condition the expiration will be set using ExpireWhen.
flags: CommandFlags // The flags to use for this operation.
) → Task<ExpireResult[]> // Empty array if the key does not exist. Otherwise, returns an array where each item is the result of operation for given fields: <list type="table"> <listheader> <term>Result</term> <description>Description</description> </listheader> <item> <term>2</term> <description>Field deleted because the specified expiration time is due.</description> </item> <item> <term>1</term> <description>Expiration time set/updated.</description> </item> <item> <term>0</term> <description>Expiration time is not set/update (a specified ExpireWhen condition is not met).</description> </item> <item> <term>-1</term> <description>No such field exists.</description> </item> </list>
HashFieldExpireAsync(
key: RedisKey, // The key of the hash.
hashFields: RedisValue[], // The fields in the hash to set expire time.
expiry: DateTime, // The exact date to expiry to set.
when: ExpireWhen, // under which condition the expiration will be set using ExpireWhen.
flags: CommandFlags // The flags to use for this operation.
) → Task<ExpireResult[]> // Empty array if the key does not exist. Otherwise, returns an array where each item is the result of operation for given fields: <list type="table"> <listheader> <term>Result</term> <description>Description</description> </listheader> <item> <term>2</term> <description>Field deleted because the specified expiration time is due.</description> </item> <item> <term>1</term> <description>Expiration time set/updated.</description> </item> <item> <term>0</term> <description>Expiration time is not set/update (a specified ExpireWhen condition is not met).</description> </item> <item> <term>-1</term> <description>No such field exists.</description> </item> </list>
HashFieldExpireAsync(
key: RedisKey, // The key of the hash.
hashFields: RedisValue[], // The fields in the hash to set expire time.
expiry: TimeSpan, // The exact date to expiry to set.
when: ExpireWhen, // under which condition the expiration will be set using ExpireWhen.
flags: CommandFlags // The flags to use for this operation.
) → Task<ExpireResult[]> // Empty array if the key does not exist. Otherwise, returns an array where each item is the result of operation for given fields: <list type="table"> <listheader> <term>Result</term> <description>Description</description> </listheader> <item> <term>2</term> <description>Field deleted because the specified expiration time is due.</description> </item> <item> <term>1</term> <description>Expiration time set/updated.</description> </item> <item> <term>0</term> <description>Expiration time is not set/update (a specified ExpireWhen condition is not met).</description> </item> <item> <term>-1</term> <description>No such field exists.</description> </item> </list>
HashFieldExpireAsync(
key: RedisKey, // The key of the hash.
hashFields: RedisValue[], // The fields in the hash to set expire time.
expiry: DateTime, // The exact date to expiry to set.
when: ExpireWhen, // under which condition the expiration will be set using ExpireWhen.
flags: CommandFlags // The flags to use for this operation.
) → Task<ExpireResult[]> // Empty array if the key does not exist. Otherwise, returns an array where each item is the result of operation for given fields: <list type="table"> <listheader> <term>Result</term> <description>Description</description> </listheader> <item> <term>2</term> <description>Field deleted because the specified expiration time is due.</description> </item> <item> <term>1</term> <description>Expiration time set/updated.</description> </item> <item> <term>0</term> <description>Expiration time is not set/update (a specified ExpireWhen condition is not met).</description> </item> <item> <term>-1</term> <description>No such field exists.</description> </item> </list>
Possible errors
- ERR wrong number of arguments:
RedisServerException
See Redis error messages for what each error means. Other errors, such as connection errors, aren't listed.
hpexpire(
$key: string,
$milliseconds: int,
$fields: array,
string $flag = null: Any
) → array|null
Possible errors
- ERR wrong number of arguments:
Predis\Response\ServerException
See Redis error messages for what each error means. Other errors, such as connection errors, aren't listed.
hpexpire(
key: K,
milliseconds: i64,
opt: ExpireOption,
fields: F
) → (Vec<IntegerReplyOrNoOp>)
hpexpire_at(
key: K,
ts: i64,
opt: ExpireOption,
fields: F
) → (Vec<IntegerReplyOrNoOp>)
Possible errors
- ERR wrong number of arguments:
ErrorKind::Server(ServerErrorKind::ResponseError)
See Redis error messages for what each error means. Other errors, such as connection errors, aren't listed.
hpexpire(
key: K,
milliseconds: i64,
opt: ExpireOption,
fields: F
) → (Vec<IntegerReplyOrNoOp>)
hpexpire_at(
key: K,
ts: i64,
opt: ExpireOption,
fields: F
) → (Vec<IntegerReplyOrNoOp>)
Possible errors
- ERR wrong number of arguments:
ErrorKind::Server(ServerErrorKind::ResponseError)
See Redis error messages for what each error means. Other errors, such as connection errors, aren't listed.
- Available since:
- Redis Open Source 7.4.0
- Time complexity:
- O(N) where N is the number of specified fields
- ACL categories:
-
@write,@hash,@fast, - Compatibility:
- Redis Software and Redis Cloud compatibility
This command works like HEXPIRE, but the expiration of a field is
specified in milliseconds instead of seconds.
Required arguments
key
The name of the key that holds the hash.
milliseconds
The timeout, in milliseconds.
FIELDS numfields field [field ...]
The hash fields to operate on. numfields is the number of fields, followed by that many field names.
Optional arguments
The following options modify the command's behavior. They are mutually exclusive.
NX
For each specified field, set expiration only when the field has no expiration.
XX
For each specified field, set expiration only when the field has an existing expiration.
GT
For each specified field, set expiration only when the new expiration is greater than the current one. A non-volatile key is treated as an infinite TTL for the purposes of GT.
LT
For each specified field, set expiration only when the new expiration is less than the current one. A non-volatile key is treated as an infinite TTL for the purposes of LT.
Examples
redis> HSET mykey field1 "hello" field2 "world"
(integer) 2
redis> HPEXPIRE mykey 2000 FIELDS 2 field1 field2
1) (integer) 1
2) (integer) 1
redis> HGETALL mykey
(empty array)
Redis Software and Redis Cloud compatibility
| Redis Software |
Redis Cloud |
Notes |
|---|---|---|
| ✅ Standard |
✅ Standard |
Return information
One of the following:
- Array reply. For each field:
- Integer reply:
-2if no such field exists in the provided hash key, or the provided key does not exist. - Integer reply:
0if the specified NX, XX, GT, or LT condition has not been met. - Integer reply:
1if the expiration time was set/updated. - Integer reply:
2whenHEXPIREorHPEXPIREis called with 0 seconds or milliseconds, or whenHEXPIREATorHPEXPIREATis called with a past Unix time in seconds or milliseconds.
- Integer reply:
- Simple error reply:
- if parsing failed, mandatory arguments are missing, unknown arguments are specified, or argument values are of the wrong type or out of range.
- if the provided key exists but is not a hash.
One of the following:
- Array reply. For each field:
- Integer reply:
-2if no such field exists in the provided hash key, or the provided key does not exist. - Integer reply:
0if the specified NX, XX, GT, or LT condition has not been met. - Integer reply:
1if the expiration time was set/updated. - Integer reply:
2whenHEXPIREorHPEXPIREis called with 0 seconds or milliseconds, or whenHEXPIREATorHPEXPIREATis called with a past Unix time in seconds or milliseconds.
- Integer reply:
- Simple error reply:
- if parsing failed, mandatory arguments are missing, unknown arguments are specified, or argument values are of the wrong type or out of range.
- if the provided key exists but is not a hash.