Search Shortcut cmd + k | ctrl + k
redis

Redis compatible Client for DuckDB

Maintainer(s): lmangani, gigapi

Installing and Loading

INSTALL redis FROM community;
LOAD redis;

Example

-- Create a local Redis connection secret
CREATE SECRET IF NOT EXISTS redis (
        TYPE redis,
        PROVIDER config,
        host 'localhost',
        port '6379',
        password 'optional_password'
    );

-- Create a Redis cloud connection secret
CREATE SECRET IF NOT EXISTS redis (
        TYPE redis,
        PROVIDER config,
        host 'redis-1234.ec2.redns.redis-cloud.com',
        port '16959',
        password 'xxxxxx'
    );

-- Set a value
SELECT redis_set('user:1', 'John Doe', 'redis') as result;

-- Get a value
SELECT redis_get('user:1', 'redis') as user_name;

-- Set hash fields
SELECT redis_hset('user:1', 'email', '[email protected]', 'redis');
SELECT redis_hset('user:1', 'age', '30', 'redis');

-- Get hash field
SELECT redis_hget('user:1', 'email', 'redis') as email;

-- Push items to list
SELECT redis_lpush('mylist', 'first_item', 'redis');
SELECT redis_lpush('mylist', 'second_item', 'redis');

-- Get range from list (returns comma-separated values)
-- Get all items (0 to -1 means start to end)
SELECT redis_lrange('mylist', 0, -1, 'redis') as items;

-- Get first 5 items
SELECT redis_lrange('mylist', 0, 4, 'redis') as items;

-- Push multiple items
WITH items(value) AS (
    VALUES ('item1'), ('item2'), ('item3')
)
SELECT redis_lpush('mylist', value, 'redis')
FROM items;

About redis

DuckDB Redis Client Extension

This extension provides Redis-compatible client functionality for DuckDB

Experimental: USE AT YOUR OWN RISK!

Features

Currently supported Redis operations:

  • String operations: GET, SET, MGET
  • Hash operations: HGET, HSET, HGETALL, HSCAN, HSCAN_OVER_SCAN
  • List operations: LPUSH, LRANGE, LRANGE_TABLE
  • Key operations: DEL, EXISTS, TYPE, SCAN, KEYS
  • Batch and discovery operations: SCAN, HSCAN_OVER_SCAN, KEYS

Quick Reference: Available Functions

Function Type Description
redis_get(key, secret) Scalar Get value of a string key
redis_set(key, value, secret) Scalar Set value of a string key
redis_mget(keys_csv, secret) Scalar Get values for multiple keys (comma-separated)
redis_hget(key, field, secret) Scalar Get value of a hash field
redis_hset(key, field, value, secret) Scalar Set value of a hash field
redis_lpush(key, value, secret) Scalar Push value to a list
redis_lrange(key, start, stop, secret) Scalar Get range from a list (comma-separated)
redis_del(key, secret) Scalar Delete a key (returns TRUE if deleted)
redis_exists(key, secret) Scalar Check if a key exists (returns TRUE if exists)
redis_type(key, secret) Scalar Get the type of a key
redis_scan(cursor, pattern, count, secret) Scalar Scan keys (returns cursor:keys_csv)
redis_hscan(key, cursor, pattern, count, secret) Scalar Scan fields in a hash
redis_keys(pattern, secret) Table List all keys matching a pattern
redis_hgetall(key, secret) Table List all fields and values in a hash
redis_lrange_table(key, start, stop, secret) Table List elements in a list as rows
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

Added Functions

function_name function_type description comment examples
redis_del scalar NULL NULL  
redis_exists scalar NULL NULL  
redis_get scalar NULL NULL  
redis_hget scalar NULL NULL  
redis_hgetall table NULL NULL  
redis_hscan scalar NULL NULL  
redis_hscan_over_scan table NULL NULL  
redis_hset scalar NULL NULL  
redis_keys table NULL NULL  
redis_lpush scalar NULL NULL  
redis_lrange scalar NULL NULL  
redis_lrange_table table NULL NULL  
redis_mget scalar NULL NULL  
redis_scan scalar NULL NULL  
redis_set scalar NULL NULL  
redis_type scalar NULL NULL