redis

Send redis pub/sub messages to Redis from PostgreSQL Directly

Overview

PackageVersionCategoryLicenseLanguage
pg_redis_pubsub0.0.1FDWMITC
IDExtensionBinLibLoadCreateTrustRelocSchema
8720redisNoYesNoYesNoYes-
Relatedredis_fdw spat pgmemcache pg_net wrappers kafka_fdw pgmq multicorn

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY0.0.11817161514pg_redis_pubsub-
RPMPIGSTY0.0.11817161514pg_redis_pubsub_$v-
DEBPIGSTY0.0.11817161514postgresql-$v-pg-redis-pubsub-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
el9.x86_64
el9.aarch64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
el10.x86_64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
el10.aarch64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
d12.x86_64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
d12.aarch64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
d13.x86_64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
d13.aarch64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
u22.x86_64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
u22.aarch64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
u24.x86_64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
u24.aarch64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1

Build

You can build the RPM / DEB packages for pg_redis_pubsub using pig build:

pig build pkg pg_redis_pubsub         # build RPM / DEB packages

Install

You can install pg_redis_pubsub directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:

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

Install the extension using pig or apt/yum/dnf:

pig install pg_redis_pubsub;          # Install for current active PG version
pig ext install -y pg_redis_pubsub -v 18  # PG 18
pig ext install -y pg_redis_pubsub -v 17  # PG 17
pig ext install -y pg_redis_pubsub -v 16  # PG 16
pig ext install -y pg_redis_pubsub -v 15  # PG 15
pig ext install -y pg_redis_pubsub -v 14  # PG 14
dnf install -y pg_redis_pubsub_18       # PG 18
dnf install -y pg_redis_pubsub_17       # PG 17
dnf install -y pg_redis_pubsub_16       # PG 16
dnf install -y pg_redis_pubsub_15       # PG 15
dnf install -y pg_redis_pubsub_14       # PG 14
apt install -y postgresql-18-pg-redis-pubsub   # PG 18
apt install -y postgresql-17-pg-redis-pubsub   # PG 17
apt install -y postgresql-16-pg-redis-pubsub   # PG 16
apt install -y postgresql-15-pg-redis-pubsub   # PG 15
apt install -y postgresql-14-pg-redis-pubsub   # PG 14

Create Extension:

CREATE EXTENSION redis;

Usage

redis: Send Redis pub/sub messages to Redis from PostgreSQL directly

The redis extension (pg_redis_pubsub) allows PostgreSQL to publish messages to Redis pub/sub channels. Currently, only the publish side is supported.

Configuration

Set the Redis connection parameters via GUC variables:

ALTER SYSTEM SET redis.host = '127.0.0.1';
ALTER SYSTEM SET redis.port = '6379';
SELECT pg_reload_conf();

These can also be set at the database, role, or session level:

SET redis.host = '127.0.0.1';
SET redis.port = '6379';

Basic Usage

CREATE EXTENSION redis;

SELECT redis_connect();
SELECT redis_publish('mychannel', 'Hello World');
SELECT redis_disconnect();

Available Functions

FunctionDescription
redis_connect()Connect to Redis using redis.host and redis.port settings
redis_disconnect()Disconnect from Redis
redis_publish(channel text, message text)Publish a message on the specified channel
redis_status()Return the status of the Redis client

Note: redis_publish automatically connects if no connection exists.

Trigger Example

Publish change events to Redis whenever a table is modified:

CREATE OR REPLACE FUNCTION notify_changes()
RETURNS TRIGGER AS $$
BEGIN
  PERFORM redis_publish(
    'products:' || NEW.id::text,
    to_jsonb(NEW)::text
  );
  RETURN NULL;
END;
$$ LANGUAGE plpgsql;

CREATE TRIGGER on_product_change
  AFTER INSERT OR UPDATE ON products
  FOR EACH ROW EXECUTE PROCEDURE notify_changes();

This allows external subscribers listening on Redis channels to react to PostgreSQL data changes in real time.


Last Modified 2026-03-12: add pg extension catalog (95749bf)