Skip to content

DuckDB Extension

Redis

Read Redis values from DuckDB SQL and join them with local data. The extension also supports writes, hashes, lists, and key discovery.

113,878
extension loads · last 90 days
On this page

Use values from Redis alongside analytical data

Redis stores values under keys and supports structures such as hashes and lists. This extension accesses those values from DuckDB, so a SQL query can look up operational data and combine it with local tables.

Use it for inspecting a Redis instance or enriching rows with values already held there. You need a reachable Redis server and the appropriate credentials. Reads observe that server’s current data; save the results locally when you need a repeatable analytical snapshot.

Example

Read an existing Redis string

Connect to a local Redis server and look up one string key. This example does not write to Redis.

Before you run it: Run a Redis server on localhost:6379, or change the connection settings. Use an existing string key.

Run this example in the DuckDB CLI or a native client.

SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
  WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL redis FROM query_farm;
LOAD redis FROM query_farm;

CREATE OR REPLACE SECRET qf_redis_demo (
  TYPE redis, PROVIDER config,
  host 'localhost', port '6379'
);
SELECT redis_get('user:1', 'qf_redis_demo') AS value;
DROP SECRET qf_redis_demo;

Replace user:1 with a string key in your instance. The result depends on the stored value. Use the authentication guidance for servers that require credentials.

Common tasks

Deep Dive

Technical Details

Reference

Extension Contents

Quick reference to all available functions and settings organized by category.

Cache / In-memory store
redis Object type: Secret Redis connection details.
Commands
redis_command() Object type: Scalar function Run any Redis command, given as a VARCHAR[] of the command name and its arguments — sets, sorted sets, counters, streams and anything else without a dedicated function.
Configuration
redis_timeout_ms Object type: Setting Timeout in milliseconds for connecting to Redis and for each wait for reply data (0 waits forever; queries can still be interrupted).
Expiry
redis_expire() Object type: Scalar function Set a key's time-to-live in seconds.
redis_expireat() Object type: Scalar function Expire a key at an absolute Unix timestamp (seconds).
redis_ttl() Object type: Scalar function Remaining time-to-live in seconds.
Hashes
redis_hget() Object type: Scalar function Get the value of a hash field.
redis_hgetall() Object type: Table function List all (field, value) pairs of a hash as a table.
redis_hgetall_map() Object type: Scalar function 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() Object type: Scalar function Cursor-paginated scan of a hash's fields.
redis_hscan_over_scan() Object type: Table function For every key matching a SCAN pattern, run HSCAN and emit (key, field, value) rows, following both cursors to the end.
redis_hscan_page() Object type: Scalar function One HSCAN step over a hash's fields, typed: returns STRUCT(cursor VARCHAR, entries MAP(VARCHAR, VARCHAR)).
redis_hset() Object type: Scalar function Set the value of a hash field.
Keys
redis_del() Object type: Scalar function Delete a key.
redis_exists() Object type: Scalar function Check whether a key exists.
redis_keys() Object type: Table function List all keys matching a pattern as a table, one row per key.
redis_scan() Object type: Scalar function Cursor-paginated SCAN of the keyspace, one page per call.
redis_scan_page() Object type: Scalar function One SCAN step over the keys matching a pattern, typed: returns STRUCT(cursor VARCHAR, keys VARCHAR[]).
redis_type() Object type: Scalar function Get the Redis type of a key (string / list / hash / set / zset / stream / none).
Lists
redis_lpush() Object type: Scalar function Push a value onto the head of a list.
redis_lrange() Object type: Scalar function Get a range from a list as a comma-separated string.
redis_lrange_list() Object type: Scalar function Get a range from a list as a VARCHAR[].
redis_lrange_table() Object type: Table function Get a range from a list as a table — one row per element, with index (the element's position in the list) and value.
Strings
redis_get() Object type: Scalar function Get the value of a string key.
redis_mget() Object type: Scalar function Get multiple values in one round-trip.
redis_mget_list() Object type: Scalar function Get multiple values in one round-trip, typed: takes the keys as a VARCHAR[] and returns a VARCHAR[] of the same length, with NULL for each missing key.
redis_set() Object type: Scalar function Set the value of a string key.

API Reference

Function Reference

Configuration

Settings

Configure the redis extension behavior using these settings.

redis_timeout_ms

Default Value: 30000

Security

Secrets

DuckDB secrets for storing the credentials and keys used by the redis extension.

redis

Description
Parameters
Parameter host Type VARCHAR Required Required Description Redis server hostname or IP.
Parameter port Type VARCHAR Required Required Description Redis server port (typically '6379').
Parameter password Type VARCHAR Required Optional Description Authentication password if the server requires AUTH. Optional: leave it out to connect without AUTH.
Parameter username Type VARCHAR Required Optional Description Redis 6+ ACL user name, sent as AUTH username password. Requires password. DuckDB 2.0 build.
Parameter db Type BIGINT Required Optional Description Database index to SELECT after connecting (default 0). DuckDB 2.0 build.
Parameter timeout_ms Type BIGINT Required Optional Description Timeout in milliseconds for connecting and for each wait for reply data; overrides the redis_timeout_ms setting. 0 waits forever (the query can still be interrupted). DuckDB 2.0 build.
Examples
1

Local Redis without auth

CREATE SECRET IF NOT EXISTS redis (
  TYPE redis,
  PROVIDER config,
  host 'localhost',
  port '6379'
);
2

Redis Cloud endpoint with a password

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

ACL user, database 2 and a 5 second timeout (DuckDB 2.0 build)

CREATE SECRET IF NOT EXISTS redis_reports (
  TYPE redis,
  PROVIDER config,
  host 'cache.internal',
  port '6379',
  username 'reporting',
  password 'xxxxxx',
  db 2,
  timeout_ms 5000
);

Practical Examples

Cookbook

Real-world recipes and patterns for common use cases.

Platform Support

Compatibility

Extension availability may vary by platform and DuckDB version. Check below to ensure this extension supports your environment before installation.

Quick Facts

Release status Experimental
Software License MIT
Pricing Free
Written In C++
Source Available Yes
View on GitHub
Usage
113,878
loads · last 90 days

Platforms

DuckDB 2.0.0

  • Linux x86_64aarch64
  • Linux (musl) Not available
  • macOS Apple Silicon
  • Windows x86_64x86_64 (MinGW)
  • WASM Not available
Compiled binary sizes
Platform Architecture Size
Linux x86_64 4.16 MB
Linux aarch64 3.51 MB
macOS Apple Silicon 2.96 MB
Windows x86_64 10.26 MB
Windows x86_64 (MinGW) 17.90 MB

Compressed download sizes for the release shown above.

DuckDB & Haybarn

Release calendar
  • DuckDB v2.0.0 Query.Farm repository Supported
  • Haybarn v1.5.6 Built-in community repository Supported

Browser examples use Haybarn-Wasm 2.0.0-rc12.

Checked .

Learn and explore

Tutorials and articles

Writing about Redis: how it works, what changed, and why.