Skip to content

ZGET

Retrieves the value for a key from the ZMap ordered key-value store.

ZGET <key> [NAMESPACE <path>]

key is positional. NAMESPACE is a keyword argument and comes after it.

ArgumentTypeRequiredDescription
keybytesYesThe key to look up.
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.

Bulk string: the value associated with the key, or nil if the key does not exist.

ZGET reads the value for a given key from the ZMap subspace of the session’s current namespace, backed by FoundationDB.

If the key does not exist, the command returns nil.

The command supports two transaction modes:

  • Auto-commit (one-off): When no explicit transaction is active, Kronotop creates a transaction, performs the read, and commits it immediately. This is the default mode.
  • Explicit transaction: When a BEGIN has been issued, the read is performed within the current transaction.

ZGET also supports snapshot reads. When snapshot mode is enabled on the session, the read does not conflict with concurrent writes, allowing higher throughput for read-heavy workloads.

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 'ZGET' 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-

Get an existing key:

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

Get a non-existent key:

> ZGET nosuchkey
(nil)

Use within an explicit transaction:

> BEGIN
OK
> ZSET mykey "Hello"
OK
> COMMIT
OK
> BEGIN
OK
> ZGET mykey
"Hello"
> COMMIT
OK