FerricStore.Tx (ferricstore v0.3.1)

Copy Markdown View Source

Transaction accumulator for executing multiple FerricStore commands atomically.

Used with FerricStore.multi/1 to batch multiple operations. Commands are accumulated in reverse order and executed sequentially when the transaction completes.

Usage

FerricStore.multi(fn tx ->
  tx
  |> FerricStore.Tx.set("key1", "val1")
  |> FerricStore.Tx.get("key1")
end)

Summary

Functions

Adds a DEL command to the transaction.

Executes all accumulated transaction commands atomically.

Adds an EXPIRE command to the transaction.

Adds a GET command to the transaction.

Adds an HGET command to the transaction.

Adds an HSET command to the transaction.

Adds an INCR command to the transaction.

Adds an INCRBY command to the transaction.

Adds an LPUSH command to the transaction.

Creates a new empty transaction.

Adds an RPUSH command to the transaction.

Adds a SADD command to the transaction.

Adds a SET command to the transaction.

Adds a ZADD command to the transaction.

Types

command()

@type command() ::
  {:set, binary(), binary(), keyword()}
  | {:get, binary()}
  | {:del, binary()}
  | {:incr, binary()}
  | {:incr_by, binary(), integer()}
  | {:hset, binary(), map()}
  | {:hget, binary(), binary()}
  | {:lpush, binary(), [binary()]}
  | {:rpush, binary(), [binary()]}
  | {:sadd, binary(), [binary()]}
  | {:zadd, binary(), [{number(), binary()}]}
  | {:expire, binary(), non_neg_integer()}

t()

@type t() :: %FerricStore.Tx{commands: [command()]}

Functions

del(tx, key)

@spec del(t(), binary()) :: t()

Adds a DEL command to the transaction.

execute(tx)

@spec execute(t()) :: [term()] | {:error, binary()}

Executes all accumulated transaction commands atomically.

Groups commands by shard. If all target a single shard, dispatches them as a batch to the shard GenServer (atomic, no interleaving). If commands span multiple shards, returns a CROSSSLOT error.

expire(tx, key, ttl_ms)

@spec expire(t(), binary(), non_neg_integer()) :: t()

Adds an EXPIRE command to the transaction.

get(tx, key)

@spec get(t(), binary()) :: t()

Adds a GET command to the transaction.

hget(tx, key, field)

@spec hget(t(), binary(), binary()) :: t()

Adds an HGET command to the transaction.

hset(tx, key, fields)

@spec hset(t(), binary(), map()) :: t()

Adds an HSET command to the transaction.

incr(tx, key)

@spec incr(t(), binary()) :: t()

Adds an INCR command to the transaction.

incr_by(tx, key, amount)

@spec incr_by(t(), binary(), integer()) :: t()

Adds an INCRBY command to the transaction.

lpush(tx, key, elements)

@spec lpush(t(), binary(), [binary()]) :: t()

Adds an LPUSH command to the transaction.

new()

@spec new() :: t()

Creates a new empty transaction.

rpush(tx, key, elements)

@spec rpush(t(), binary(), [binary()]) :: t()

Adds an RPUSH command to the transaction.

sadd(tx, key, members)

@spec sadd(t(), binary(), [binary()]) :: t()

Adds a SADD command to the transaction.

set(tx, key, value, opts \\ [])

@spec set(t(), binary(), binary(), keyword()) :: t()

Adds a SET command to the transaction.

zadd(tx, key, score_member_pairs)

@spec zadd(t(), binary(), [{number(), binary()}]) :: t()

Adds a ZADD command to the transaction.