redis
redis
pg_redis_pubsub : Send redis pub/sub messages to Redis from PostgreSQL Directly
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 8720 | redis
|
pg_redis_pubsub
|
0.0.1 |
FDW
|
MIT
|
C
|
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
--s-d-r
|
No
|
Yes
|
No
|
Yes
|
yes
|
no
|
| Relationships | |
|---|---|
| See Also | redis_fdw
spat
pgmemcache
pg_net
wrappers
kafka_fdw
pgmq
multicorn
|
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PIGSTY
|
0.0.1 |
18
17
16
15
14
|
pg_redis_pubsub |
- |
| RPM | PIGSTY
|
0.0.1 |
18
17
16
15
14
|
pg_redis_pubsub_$v |
- |
| DEB | PIGSTY
|
0.0.1 |
18
17
16
15
14
|
postgresql-$v-pg-redis-pubsub |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
el8.x86_64
|
PIGSTY 0.0.1
|
PIGSTY 0.0.1
|
PIGSTY 0.0.1
|
PIGSTY 0.0.1
|
PIGSTY 0.0.1
|
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
|
PIGSTY 0.0.1
|
PIGSTY 0.0.1
|
PIGSTY 0.0.1
|
PIGSTY 0.0.1
|
PIGSTY 0.0.1
|
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
|
Source
pig build pkg pg_redis_pubsub; # build rpm/debInstall
Make sure PGDG and PIGSTY repo available:
pig repo add pgsql -u # add both repo and update cacheInstall this extension with pig:
pig install pg_redis_pubsub; # install via package name, for the active PG version
pig install redis; # install by extension name, for the current active PG version
pig install redis -v 18; # install for PG 18
pig install redis -v 17; # install for PG 17
pig install redis -v 16; # install for PG 16
pig install redis -v 15; # install for PG 15
pig install redis -v 14; # install for PG 14Create this extension with:
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.
Last updated on