Command builders for Redis string operations.
This module provides pure functions that return Redis command lists for
string data type operations, including getting/setting values, atomic
counters, and bulk operations. All functions return a list of strings
suitable for use with Redis.command/2 or Redis.pipeline/2.
Examples
# SET with expiry and NX (only if key does not exist)
iex> Redis.Commands.String.set("session:abc", "user_1", ex: 3600, nx: true)
["SET", "session:abc", "user_1", "EX", "3600", "NX"]
# GET a value
iex> Redis.Commands.String.get("session:abc")
["GET", "session:abc"]
# Atomic counter increment
iex> Redis.Commands.String.incr("page:views")
["INCR", "page:views"]
# Fetch multiple keys at once
iex> Redis.Commands.String.mget(["key1", "key2", "key3"])
["MGET", "key1", "key2", "key3"]
Summary
Functions
Builds an APPEND command to append value to the string already stored at
key. If the key does not exist, it is created with value as its content.
Returns the length of the string after the append operation.
Builds a GETDEL command with conditional deletion (Redis 8.0+). Retrieves
the value at key and deletes it only if the condition is met.
Builds a DIGEST command to return the hash digest of the value stored at
key (Redis 8.0+).
Builds a GET command to retrieve the value stored at key.
Builds a GETEX command to retrieve the value at key and optionally
set or clear its expiration.
Builds an INCR command to atomically increment the integer value at key by 1.
Builds an INCRBY command to atomically increment the integer value at key
by amount. The amount may be negative to decrement.
Builds an MGET command to retrieve the values of multiple keys in one call.
Builds an MSETEX command to atomically set multiple key-value pairs with a shared expiration (Redis 8.0+).
Builds a SET command to store value at key.
Deprecated: use getrange/3 instead.
Functions
Builds an APPEND command to append value to the string already stored at
key. If the key does not exist, it is created with value as its content.
Returns the length of the string after the append operation.
Builds a GETDEL command with conditional deletion (Redis 8.0+). Retrieves
the value at key and deletes it only if the condition is met.
Options
:ifeq- delete only if the current value equals the given string:ifne- delete only if the current value does not equal the given string
Builds a DIGEST command to return the hash digest of the value stored at
key (Redis 8.0+).
Builds a GET command to retrieve the value stored at key.
Returns nil from Redis when the key does not exist.
Builds a GETEX command to retrieve the value at key and optionally
set or clear its expiration.
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 the existing expiry
Builds an INCR command to atomically increment the integer value at key by 1.
If the key does not exist, it is initialized to 0 before incrementing.
Builds an INCRBY command to atomically increment the integer value at key
by amount. The amount may be negative to decrement.
Builds an MGET command to retrieve the values of multiple keys in one call.
Returns a list of values in the same order as the requested keys.
Keys that do not exist produce nil in the corresponding position.
Builds an MSETEX command to atomically set multiple key-value pairs with a shared expiration (Redis 8.0+).
kv_pairs is a list of {key, 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 a SET command to store value at key.
Options
:ex- set expiry in seconds:px- set expiry in milliseconds:nx- only set if the key does not already exist:xx- only set if the key already exists:get- return the old value stored at the key:ifeq- only set if the current value equals the given string (Redis 8.0+):ifne- only set if the current value does not equal the given string (Redis 8.0+)
Deprecated: use getrange/3 instead.