redis
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_redis_pubsub | 0.0.1 | FDW | MIT | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 8720 | redis | No | Yes | No | Yes | No | Yes | - |
| Related | redis_fdw spat pgmemcache pg_net wrappers kafka_fdw pgmq multicorn |
|---|
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 0.0.1 | 1817161514 | pg_redis_pubsub | - |
| RPM | PIGSTY | 0.0.1 | 1817161514 | pg_redis_pubsub_$v | - |
| DEB | PIGSTY | 0.0.1 | 1817161514 | postgresql-$v-pg-redis-pubsub | - |
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
| Function | Description |
|---|---|
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.
Feedback
Was this page helpful?
Thanks for the feedback! Please let us know how we can improve.
Sorry to hear that. Please let us know how we can improve.