Skip to main content

Command: Scan By Prefix

Scans persistent storage across the cluster and returns key/value pairs whose keys start with the specified prefix.

set `services/auth/instance-1` "node1"
r0 set 8ms

set `services/auth/instance-2` "node2"
r0 set 9ms

scan by prefix `services/auth`
r0 services/auth/instance-1 node1
r0 services/auth/instance-2 node2

Assigning Results

Inside a script, assign the command to a variable with let. The variable receives an array of the returned values.

let instances = scan by prefix `services/auth`
return count(instances)

Scan By Prefix As Of Timestamp

scan by prefix also supports snapshot reads:

scan by prefix `services/auth` as of 1718392012345

This returns only the keys that were visible under that prefix at the requested snapshot time.

If a key already existed at that time and was updated later, the snapshot still returns the older visible value from the requested time. Keys created after that time are not returned.

Notes

scan by prefix visits nodes and workers to find matching keys. It is broader and slower than get by bucket, and it is not the preferred command for transactional logic. Use get by bucket when the keys share a bucket and you need a consistent, partition-local read.

The command returns the matching set in one response and is capped at 4096 entries. Use paginated range reads from the .NET client for large or unbounded ordered scans.