HSCAN to iterate the fields of a hash in batches instead of reading it all at once.
Each call takes a cursor and returns the next cursor together with a batch of field and value pairs. Start at cursor 0 and keep calling with the cursor from the previous reply until the server returns 0, which ends the iteration. Because each call does a bounded amount of work, this avoids the long single reply that HGETALL produces on a large hash.
MATCH filters field names with a glob-style pattern, COUNT hints at how much work each call should do, and NOVALUES returns field names only, which is noticeably cheaper when values are large and you do not need them. Filtering is applied after a batch has been read, so a call can return nothing while the cursor is still non-zero: only a cursor of 0 means the iteration is over. Fields present for the whole iteration are returned at least once, and fields added or removed while it runs may or may not appear.
Syntax
Arguments
Important points
- This operation can inspect a large part of the database. Prefer cursor-based scans where possible and avoid unbounded use on hot paths.
- The cursor is opaque. Start with
0and continue until the server returns cursor0; a single iteration may return no elements.
Response
The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below.Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply.
Examples
TCP examples use the TLSREDIS_URL from the Upstash console. REST examples use UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN.
Redis CLI
Redis CLI
@upstash/redis
@upstash/redis
upstash_redis
upstash_redis
ioredis
ioredis
node-redis
node-redis
redis-py
redis-py
go-redis
go-redis
jedis
jedis
redis-rs
redis-rs