Skip to content

ZSET

Sets a key-value pair in the ZMap ordered key-value store.

ZSET <key> <value> [NAMESPACE <path>]

key and value are positional. NAMESPACE is a keyword argument and comes after them.

ArgumentTypeRequiredDescription
keybytesYesThe key to set.
valuebytesYesThe value to associate with the key.
NAMESPACEstringNoRun this command in the given namespace instead of the session’s current one. The namespace must exist. The session’s current namespace does not change.

Simple string: OK on success.

ZSET writes a key-value pair into the ZMap subspace of the session’s current namespace, backed by FoundationDB. Keys are stored in lexicographic order.

If the key already exists, its value is overwritten silently. There is no duplicate-key error.

The command supports two transaction modes:

  • Auto-commit (one-off): When no explicit transaction is active, Kronotop creates a transaction, performs the write, and commits it immediately. This is the default mode.
  • Explicit transaction: When a BEGIN has been issued, the write is staged in the current transaction and only persists when COMMIT is called.

All data is scoped to a namespace: the session’s active one, or the one given with NAMESPACE. The same key in different namespaces refers to different entries.

Argument errors:

Error CodeError messageCause
ERRwrong number of arguments for 'ZSET' command-
ERRUnknown '<keyword>' argument-
ERRNAMESPACE argument must be followed by a namespace-

Namespace errors:

Error CodeError messageCause
NOSUCHNAMESPACENo such namespace: '<path>'-
NAMESPACEBEINGREMOVEDNamespace '<path>' is being removed-

Set a key-value pair:

> ZSET mykey "Hello"
OK

Overwrite an existing key:

> ZSET mykey "Hello"
OK
> ZSET mykey "World"
OK
> ZGET mykey
"World"

Use within an explicit transaction:

> BEGIN
OK
> ZSET mykey "Hello"
OK
> ZSET anotherkey "World"
OK
> COMMIT
OK