@@ -7,11 +7,32 @@ This extension provides Redis client functionality for DuckDB, allowing you to i
7
7
8
8
## Features
9
9
Currently 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 |
15
36
16
37
## Installation
17
38
``` sql
@@ -70,6 +91,15 @@ SELECT redis_hset('user:1', 'age', '30', 'redis');
70
91
-- Get hash field
71
92
SELECT redis_hget(' user:1' , ' email' , ' redis' ) as email;
72
93
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
+
73
103
-- Store user profile as hash
74
104
WITH profile(id, field, value) AS (
75
105
VALUES
@@ -93,11 +123,10 @@ SELECT redis_lpush('mylist', 'first_item', 'redis');
93
123
SELECT redis_lpush(' mylist' , ' second_item' , ' redis' );
94
124
95
125
-- Get range from list (returns comma-separated values)
96
- -- Get all items (0 to -1 means start to end)
97
126
SELECT redis_lrange(' mylist' , 0 , - 1 , ' redis' ) as items;
98
127
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' );
101
130
102
131
-- Push multiple items
103
132
WITH items(value) AS (
@@ -107,24 +136,34 @@ SELECT redis_lpush('mylist', value, 'redis')
107
136
FROM items;
108
137
```
109
138
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
111
155
``` sql
112
156
-- Get multiple keys at once
113
157
SELECT redis_mget(' key1,key2,key3' , ' redis' ) as values ;
114
- -- Returns comma-separated values for all keys
115
158
116
159
-- Scan keys matching a pattern
117
160
SELECT 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
120
161
121
- -- Scan all keys matching a pattern
162
+ -- Scan all keys matching a pattern (recursive)
122
163
WITH RECURSIVE scan(cursor, keys) AS (
123
- -- Initial scan
124
164
SELECT split_part(redis_scan(' 0' , ' user:*' , 10 , ' redis' ), ' :' , 1 ),
125
165
split_part(redis_scan(' 0' , ' user:*' , 10 , ' redis' ), ' :' , 2 )
126
166
UNION ALL
127
- -- Continue scanning until cursor is 0
128
167
SELECT split_part(redis_scan(cursor, ' user:*' , 10 , ' redis' ), ' :' , 1 ),
129
168
split_part(redis_scan(cursor, ' user:*' , 10 , ' redis' ), ' :' , 2 )
130
169
FROM scan
0 commit comments