Hashes functions in the Redis DuckDB extension
Function category
Hashes
7 functionsHGET / HSET / HGETALL / HSCAN — for field-keyed records stored under one Redis key. The _over_scan variant pairs SCAN with HSCAN for high-throughput bulk reads.
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
key
|
Type
VARCHAR
|
Mode Positional | Description |
Argument
field
|
Type
VARCHAR
|
Mode Positional | Description |
Argument
secret_name
|
Type
VARCHAR
|
Mode Positional | Description |
Description
Get the value of a hash field. Returns NULL if the key or field does not exist.
SELECT redis_hget('myhash', 'field1', 'my_redis_secret');
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
key
|
Type
VARCHAR
|
Mode Positional | Description |
Argument
secret_name
|
Type
VARCHAR
|
Mode Positional | Description |
Description
List all (field, value) pairs of a hash as a table.
SELECT * FROM redis_hgetall('myhash', 'my_redis_secret');
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
key
|
Type
VARCHAR
|
Mode Positional | Description |
Argument
secret_name
|
Type
VARCHAR
|
Mode Positional | Description |
Description
All fields and values of a hash as a MAP(VARCHAR, VARCHAR) — one value per row, so it works per row in a SELECT (redis_hgetall is a table function). An empty map when the key does not exist. DuckDB 2.0 build.
SELECT redis_hgetall_map('myhash', 'my_redis_secret');
SELECT id, redis_hgetall_map('user:' || id, 'my_redis_secret')['name'] FROM users;
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
key
|
Type
VARCHAR
|
Mode Positional | Description |
Argument
cursor
|
Type
VARCHAR
|
Mode Positional | Description |
Argument
pattern
|
Type
VARCHAR
|
Mode Positional | Description |
Argument
count
|
Type
BIGINT
|
Mode Positional | Description |
Argument
secret_name
|
Type
VARCHAR
|
Mode Positional | Description |
Description
Cursor-paginated scan of a hash's fields. Returns 'next_cursor:field1=value1,...'; re-pass the cursor until it comes back as '0'. Ambiguous when fields or values contain ',' or '='; prefer redis_hscan_page.
SELECT redis_hscan('myhash', '0', '*', 100, 'my_redis_secret');
Related functions
- redis_hscan_page() — One HSCAN step over a hash's fields, typed: returns STRUCT(cursor VARCHAR, entries MAP(VARCHAR, VARCHAR))
- redis_hgetall() — List all (field, value) pairs of a hash as a table
- redis_hscan_over_scan() — For every key matching a SCAN pattern, run HSCAN and emit (key, field, value) rows, following both cursors to the end
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
scan_pattern
|
Type
VARCHAR
|
Mode Positional | Description |
Argument
hscan_pattern
|
Type
VARCHAR
|
Mode Positional | Description |
Argument
count
|
Type
BIGINT
|
Mode Positional | Description |
Argument
secret_name
|
Type
VARCHAR
|
Mode Positional | Description |
Description
For every key matching a SCAN pattern, run HSCAN and emit (key, field, value) rows, following both cursors to the end. Matching keys that are not hashes are skipped. The high-throughput discovery primitive for migration / analysis.
SELECT * FROM redis_hscan_over_scan('user:*', '*', 100, 'my_redis_secret');
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
key
|
Type
VARCHAR
|
Mode Positional | Description |
Argument
cursor
|
Type
VARCHAR
|
Mode Positional | Description |
Argument
pattern
|
Type
VARCHAR
|
Mode Positional | Description |
Argument
count
|
Type
BIGINT
|
Mode Positional | Description |
Argument
secret_name
|
Type
VARCHAR
|
Mode Positional | Description |
Description
One HSCAN step over a hash's fields, typed: returns STRUCT(cursor VARCHAR, entries MAP(VARCHAR, VARCHAR)). Re-pass the cursor until it comes back as '0'. DuckDB 2.0 build.
SELECT redis_hscan_page('myhash', '0', '*', 100, 'my_redis_secret');
SELECT redis_hscan_page('myhash', '0', '*', 100, 'my_redis_secret').entries['field1'];
Related functions
- redis_hscan() — Cursor-paginated scan of a hash's fields
- redis_hgetall_map() — All fields and values of a hash as a MAP(VARCHAR, VARCHAR) — one value per row, so it works per row in a SELECT (redis_hgetall is a table function)
- redis_hscan_over_scan() — For every key matching a SCAN pattern, run HSCAN and emit (key, field, value) rows, following both cursors to the end
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
key
|
Type
VARCHAR
|
Mode Positional | Description |
Argument
field
|
Type
VARCHAR
|
Mode Positional | Description |
Argument
value
|
Type
VARCHAR
|
Mode Positional | Description |
Argument
secret_name
|
Type
VARCHAR
|
Mode Positional | Description |
Description
Set the value of a hash field. Returns the number of fields added as a BIGINT: 1 for a new field, 0 when an existing field is overwritten.
SELECT redis_hset('myhash', 'field1', 'value1', 'my_redis_secret');