Command builders for Redis hash operations.
This module provides pure functions that return Redis command lists for
hash data type operations, including setting and retrieving fields,
atomic field increments, and hash scanning. All functions return a list
of strings suitable for use with Redis.command/2 or Redis.pipeline/2.
Examples
# HSET with multiple fields at once
iex> Redis.Commands.Hash.hset("user:1", [{"name", "Alice"}, {"age", "30"}])
["HSET", "user:1", "name", "Alice", "age", "30"]
# Retrieve all fields and values
iex> Redis.Commands.Hash.hgetall("user:1")
["HGETALL", "user:1"]
# Atomically increment a numeric field
iex> Redis.Commands.Hash.hincrby("user:1", "login_count", 1)
["HINCRBY", "user:1", "login_count", "1"]
Summary
Functions
Builds an HDEL command to remove one or more fields from the hash at key.
Returns the number of fields that were removed.
Builds an HEXPIRE command to set a timeout in seconds on one or more
hash fields stored at key.
Builds an HEXPIREAT command to set an expiry on one or more hash fields
at the given absolute Unix timestamp (seconds).
Builds an HEXPIRETIME command to retrieve the absolute Unix expiration
timestamp (seconds) for each of the specified hash fields at key.
Builds an HGET command to retrieve the value of a single field in the
hash stored at key. Returns nil when the field or key does not exist.
Builds an HGETALL command to retrieve all fields and values in the hash
stored at key. The result from Redis is a flat list alternating between
field names and their values.
Builds an HGETDEL command to atomically retrieve and delete one or more
fields from the hash at key (Redis 8.0+).
Builds an HGETEX command to retrieve the values of one or more fields in
the hash at key and optionally set or clear per-field expiration (Redis 8.0+).
Builds an HINCRBY command to atomically increment the integer value of
field in the hash at key by amount. If the field does not exist,
it is initialized to 0 before incrementing.
Deprecated: use hset/2 instead.
Builds an HPERSIST command to remove the expiration from one or more
hash fields at key, making them persistent.
Builds an HPEXPIRE command to set a timeout in milliseconds on one or more
hash fields stored at key.
Builds an HPEXPIREAT command to set an expiry on one or more hash fields
at the given absolute Unix timestamp (milliseconds).
Builds an HPEXPIRETIME command to retrieve the absolute Unix expiration
timestamp (milliseconds) for each of the specified hash fields at key.
Builds an HPTTL command to retrieve the remaining time-to-live in
milliseconds for each of the specified hash fields at key.
Builds an HSCAN command to incrementally iterate over fields in the hash
at key. Start with cursor 0 and use the cursor returned by Redis in
subsequent calls until it returns 0.
Builds an HSET command to set one or more field-value pairs in the hash
stored at key. Accepts a list of {field, value} tuples. Fields that
already exist are overwritten.
Builds an HSETEX command to set one or more field-value pairs in the hash at
key with a per-field expiration (Redis 8.0+).
Builds an HTTL command to retrieve the remaining time-to-live in seconds
for each of the specified hash fields at key.
Functions
Builds an HDEL command to remove one or more fields from the hash at key.
Returns the number of fields that were removed.
Builds an HEXPIRE command to set a timeout in seconds on one or more
hash fields stored at key.
Options
:nx- set expiry only when the field has no expiry:xx- set expiry only when the field already has an expiry:gt- set expiry only when the new expiry is greater than the current one:lt- set expiry only when the new expiry is less than the current one
Builds an HEXPIREAT command to set an expiry on one or more hash fields
at the given absolute Unix timestamp (seconds).
Accepts the same options as hexpire/4.
Builds an HEXPIRETIME command to retrieve the absolute Unix expiration
timestamp (seconds) for each of the specified hash fields at key.
Builds an HGET command to retrieve the value of a single field in the
hash stored at key. Returns nil when the field or key does not exist.
Builds an HGETALL command to retrieve all fields and values in the hash
stored at key. The result from Redis is a flat list alternating between
field names and their values.
Builds an HGETDEL command to atomically retrieve and delete one or more
fields from the hash at key (Redis 8.0+).
Builds an HGETEX command to retrieve the values of one or more fields in
the hash at key and optionally set or clear per-field expiration (Redis 8.0+).
Options
:ex- set expiry in seconds:px- set expiry in milliseconds:exat- set expiry as a Unix timestamp in seconds:pxat- set expiry as a Unix timestamp in milliseconds:persist- remove existing expiry from the fields
Builds an HINCRBY command to atomically increment the integer value of
field in the hash at key by amount. If the field does not exist,
it is initialized to 0 before incrementing.
Deprecated: use hset/2 instead.
Builds an HPERSIST command to remove the expiration from one or more
hash fields at key, making them persistent.
Builds an HPEXPIRE command to set a timeout in milliseconds on one or more
hash fields stored at key.
Accepts the same options as hexpire/4.
Builds an HPEXPIREAT command to set an expiry on one or more hash fields
at the given absolute Unix timestamp (milliseconds).
Accepts the same options as hexpire/4.
Builds an HPEXPIRETIME command to retrieve the absolute Unix expiration
timestamp (milliseconds) for each of the specified hash fields at key.
Builds an HPTTL command to retrieve the remaining time-to-live in
milliseconds for each of the specified hash fields at key.
Builds an HSCAN command to incrementally iterate over fields in the hash
at key. Start with cursor 0 and use the cursor returned by Redis in
subsequent calls until it returns 0.
Options
:match- glob-style pattern to filter field names:count- hint for how many elements to return per call
Builds an HSET command to set one or more field-value pairs in the hash
stored at key. Accepts a list of {field, value} tuples. Fields that
already exist are overwritten.
Builds an HSETEX command to set one or more field-value pairs in the hash at
key with a per-field expiration (Redis 8.0+).
field_values is a list of {field, value} tuples.
Options
:ex- set expiry in seconds:px- set expiry in milliseconds:exat- set expiry as a Unix timestamp in seconds:pxat- set expiry as a Unix timestamp in milliseconds
Builds an HTTL command to retrieve the remaining time-to-live in seconds
for each of the specified hash fields at key.