Transactions

BetterKV supports Redis-style transactional workflows, but the real developer question is when to use transactions versus Lua scripts versus plain pipelining.

MULTI and EXEC

MULTI
SET foo bar
INCR counter
LPUSH jobs a
EXEC

Commands queue after MULTI and execute together at EXEC.

DISCARD

MULTI
SET foo oops
DISCARD

WATCH for optimistic concurrency

WATCH balance:alice balance:bob
MULTI
SET balance:alice 900
SET balance:bob 1100
EXEC

If a watched key changes before EXEC, the transaction aborts and the client should retry.

When to use what

NeedBest fit
simple atomic batchMULTI / EXEC
compare-and-setWATCH + MULTI
conditional server-side logicLua
raw throughput with independent commandspipelining

Error model

  • syntax or queueing errors can abort the transaction before EXEC
  • runtime errors inside EXEC do not roll back earlier successful commands

Comparison guidance

If you benchmark BetterKV against Redis and Valkey, transactions are another place to compare tail latency rather than only throughput. Publish contention-heavy cases, not only no-conflict happy paths.