Interface RedisHashCommands
- All Known Subinterfaces:
DefaultedRedisClusterConnection,DefaultedRedisConnection,RedisClusterConnection,RedisCommands,RedisConnection,RedisConnectionUtils.RedisConnectionProxy,StringRedisConnection
- All Known Implementing Classes:
AbstractRedisConnection,DefaultStringRedisConnection,JedisClusterConnection,JedisConnection,LettuceClusterConnection,LettuceConnection
public interface RedisHashCommands
Hash-specific commands supported by Redis.
- Author:
- Costin Leau, Christoph Strobl, Mark Paluch, Tihomir Mateev
-
Method Summary
Modifier and TypeMethodDescriptionapplyHashFieldExpiration(byte[] key, Expiration expiration, byte[]... fields) Apply a givenExpirationto the given fields.applyHashFieldExpiration(byte[] key, Expiration expiration, ExpirationOptions options, byte[]... fields) hDel(byte[] key, byte[]... fields) Delete given hashfields.hExists(byte[] key, byte[] field) Determine if given hashfieldexists.hExpire(byte[] key, long seconds, byte[]... fields) Set time to live for givenfieldsin seconds.hExpire(byte[] key, long seconds, ExpirationOptions.Condition condition, byte[]... fields) Set time to live for givenfieldsin seconds.Set time to live for givenfields.hExpireAt(byte[] key, long unixTime, byte[]... fields) Set the expiration for givenfieldas a UNIX timestamp.hExpireAt(byte[] key, long unixTime, ExpirationOptions.Condition condition, byte[]... fields) Set the expiration for givenfieldas a UNIX timestamp.byte[]hGet(byte[] key, byte[] field) Get value for givenfieldfrom hash atkey.Map<byte[],byte[]> hGetAll(byte[] key) Get entire hash stored atkey.hIncrBy(byte[] key, byte[] field, double delta) Incrementvalueof a hashfieldby the givendelta.hIncrBy(byte[] key, byte[] field, long delta) Incrementvalueof a hashfieldby the givendelta.Set<byte[]>hKeys(byte[] key) Get key set (fields) of hash atkey.hLen(byte[] key) Get size of hash atkey.List<byte[]>hMGet(byte[] key, byte[]... fields) Get values for givenfieldsfrom hash atkey.voidSet multiple hash fields to multiple values using data provided inhasheshPersist(byte[] key, byte[]... fields) Remove the expiration from givenfield.hpExpire(byte[] key, long millis, byte[]... fields) Set time to live for givenfieldsin milliseconds.hpExpire(byte[] key, long millis, ExpirationOptions.Condition condition, byte[]... fields) Set time to live for givenfieldsin milliseconds.Set time to live for givenfieldsin milliseconds.hpExpireAt(byte[] key, long unixTimeInMillis, byte[]... fields) Set the expiration for givenfieldas a UNIX timestamp in milliseconds.hpExpireAt(byte[] key, long unixTimeInMillis, ExpirationOptions.Condition condition, byte[]... fields) Set the expiration for givenfieldas a UNIX timestamp in milliseconds.hpTtl(byte[] key, byte[]... fields) Get the time to live forfieldsin milliseconds.byte[]hRandField(byte[] key) Return a random field from the hash stored atkey.List<byte[]>hRandField(byte[] key, long count) Return a random field from the hash stored atkey.Map.Entry<byte[],byte[]> hRandFieldWithValues(byte[] key) Return a random field from the hash along with its value stored atkey.hRandFieldWithValues(byte[] key, long count) Return a random field from the hash along with its value stored atkey.hScan(byte[] key, ScanOptions options) Use aCursorto iterate over entries in hash atkey.hSet(byte[] key, byte[] field, byte[] value) Set thevalueof a hashfield.hSetNX(byte[] key, byte[] field, byte[] value) Set thevalueof a hashfieldonly iffielddoes not exist.hStrLen(byte[] key, byte[] field) Returns the length of the value associated withfieldin the hash stored atkey.hTtl(byte[] key, byte[]... fields) Get the time to live forfieldsin seconds.Get the time to live forfieldsin and convert it to the givenTimeUnit.List<byte[]>hVals(byte[] key) Get entry set (values) of hash atfield.
-
Method Details
-
hSet
Set thevalueof a hashfield.- Parameters:
key- must not be null.field- must not be null.value- must not be null.- Returns:
- null when used in pipeline / transaction.
- See Also:
-
hSetNX
Set thevalueof a hashfieldonly iffielddoes not exist.- Parameters:
key- must not be null.field- must not be null.value- must not be null.- Returns:
- null when used in pipeline / transaction.
- See Also:
-
hGet
Get value for givenfieldfrom hash atkey.- Parameters:
key- must not be null.field- must not be null.- Returns:
- null when key or field do not exists or when used in pipeline / transaction.
- See Also:
-
hMGet
Get values for givenfieldsfrom hash atkey. Values are in the order of the requested keys Absent field values are represented using null in the resultingList.- Parameters:
key- must not be null.fields- must not be empty.- Returns:
- empty
Listif key does not exist. null when used in pipeline / transaction. - See Also:
-
hMSet
Set multiple hash fields to multiple values using data provided inhashes- Parameters:
key- must not be null.hashes- must not be null.- See Also:
-
hIncrBy
Incrementvalueof a hashfieldby the givendelta.- Parameters:
key- must not be null.field- must not be null.delta-- Returns:
- null when used in pipeline / transaction.
- See Also:
-
hIncrBy
Incrementvalueof a hashfieldby the givendelta.- Parameters:
key- must not be null.field- must not be null.delta-- Returns:
- null when used in pipeline / transaction.
- See Also:
-
hExists
Determine if given hashfieldexists.- Parameters:
key- must not be null.field- must not be null.- Returns:
- null when used in pipeline / transaction.
- See Also:
-
hDel
Delete given hashfields.- Parameters:
key- must not be null.fields- must not be empty.- Returns:
- null when used in pipeline / transaction.
- See Also:
-
hLen
Get size of hash atkey.- Parameters:
key- must not be null.- Returns:
- null when used in pipeline / transaction.
- See Also:
-
hKeys
Get key set (fields) of hash atkey.- Parameters:
key- must not be null.- Returns:
- null when used in pipeline / transaction.
- See Also:
-
hVals
Get entry set (values) of hash atfield.- Parameters:
key- must not be null.- Returns:
- empty
Listif key does not exist. null when used in pipeline / transaction. - See Also:
-
hGetAll
Get entire hash stored atkey.- Parameters:
key- must not be null.- Returns:
- empty
Mapif key does not exist or null when used in pipeline / transaction. - See Also:
-
hRandField
Return a random field from the hash stored atkey.- Parameters:
key- must not be null.- Returns:
- null if key does not exist or when used in pipeline / transaction.
- Since:
- 2.6
- See Also:
-
hRandFieldWithValues
Return a random field from the hash along with its value stored atkey.- Parameters:
key- must not be null.- Returns:
- null if key does not exist or when used in pipeline / transaction.
- Since:
- 2.6
- See Also:
-
hRandField
Return a random field from the hash stored atkey. If the providedcountargument is positive, return a list of distinct fields, capped either atcountor the hash size. Ifcountis negative, the behavior changes and the command is allowed to return the same field multiple times. In this case, the number of returned fields is the absolute value of the specified count.- Parameters:
key- must not be null.count- number of fields to return.- Returns:
- null if key does not exist or when used in pipeline / transaction.
- Since:
- 2.6
- See Also:
-
hRandFieldWithValues
Return a random field from the hash along with its value stored atkey. If the providedcountargument is positive, return a list of distinct fields, capped either atcountor the hash size. Ifcountis negative, the behavior changes and the command is allowed to return the same field multiple times. In this case, the number of returned fields is the absolute value of the specified count.- Parameters:
key- must not be null.count- number of fields to return.- Returns:
- null if key does not exist or when used in pipeline / transaction.
- Since:
- 2.6
- See Also:
-
hScan
Use aCursorto iterate over entries in hash atkey.- Parameters:
key- must not be null.options- must not be null.- Returns:
- Since:
- 1.4
- See Also:
-
hStrLen
Returns the length of the value associated withfieldin the hash stored atkey. If thekeyor thefielddo not exist,0is returned.- Parameters:
key- must not be null.field- must not be null.- Returns:
- null when used in pipeline / transaction.
- Since:
- 2.1
- See Also:
-
applyHashFieldExpiration
@Nullable default List<Long> applyHashFieldExpiration(byte[] key, Expiration expiration, byte[]... fields) Apply a givenExpirationto the given fields.- Parameters:
key- must not be null.expiration- theExpirationto apply.fields- the names of the fields to apply the expiration to.- Returns:
- a
Listholding the command result for each field in order -2indicating the specific field is deleted already due to expiration, or provided expiry interval is 0;1indicating expiration time is set/updated;0indicating the expiration time is not set;-2indicating there is no such field; - Since:
- 3.5
-
applyHashFieldExpiration
@Nullable default List<Long> applyHashFieldExpiration(byte[] key, Expiration expiration, ExpirationOptions options, byte[]... fields) - Parameters:
key- must not be null.expiration- theExpirationto apply.options- additional options to be sent along with the command.fields- the names of the fields to apply the expiration to.- Returns:
- a
Listholding the command result for each field in order -2indicating the specific field is deleted already due to expiration, or provided expiry interval is 0;1indicating expiration time is set/updated;0indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not met);-2indicating there is no such field; - Since:
- 3.5
-
hExpire
Set time to live for givenfieldsin seconds.- Parameters:
key- must not be null.seconds- the amount of time after which the fields will be expired in seconds, must not be null.fields- must not be null.- Returns:
- a list of
Longvalues for each of the fields provided:2indicating the specific field is deleted already due to expiration, or provided expiry interval is 0;1indicating expiration time is set/updated;0indicating the expiration time is not set;-2indicating there is no such field; null when used in pipeline / transaction. - Since:
- 3.5
- See Also:
-
hExpire
Set time to live for givenfields.- Parameters:
key- must not be null.ttl- the amount of time after which the fields will be expired insecondsprecision, must not be null.fields- must not be null.- Returns:
- a list of
Longvalues for each of the fields provided:2indicating the specific field is deleted already due to expiration, or provided expiry interval is 0;1indicating expiration time is set/updated;0indicating the expiration time is not set;-2indicating there is no such field; null when used in pipeline / transaction. - Since:
- 3.5
- See Also:
-
hExpire
@Nullable List<Long> hExpire(byte[] key, long seconds, ExpirationOptions.Condition condition, byte[]... fields) Set time to live for givenfieldsin seconds.- Parameters:
key- must not be null.seconds- the amount of time after which the fields will be expired in seconds, must not be null.fields- must not be null.condition- the condition for expiration, must not be null.- Returns:
- a list of
Longvalues for each of the fields provided:2indicating the specific field is deleted already due to expiration, or provided expiry interval is 0;1indicating expiration time is set/updated;0indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not met);-2indicating there is no such field; null when used in pipeline / transaction. - Since:
- 3.5
- See Also:
-
hpExpire
Set time to live for givenfieldsin milliseconds.- Parameters:
key- must not be null.millis- the amount of time after which the fields will be expired in milliseconds, must not be null.fields- must not be null.- Returns:
- a list of
Longvalues for each of the fields provided:2indicating the specific field is deleted already due to expiration, or provided expiry interval is 0;1indicating expiration time is set/updated;0indicating the expiration time is not set ;-2indicating there is no such field; null when used in pipeline / transaction. - Since:
- 3.5
- See Also:
-
hpExpire
Set time to live for givenfieldsin milliseconds.- Parameters:
key- must not be null.ttl- the amount of time after which the fields will be expired inmillisecondsprecision, must not be null.fields- must not be null.- Returns:
- a list of
Longvalues for each of the fields provided:2indicating the specific field is deleted already due to expiration, or provided expiry interval is 0;1indicating expiration time is set/updated;0indicating the expiration time is not set;-2indicating there is no such field; null when used in pipeline / transaction. - Since:
- 3.5
- See Also:
-
hpExpire
@Nullable List<Long> hpExpire(byte[] key, long millis, ExpirationOptions.Condition condition, byte[]... fields) Set time to live for givenfieldsin milliseconds.- Parameters:
key- must not be null.millis- the amount of time after which the fields will be expired in milliseconds, must not be null.condition- the condition for expiration, must not be null.fields- must not be null.- Returns:
- a list of
Longvalues for each of the fields provided:2indicating the specific field is deleted already due to expiration, or provided expiry interval is 0;1indicating expiration time is set/updated;0indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not met);-2indicating there is no such field; null when used in pipeline / transaction. - Since:
- 3.5
- See Also:
-
hExpireAt
Set the expiration for givenfieldas a UNIX timestamp.- Parameters:
key- must not be null.unixTime- the moment in time in which the field expires, must not be null.fields- must not be null.- Returns:
- a list of
Longvalues for each of the fields provided:2indicating the specific field is deleted already due to expiration, or provided expiry interval is in the past;1indicating expiration time is set/updated;0indicating the expiration time is not set;-2indicating there is no such field; null when used in pipeline / transaction. - Since:
- 3.5
- See Also:
-
hExpireAt
@Nullable List<Long> hExpireAt(byte[] key, long unixTime, ExpirationOptions.Condition condition, byte[]... fields) Set the expiration for givenfieldas a UNIX timestamp.- Parameters:
key- must not be null.unixTime- the moment in time in which the field expires, must not be null.condition- the condition for expiration, must not be null.fields- must not be null.- Returns:
- a list of
Longvalues for each of the fields provided:2indicating the specific field is deleted already due to expiration, or provided expiry interval is in the past;1indicating expiration time is set/updated;0indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not met);-2indicating there is no such field; null when used in pipeline / transaction. - Since:
- 3.5
- See Also:
-
hpExpireAt
Set the expiration for givenfieldas a UNIX timestamp in milliseconds.- Parameters:
key- must not be null.unixTimeInMillis- the moment in time in which the field expires in milliseconds, must not be null.fields- must not be null.- Returns:
- a list of
Longvalues for each of the fields provided:2indicating the specific field is deleted already due to expiration, or provided expiry interval is in the past;1indicating expiration time is set/updated;0indicating the expiration time is not set;-2indicating there is no such field; null when used in pipeline / transaction. - Since:
- 3.5
- See Also:
-
hpExpireAt
@Nullable List<Long> hpExpireAt(byte[] key, long unixTimeInMillis, ExpirationOptions.Condition condition, byte[]... fields) Set the expiration for givenfieldas a UNIX timestamp in milliseconds.- Parameters:
key- must not be null.unixTimeInMillis- the moment in time in which the field expires in milliseconds, must not be null.condition- the condition for expiration, must not be null.fields- must not be null.- Returns:
- a list of
Longvalues for each of the fields provided:2indicating the specific field is deleted already due to expiration, or provided expiry interval is in the past;1indicating expiration time is set/updated;0indicating the expiration time is not set (a provided NX | XX | GT | LT condition is not met);-2indicating there is no such field; null when used in pipeline / transaction. - Since:
- 3.5
- See Also:
-
hPersist
Remove the expiration from givenfield.- Parameters:
key- must not be null.fields- must not be null.- Returns:
- a list of
Longvalues for each of the fields provided:1indicating expiration time is removed;-1field has no expiration time to be removed;-2indicating there is no such field; null when used in pipeline / transaction.null when used in pipeline / transaction. - Since:
- 3.5
- See Also:
-
hTtl
Get the time to live forfieldsin seconds.- Parameters:
key- must not be null.fields- must not be null.- Returns:
- a list of
Longvalues for each of the fields provided: the time to live in seconds; or a negative value to signal an error. The command returns-1if the field exists but has no associated expiration time. The command returns-2if the field does not exist; null when used in pipeline / transaction. - Since:
- 3.5
- See Also:
-
hTtl
Get the time to live forfieldsin and convert it to the givenTimeUnit.- Parameters:
key- must not be null.timeUnit- must not be null.fields- must not be null.- Returns:
- for each of the fields supplied - the time to live in the
TimeUnitprovided; or a negative value to signal an error. The command returns-1if the key exists but has no associated expiration time. The command returns-2if the key does not exist; null when used in pipeline / transaction. - Since:
- 3.5
- See Also:
-
hpTtl
Get the time to live forfieldsin milliseconds.- Parameters:
key- must not be null.fields- must not be null.- Returns:
- a list of
Longvalues for each of the fields provided: the time to live in seconds; or a negative value to signal an error. The command returns-1if the key exists but has no associated expiration time. The command returns-2if the key does not exist; null when used in pipeline / transaction. - Since:
- 3.5
- See Also:
-