|
| 1 | +# DuckDB Redis Extension |
| 2 | +This extension provides Redis client functionality for DuckDB, allowing you to interact with a Redis server directly from SQL queries. The extension uses Boost.Asio for network communication and implements basic Redis protocol commands. |
| 3 | + |
| 4 | +## Features |
| 5 | +Currently supported Redis operations: |
| 6 | +- `redis_get(key, host, port)`: Retrieves a value from Redis for a given key |
| 7 | +- `redis_set(key, value, host, port)`: Sets a value in Redis for a given key |
| 8 | + |
| 9 | +## Installation |
| 10 | +```sql |
| 11 | +INSTALL 'redis' FROM community; |
| 12 | +LOAD 'redis'; |
| 13 | +``` |
| 14 | + |
| 15 | +## Usage Examples |
| 16 | +### Setting Values in Redis |
| 17 | +```sql |
| 18 | +-- Set a single value |
| 19 | +SELECT redis_set('user:1', 'John Doe', 'localhost', '6379') as result; |
| 20 | + |
| 21 | +-- Set multiple values in a query |
| 22 | +INSERT INTO users (id, name, age) |
| 23 | +SELECT redis_set( |
| 24 | + 'user:' || id::VARCHAR, |
| 25 | + name, |
| 26 | + 'localhost', |
| 27 | + '6379' |
| 28 | +) |
| 29 | +FROM new_users; |
| 30 | +``` |
| 31 | + |
| 32 | +### Getting Values from Redis |
| 33 | +```sql |
| 34 | +-- Get a single value |
| 35 | +SELECT redis_get('user:1', 'localhost', '6379') as user_name; |
| 36 | + |
| 37 | +-- Get multiple values |
| 38 | +SELECT |
| 39 | + id, |
| 40 | + redis_get('user:' || id::VARCHAR, 'localhost', '6379') as user_data |
| 41 | +FROM user_ids; |
| 42 | +``` |
| 43 | + |
| 44 | +## Building from Source |
| 45 | +Follow the standard DuckDB extension build process: |
| 46 | + |
| 47 | +```sh |
| 48 | +# Install vcpkg dependencies |
| 49 | +./vcpkg/vcpkg install boost-asio |
| 50 | + |
| 51 | +# Build the extension |
| 52 | +make |
| 53 | +``` |
| 54 | + |
| 55 | +## Dependencies |
| 56 | +- Boost.Asio (header-only, installed via vcpkg) |
| 57 | + |
| 58 | +## Error Handling |
| 59 | +The extension functions will throw exceptions with descriptive error messages when: |
| 60 | +- Unable to connect to Redis server |
| 61 | +- Network communication errors occur |
| 62 | +- Invalid Redis protocol responses are received |
| 63 | + |
| 64 | +## Future Enhancements |
| 65 | +Planned features include: |
| 66 | +- Support for Redis authentication |
| 67 | +- Connection pooling for better performance |
| 68 | +- Additional Redis commands (HGET, HSET, LPUSH, etc.) |
| 69 | +- Table functions for scanning Redis keys |
| 70 | +- Batch operations using Redis pipelines |
| 71 | +- Connection timeout handling |
| 72 | + |
1 | 73 | # DuckDB Extension Template |
2 | 74 | This repository contains a template for creating a DuckDB extension. The main goal of this template is to allow users to easily develop, test and distribute their own DuckDB extension. The main branch of the template is always based on the latest stable DuckDB allowing you to try out your extension right away. |
3 | 75 |
|
|
0 commit comments