Skip to content

Hash Commands

Hash commands operate on Redis hashes — maps between string fields and string values. Hashes are ideal for representing objects with multiple fields.

This page covers: HEXISTS, HGET, HGETALL, HINCRBY, HLEN, HMGET, HSCAN, HSET


HSET

Set one or more fields in a hash.

📘 Redis Reference: HSET

XML Example

xml
<!-- Set multiple fields in a user hash -->
<lettuce-redis:hset doc:name="Set user fields"
    config-ref="Redis_Config"
    key="user:123"
    fields="#[{'name': 'Alice Johnson', 'email': 'alice@example.com', 'role': 'admin', 'status': 'active'}]"/>

Parameters

ParameterTypeRequiredDefaultDescription
keyStringYesThe hash key
fieldsMap<String, String>YesField-value pairs to set. Map must not be empty. Payload by default via @Content.

Output

Type: Long

The number of new fields added. Updates to existing fields are not counted.

Errors

Error TypeCondition
REDIS:ARGUMENTFields map is empty
REDIS:COMMANDGeneral command execution error
REDIS:WRONG_TYPEKey exists but is not a hash

HGET

Get the value of a hash field.

📘 Redis Reference: HGET

XML Example

xml
<lettuce-redis:hget doc:name="Get user email"
    config-ref="Redis_Config"
    key="user:123"
    field="email"/>

<!-- payload now contains the email address -->

Parameters

ParameterTypeRequiredDefaultDescription
keyStringYesThe hash key
fieldStringYesThe field name to retrieve

Output

Type: String (media type: text/plain)

The value of the field.

Errors

Error TypeCondition
REDIS:NILField does not exist in the hash
REDIS:COMMANDGeneral command execution error
REDIS:WRONG_TYPEKey exists but is not a hash

HGETALL

Get all fields and values in a hash.

📘 Redis Reference: HGETALL

XML Example

xml
<lettuce-redis:hgetall doc:name="Get all user fields"
    config-ref="Redis_Config"
    key="user:123"/>

<!-- payload is now a Map<String, String> with all fields and values -->
<logger level="INFO" message="User name: #[payload.name]"/>
<logger level="INFO" message="User email: #[payload.email]"/>

Parameters

ParameterTypeRequiredDefaultDescription
keyStringYesThe hash key

Output

Type: Map<String, String>

A map of all field-value pairs in the hash. Returns an empty map if the hash does not exist.

Errors

Error TypeCondition
REDIS:COMMANDGeneral command execution error
REDIS:WRONG_TYPEKey exists but is not a hash

HMGET

Get the values of multiple hash fields.

📘 Redis Reference: HMGET

XML Example

xml
<lettuce-redis:hmget doc:name="Get multiple user fields"
    config-ref="Redis_Config"
    key="user:123"
    fieldNames="#[['name', 'email', 'status']]"/>

<!-- payload is now a Map<String, String> with the requested fields -->
<!-- Missing fields appear with null values in the map -->

Parameters

ParameterTypeRequiredDefaultDescription
keyStringYesThe hash key
fieldNamesList<String>YesField names to retrieve. At least one required. Fields must be defined inline (allowInlineDefinition=true, allowReferences=false).

Output

Type: Map<String, String>

A map of field names to values. If a field does not exist in the hash, its value in the map is null.

Errors

Error TypeCondition
REDIS:ARGUMENTNo field names provided
REDIS:COMMANDGeneral command execution error
REDIS:WRONG_TYPEKey exists but is not a hash

HEXISTS

Check if a field exists in a hash.

📘 Redis Reference: HEXISTS

XML Example

xml
<lettuce-redis:hexists doc:name="Check if user has phone"
    config-ref="Redis_Config"
    key="user:123"
    field="phone"/>

<choice>
    <when expression="#[payload == true]">
        <logger level="INFO" message="User has a phone number on file"/>
    </when>
    <otherwise>
        <logger level="INFO" message="No phone number for user"/>
    </otherwise>
</choice>

Parameters

ParameterTypeRequiredDefaultDescription
keyStringYesThe hash key
fieldStringYesThe field to check

Output

Type: Boolean

  • true if the field exists in the hash
  • false if the field does not exist or the hash does not exist

Errors

Error TypeCondition
REDIS:COMMANDGeneral command execution error
REDIS:WRONG_TYPEKey exists but is not a hash

HLEN

Get the number of fields in a hash.

📘 Redis Reference: HLEN

XML Example

xml
<lettuce-redis:hlen doc:name="Count user fields"
    config-ref="Redis_Config"
    key="user:123"/>

<logger level="INFO" message="User has #[payload] fields"/>

Parameters

ParameterTypeRequiredDefaultDescription
keyStringYesThe hash key

Output

Type: Long

The number of fields in the hash. Returns 0 if the hash does not exist.

Errors

Error TypeCondition
REDIS:COMMANDGeneral command execution error
REDIS:WRONG_TYPEKey exists but is not a hash

HINCRBY

Increment the integer value of a hash field by the specified amount.

📘 Redis Reference: HINCRBY

XML Example

xml
<lettuce-redis:hincrby doc:name="Increment user login count"
    config-ref="Redis_Config"
    key="user:123:stats"
    field="loginCount"
    increment="1"/>

<!-- payload is now the new value after increment -->

Parameters

ParameterTypeRequiredDefaultDescription
keyStringYesThe hash key
fieldStringYesThe field to increment
incrementLongYesThe amount to add (can be negative for decrement)

Output

Type: Long

The new value of the field after the increment.

Errors

Error TypeCondition
REDIS:COMMANDGeneral command execution error
REDIS:WRONG_TYPEKey exists but is not a hash, or field does not hold an integer value

HSCAN

Incrementally iterate hash fields using a cursor.

📘 Redis Reference: HSCAN

Automated Cursor Management

For most use cases, consider using Search Hash Fields instead, which handles cursor iteration automatically and streams all field-value pairs. Use HSCAN directly only when you need fine-grained control over pagination.

XML Example

xml
<!-- Start a new scan (cursor 0) -->
<lettuce-redis:hscan doc:name="Scan hash fields"
    config-ref="Redis_Config"
    key="user:123"
    cursor="0"
    match="setting:*"
    count="50"/>

<!-- payload contains a Map<String, String> of fields from this page -->
<!-- attributes.cursor contains the next cursor value -->
<logger level="INFO" message="Next cursor: #[attributes.cursor]"/>

<!-- Continue scanning with the next cursor -->
<lettuce-redis:hscan doc:name="Scan next page"
    config-ref="Redis_Config"
    key="user:123"
    cursor="#[attributes.cursor]"
    match="setting:*"
    count="50"/>

Parameters

ParameterTypeRequiredDefaultDescription
keyStringYesThe hash key to scan
cursorIntegerYesCursor position. Use 0 to start a new scan.
matchStringNoGlob-style pattern to filter field names
countIntegerNoHint for the number of elements to return per iteration

Output

Type: Map<String, String>

A map of field-value pairs matching the pattern for this scan iteration.

Attributes: ScanAttributes — Contains the cursor field with the next cursor value. When cursor is 0, the scan is complete.

Errors

Error TypeCondition
REDIS:COMMANDGeneral command execution error
REDIS:WRONG_TYPEKey exists but is not a hash

Released under the MIT License.