@@ -7,11 +7,32 @@ This extension provides Redis client functionality for DuckDB, allowing you to i
77
88## Features
99Currently supported Redis operations:
10- - String operations: ` GET ` , ` SET `
11- - Hash operations: ` HGET ` , ` HSET `
12- - List operations: ` LPUSH ` , ` LRANGE `
13- - Batch operations: ` MGET ` , ` SCAN `
14-
10+ - String operations: ` GET ` , ` SET ` , ` MGET `
11+ - Hash operations: ` HGET ` , ` HSET ` , ` HGETALL ` , ` HSCAN ` , ` HSCAN_OVER_SCAN `
12+ - List operations: ` LPUSH ` , ` LRANGE ` , ` LRANGE_TABLE `
13+ - Key operations: ` DEL ` , ` EXISTS ` , ` TYPE ` , ` SCAN ` , ` KEYS `
14+ - Batch and discovery operations: ` SCAN ` , ` HSCAN_OVER_SCAN ` , ` KEYS `
15+
16+ ## Quick Reference: Available Functions
17+
18+ | Function | Type | Description |
19+ | ----------| ------| -------------|
20+ | ` redis_get(key, secret) ` | Scalar | Get value of a string key |
21+ | ` redis_set(key, value, secret) ` | Scalar | Set value of a string key |
22+ | ` redis_mget(keys_csv, secret) ` | Scalar | Get values for multiple keys (comma-separated) |
23+ | ` redis_hget(key, field, secret) ` | Scalar | Get value of a hash field |
24+ | ` redis_hset(key, field, value, secret) ` | Scalar | Set value of a hash field |
25+ | ` redis_lpush(key, value, secret) ` | Scalar | Push value to a list |
26+ | ` redis_lrange(key, start, stop, secret) ` | Scalar | Get range from a list (comma-separated) |
27+ | ` redis_del(key, secret) ` | Scalar | Delete a key (returns TRUE if deleted) |
28+ | ` redis_exists(key, secret) ` | Scalar | Check if a key exists (returns TRUE if exists) |
29+ | ` redis_type(key, secret) ` | Scalar | Get the type of a key |
30+ | ` redis_scan(cursor, pattern, count, secret) ` | Scalar | Scan keys (returns cursor: keys_csv ) |
31+ | ` redis_hscan(key, cursor, pattern, count, secret) ` | Scalar | Scan fields in a hash |
32+ | ` redis_keys(pattern, secret) ` | Table | List all keys matching a pattern |
33+ | ` redis_hgetall(key, secret) ` | Table | List all fields and values in a hash |
34+ | ` redis_lrange_table(key, start, stop, secret) ` | Table | List elements in a list as rows |
35+ | ` redis_hscan_over_scan(scan_pattern, hscan_pattern, count, secret) ` | Table | For all keys matching scan_pattern, HSCAN with hscan_pattern, return (key, field, value) rows |
1536
1637## Installation
1738``` sql
@@ -70,6 +91,15 @@ SELECT redis_hset('user:1', 'age', '30', 'redis');
7091-- Get hash field
7192SELECT redis_hget(' user:1' , ' email' , ' redis' ) as email;
7293
94+ -- Get all fields and values in a hash (table)
95+ SELECT * FROM redis_hgetall(' user:1' , ' redis' );
96+
97+ -- HSCAN a hash (pattern match fields)
98+ SELECT redis_hscan(' user:1' , ' 0' , ' email*' , 100 , ' redis' );
99+
100+ -- HSCAN over SCAN: for all keys matching a pattern, get all hash fields matching a pattern
101+ SELECT * FROM redis_hscan_over_scan(' user:*' , ' email*' , 100 , ' redis' );
102+
73103-- Store user profile as hash
74104WITH profile(id, field, value) AS (
75105 VALUES
@@ -93,11 +123,10 @@ SELECT redis_lpush('mylist', 'first_item', 'redis');
93123SELECT redis_lpush(' mylist' , ' second_item' , ' redis' );
94124
95125-- Get range from list (returns comma-separated values)
96- -- Get all items (0 to -1 means start to end)
97126SELECT redis_lrange(' mylist' , 0 , - 1 , ' redis' ) as items;
98127
99- -- Get first 5 items
100- SELECT redis_lrange (' mylist' , 0 , 4 , ' redis' ) as items ;
128+ -- Get all items in a list as rows (table)
129+ SELECT * FROM redis_lrange_table (' mylist' , 0 , - 1 , ' redis' );
101130
102131-- Push multiple items
103132WITH items(value) AS (
@@ -107,24 +136,34 @@ SELECT redis_lpush('mylist', value, 'redis')
107136FROM items;
108137```
109138
110- ### Batch Operations
139+ ### Key Operations
140+ ``` sql
141+ -- List all keys matching a pattern (table)
142+ SELECT * FROM redis_keys(' user:*' , ' redis' );
143+
144+ -- Delete a key
145+ SELECT redis_del(' user:1' , ' redis' );
146+
147+ -- Check if a key exists
148+ SELECT redis_exists(' user:1' , ' redis' );
149+
150+ -- Get the type of a key
151+ SELECT redis_type(' user:1' , ' redis' );
152+ ```
153+
154+ ### Batch and Discovery Operations
111155``` sql
112156-- Get multiple keys at once
113157SELECT redis_mget(' key1,key2,key3' , ' redis' ) as values ;
114- -- Returns comma-separated values for all keys
115158
116159-- Scan keys matching a pattern
117160SELECT redis_scan(' 0' , ' user:*' , 10 , ' redis' ) as result;
118- -- Returns: "cursor:key1,key2,key3" where cursor is the next position for scanning
119- -- Use the returned cursor for the next scan until cursor is 0
120161
121- -- Scan all keys matching a pattern
162+ -- Scan all keys matching a pattern (recursive)
122163WITH RECURSIVE scan(cursor, keys) AS (
123- -- Initial scan
124164 SELECT split_part(redis_scan(' 0' , ' user:*' , 10 , ' redis' ), ' :' , 1 ),
125165 split_part(redis_scan(' 0' , ' user:*' , 10 , ' redis' ), ' :' , 2 )
126166 UNION ALL
127- -- Continue scanning until cursor is 0
128167 SELECT split_part(redis_scan(cursor, ' user:*' , 10 , ' redis' ), ' :' , 1 ),
129168 split_part(redis_scan(cursor, ' user:*' , 10 , ' redis' ), ' :' , 2 )
130169 FROM scan
0 commit comments