redis_fdw

redis_fdw

redis_fdw : Foreign data wrapper for querying a Redis server

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
8710
redis_fdw
redis_fdw
1.0
FDW
PostgreSQL
C
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--s-d-r
No
Yes
No
Yes
yes
no
Relationships
See Also
mongo_fdw
redis
kafka_fdw
wrappers
multicorn
spat
pgmemcache
odbc_fdw

multiple branch for different pg major versions

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXT
PIGSTY
1.0
18
17
16
15
14
redis_fdw-
RPM
PIGSTY
1.0
18
17
16
15
14
redis_fdw_$v-
DEB
PIGSTY
1.0
18
17
16
15
14
postgresql-$v-redis-fdw-
Linux / PGPG18PG17PG16PG15PG14
el8.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
el8.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
el9.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
el9.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
el10.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
el10.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
d12.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
d12.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
d13.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
d13.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
u22.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
u22.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
u24.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
u24.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0

Source

pig build pkg redis_fdw;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install redis_fdw;		# install via package name, for the active PG version

pig install redis_fdw -v 18;   # install for PG 18
pig install redis_fdw -v 17;   # install for PG 17
pig install redis_fdw -v 16;   # install for PG 16
pig install redis_fdw -v 15;   # install for PG 15
pig install redis_fdw -v 14;   # install for PG 14

Create this extension with:

CREATE EXTENSION redis_fdw;

Usage

redis_fdw: Foreign data wrapper for querying a Redis server

Create Server

CREATE EXTENSION redis_fdw;

CREATE SERVER redis_server FOREIGN DATA WRAPPER redis_fdw
  OPTIONS (address '127.0.0.1', port '6379');

Server Options: address (default 127.0.0.1), port (default 6379).

Create User Mapping

CREATE USER MAPPING FOR pguser SERVER redis_server
  OPTIONS (password 'secret');

Scalar Key-Value Pairs

CREATE FOREIGN TABLE redis_db0 (
  key text,
  val text
)
SERVER redis_server
OPTIONS (database '0');

SELECT * FROM redis_db0;

Hash Tables (with Key Prefix)

CREATE FOREIGN TABLE redis_hash (
  key text,
  val text[]
)
SERVER redis_server
OPTIONS (database '0', tabletype 'hash', tablekeyprefix 'mytable:');

INSERT INTO redis_hash VALUES ('mytable:r1', '{prop1,val1,prop2,val2}');
UPDATE redis_hash SET val = '{prop3,val3}' WHERE key = 'mytable:r1';
DELETE FROM redis_hash WHERE key = 'mytable:r1';
SELECT * FROM redis_hash;

Hash Tables (Singleton Key)

CREATE FOREIGN TABLE redis_singleton (
  key text,
  val text
)
SERVER redis_server
OPTIONS (database '0', tabletype 'hash', singleton_key 'myhash');

INSERT INTO redis_singleton VALUES ('field1', 'value1');
UPDATE redis_singleton SET val = 'newvalue' WHERE key = 'field1';
DELETE FROM redis_singleton WHERE key = 'field1';

Table Options

OptionDescription
databaseRedis database number (default 0)
tabletypehash, list, set, or zset (omit for scalar key-value)
tablekeyprefixFilter items by key prefix
tablekeysetFetch keys from a specific Redis set
singleton_keyAccess all values from a single Redis key

Use only one of tablekeyset or tablekeyprefix. Do not combine them with singleton_key.

Hash values are returned as alternating key-value pairs in a text[] array. Lists, sets, and sorted sets also return values as arrays.

Last updated on