Skip to content

Redis

Read and write Redis from DuckDB SQL.

239,424
extension loads ยท last 90 days
On this page

Technical Overview

Reach the cache without the app-layer glue

What it is

How it works

  • โ€ข Secret-based configuration: A redis secret holds host, port, and an optional password. See CREATE SECRET; parameterize the password from the environment so it never lands in a cached query plan.
  • โ€ข RESP over TCP: The extension speaks the native Redis Serialization Protocol directly over a plain TCP socket โ€” no separate Redis daemon, sidecar, or driver process is involved.
  • โ€ข Connection reuse: Connections to a given secret are pooled and reused across calls rather than reopened per row, so per-row lookups inside a SELECT and streaming table functions amortize the connection cost.

Production caveats

  • โ€ข Use SCAN, not KEYS: KEYS blocks the Redis server for the duration of the scan โ€” fine in dev, dangerous on production keyspaces. Prefer the cursor-paginated SCAN-backed functions, which iterate without stalling traffic.
  • โ€ข Strings, hashes, and lists only: No SET / ZSET / STREAM / PUB-SUB / TRANSACTIONS / SCRIPTING today. See Redis data types for what's supported elsewhere.
  • โ€ข Single-node connections: No Redis Cluster topology awareness. Point the secret at a single endpoint.
  • โ€ข Plaintext auth: The password field in the secret is sent over plain TCP โ€” TLS is not yet wired up. Use the extension on trusted networks until that lands. See Redis security for the upstream guidance.
  • โ€ข Experimental status: The function surface may change as more Redis primitives land. Pin a known-good extension version in production CTAS jobs.

Deep Dive

Technical Details

Install

INSTALL redis FROM community;
LOAD redis;

Quick Start

Connect via a secret

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

Read and write strings

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

SELECT redis_set('user:1', 'John Doe', 'redis') AS ok;
SELECT redis_get('user:1', 'redis') AS name;

Discover keys matching a pattern

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

SELECT * FROM redis_keys('user:*', 'redis');

Reference

Extension Contents

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

Name Description
Cache / In-memory store
redis Redis connection details.
Hashes
redis_hget() Get the value of a hash field.
redis_hgetall() List all (field, value) pairs of a hash as a table.
redis_hscan() Cursor-paginated scan of a hash's fields.
redis_hscan_over_scan() For every key matching a SCAN pattern, run HSCAN and emit (key, field, value) rows.
redis_hset() Set the value of a hash field.
Keys
redis_del() Delete a key.
redis_exists() Check whether a key exists.
redis_keys() List all keys matching a pattern as a table.
redis_scan() Cursor-paginated SCAN of the keyspace.
redis_type() Get the Redis type of a key (string / list / hash / set / zset / stream / none).
Lists
redis_lpush() Push a value onto the head of a list.
redis_lrange() Get a range from a list as a comma-separated string.
redis_lrange_table() Get a range from a list as a table โ€” one row per element.
Strings
redis_get() Get the value of a string key.
redis_mget() Get multiple values in one round-trip.
redis_set() Set the value of a string key.

API Reference

Function Documentation

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.
Examples
1

Local Redis without auth

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

Redis Cloud with TLS endpoint

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

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
239,424
loads ยท last 90 days

Platforms

  • Linux x86_64 aarch64
  • Linux (musl) Not available
  • macOS Intel Apple Silicon
  • Windows x86_64
  • WASM Not available
Compiled binary sizes
Platform Architecture Size
Linux x86_64 3.40 MB
Linux aarch64 3.02 MB
macOS Intel 1.62 MB
macOS Apple Silicon 1.47 MB
Windows x86_64 7.45 MB

Compressed download size from the Haybarn extension repository.

DuckDB & Haybarn

Release calendar