跳转到主要内容

redis

从PG向Redis发送Pub/Sub消息

pg_redis_pubsub · 从PG向Redis发送Pub/Sub消息

概览

ID扩展软件包版本类别许可证编程语言
8720redispg_redis_pubsub0.0.1FDWMITC
属性可执行文件动态库需要预加载需要建扩展可迁移可信
--s-d-r否是否是是否

软件包

类型仓库版本兼容的 PostgreSQL 大版本包名模式依赖
EXTPIGSTY0.0.119 18 17 16 15pg_redis_pubsub-
RPMPIGSTY0.0.119 18 17 16 15pg_redis_pubsub_$v-
DEBPIGSTY0.0.119 18 17 16 15postgresql-$v-pg-redis-pubsub-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
el8.aarch64N/APIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
el9.x86_64PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
el9.aarch64PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
el10.x86_64PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
el10.aarch64PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
d12.x86_64PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
d12.aarch64PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
d13.x86_64PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
d13.aarch64PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
u22.x86_64PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
u22.aarch64PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
u24.x86_64PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
u24.aarch64PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
u26.x86_64PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
u26.aarch64PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
软件包版本平台仓库大小下载
pg_redis_pubsub_190.0.1el9.x86_64pigsty20.4 KiBpg_redis_pubsub_19-0.0.1-1PGSTY.el9.x86_64.rpm
pg_redis_pubsub_190.0.1el9.aarch64pigsty20.2 KiBpg_redis_pubsub_19-0.0.1-1PGSTY.el9.aarch64.rpm
pg_redis_pubsub_190.0.1el10.x86_64pigsty20.4 KiBpg_redis_pubsub_19-0.0.1-1PGSTY.el10.x86_64.rpm
pg_redis_pubsub_190.0.1el10.aarch64pigsty20.5 KiBpg_redis_pubsub_19-0.0.1-1PGSTY.el10.aarch64.rpm
postgresql-19-pg-redis-pubsub0.0.1d12.x86_64pigsty12.4 KiBpostgresql-19-pg-redis-pubsub_0.0.1-1PGSTY~bookworm_amd64.deb
postgresql-19-pg-redis-pubsub0.0.1d12.aarch64pigsty12.4 KiBpostgresql-19-pg-redis-pubsub_0.0.1-1PGSTY~bookworm_arm64.deb
postgresql-19-pg-redis-pubsub0.0.1d13.x86_64pigsty12.3 KiBpostgresql-19-pg-redis-pubsub_0.0.1-1PGSTY~trixie_amd64.deb
postgresql-19-pg-redis-pubsub0.0.1d13.aarch64pigsty12.4 KiBpostgresql-19-pg-redis-pubsub_0.0.1-1PGSTY~trixie_arm64.deb
postgresql-19-pg-redis-pubsub0.0.1u22.x86_64pigsty12.7 KiBpostgresql-19-pg-redis-pubsub_0.0.1-1PGSTY~jammy_amd64.deb
postgresql-19-pg-redis-pubsub0.0.1u22.aarch64pigsty12.6 KiBpostgresql-19-pg-redis-pubsub_0.0.1-1PGSTY~jammy_arm64.deb
postgresql-19-pg-redis-pubsub0.0.1u24.x86_64pigsty12.9 KiBpostgresql-19-pg-redis-pubsub_0.0.1-1PGSTY~noble_amd64.deb
postgresql-19-pg-redis-pubsub0.0.1u24.aarch64pigsty12.9 KiBpostgresql-19-pg-redis-pubsub_0.0.1-1PGSTY~noble_arm64.deb
postgresql-19-pg-redis-pubsub0.0.1u26.x86_64pigsty12.9 KiBpostgresql-19-pg-redis-pubsub_0.0.1-1PGSTY~resolute_amd64.deb
postgresql-19-pg-redis-pubsub0.0.1u26.aarch64pigsty13.0 KiBpostgresql-19-pg-redis-pubsub_0.0.1-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_redis_pubsub_180.0.1el8.x86_64pigsty20.1 KiBpg_redis_pubsub_18-0.0.1-1PGSTY.el8.x86_64.rpm
pg_redis_pubsub_180.0.1el8.aarch64pigsty20.2 KiBpg_redis_pubsub_18-0.0.1-1PGSTY.el8.aarch64.rpm
pg_redis_pubsub_180.0.1el9.x86_64pigsty20.4 KiBpg_redis_pubsub_18-0.0.1-1PGSTY.el9.x86_64.rpm
pg_redis_pubsub_180.0.1el9.aarch64pigsty20.2 KiBpg_redis_pubsub_18-0.0.1-1PGSTY.el9.aarch64.rpm
pg_redis_pubsub_180.0.1el10.x86_64pigsty20.4 KiBpg_redis_pubsub_18-0.0.1-1PGSTY.el10.x86_64.rpm
pg_redis_pubsub_180.0.1el10.aarch64pigsty20.5 KiBpg_redis_pubsub_18-0.0.1-1PGSTY.el10.aarch64.rpm
postgresql-18-pg-redis-pubsub0.0.1d12.x86_64pigsty12.4 KiBpostgresql-18-pg-redis-pubsub_0.0.1-1PGSTY~bookworm_amd64.deb
postgresql-18-pg-redis-pubsub0.0.1d12.aarch64pigsty12.4 KiBpostgresql-18-pg-redis-pubsub_0.0.1-1PGSTY~bookworm_arm64.deb
postgresql-18-pg-redis-pubsub0.0.1d13.x86_64pigsty12.3 KiBpostgresql-18-pg-redis-pubsub_0.0.1-1PGSTY~trixie_amd64.deb
postgresql-18-pg-redis-pubsub0.0.1d13.aarch64pigsty12.4 KiBpostgresql-18-pg-redis-pubsub_0.0.1-1PGSTY~trixie_arm64.deb
postgresql-18-pg-redis-pubsub0.0.1u22.x86_64pigsty12.7 KiBpostgresql-18-pg-redis-pubsub_0.0.1-1PGSTY~jammy_amd64.deb
postgresql-18-pg-redis-pubsub0.0.1u22.aarch64pigsty12.6 KiBpostgresql-18-pg-redis-pubsub_0.0.1-1PGSTY~jammy_arm64.deb
postgresql-18-pg-redis-pubsub0.0.1u24.x86_64pigsty12.9 KiBpostgresql-18-pg-redis-pubsub_0.0.1-1PGSTY~noble_amd64.deb
postgresql-18-pg-redis-pubsub0.0.1u24.aarch64pigsty12.9 KiBpostgresql-18-pg-redis-pubsub_0.0.1-1PGSTY~noble_arm64.deb
postgresql-18-pg-redis-pubsub0.0.1u26.x86_64pigsty12.9 KiBpostgresql-18-pg-redis-pubsub_0.0.1-1PGSTY~resolute_amd64.deb
postgresql-18-pg-redis-pubsub0.0.1u26.aarch64pigsty13.0 KiBpostgresql-18-pg-redis-pubsub_0.0.1-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_redis_pubsub_170.0.1el8.x86_64pigsty20.1 KiBpg_redis_pubsub_17-0.0.1-1PGSTY.el8.x86_64.rpm
pg_redis_pubsub_170.0.1el8.aarch64pigsty20.1 KiBpg_redis_pubsub_17-0.0.1-1PGSTY.el8.aarch64.rpm
pg_redis_pubsub_170.0.1el9.x86_64pigsty20.3 KiBpg_redis_pubsub_17-0.0.1-1PGSTY.el9.x86_64.rpm
pg_redis_pubsub_170.0.1el9.aarch64pigsty20.2 KiBpg_redis_pubsub_17-0.0.1-1PGSTY.el9.aarch64.rpm
pg_redis_pubsub_170.0.1el10.x86_64pigsty20.4 KiBpg_redis_pubsub_17-0.0.1-1PGSTY.el10.x86_64.rpm
pg_redis_pubsub_170.0.1el10.aarch64pigsty20.6 KiBpg_redis_pubsub_17-0.0.1-1PGSTY.el10.aarch64.rpm
postgresql-17-pg-redis-pubsub0.0.1d12.x86_64pigsty12.3 KiBpostgresql-17-pg-redis-pubsub_0.0.1-1PGSTY~bookworm_amd64.deb
postgresql-17-pg-redis-pubsub0.0.1d12.aarch64pigsty12.4 KiBpostgresql-17-pg-redis-pubsub_0.0.1-1PGSTY~bookworm_arm64.deb
postgresql-17-pg-redis-pubsub0.0.1d13.x86_64pigsty12.3 KiBpostgresql-17-pg-redis-pubsub_0.0.1-1PGSTY~trixie_amd64.deb
postgresql-17-pg-redis-pubsub0.0.1d13.aarch64pigsty12.4 KiBpostgresql-17-pg-redis-pubsub_0.0.1-1PGSTY~trixie_arm64.deb
postgresql-17-pg-redis-pubsub0.0.1u22.x86_64pigsty13.2 KiBpostgresql-17-pg-redis-pubsub_0.0.1-1PGSTY~jammy_amd64.deb
postgresql-17-pg-redis-pubsub0.0.1u22.aarch64pigsty13.0 KiBpostgresql-17-pg-redis-pubsub_0.0.1-1PGSTY~jammy_arm64.deb
postgresql-17-pg-redis-pubsub0.0.1u24.x86_64pigsty12.9 KiBpostgresql-17-pg-redis-pubsub_0.0.1-1PGSTY~noble_amd64.deb
postgresql-17-pg-redis-pubsub0.0.1u24.aarch64pigsty12.8 KiBpostgresql-17-pg-redis-pubsub_0.0.1-1PGSTY~noble_arm64.deb
postgresql-17-pg-redis-pubsub0.0.1u26.x86_64pigsty12.9 KiBpostgresql-17-pg-redis-pubsub_0.0.1-1PGSTY~resolute_amd64.deb
postgresql-17-pg-redis-pubsub0.0.1u26.aarch64pigsty13.0 KiBpostgresql-17-pg-redis-pubsub_0.0.1-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_redis_pubsub_160.0.1el8.x86_64pigsty20.1 KiBpg_redis_pubsub_16-0.0.1-1PGSTY.el8.x86_64.rpm
pg_redis_pubsub_160.0.1el8.aarch64pigsty20.1 KiBpg_redis_pubsub_16-0.0.1-1PGSTY.el8.aarch64.rpm
pg_redis_pubsub_160.0.1el9.x86_64pigsty20.3 KiBpg_redis_pubsub_16-0.0.1-1PGSTY.el9.x86_64.rpm
pg_redis_pubsub_160.0.1el9.aarch64pigsty20.1 KiBpg_redis_pubsub_16-0.0.1-1PGSTY.el9.aarch64.rpm
pg_redis_pubsub_160.0.1el10.x86_64pigsty20.4 KiBpg_redis_pubsub_16-0.0.1-1PGSTY.el10.x86_64.rpm
pg_redis_pubsub_160.0.1el10.aarch64pigsty20.5 KiBpg_redis_pubsub_16-0.0.1-1PGSTY.el10.aarch64.rpm
postgresql-16-pg-redis-pubsub0.0.1d12.x86_64pigsty12.3 KiBpostgresql-16-pg-redis-pubsub_0.0.1-1PGSTY~bookworm_amd64.deb
postgresql-16-pg-redis-pubsub0.0.1d12.aarch64pigsty12.4 KiBpostgresql-16-pg-redis-pubsub_0.0.1-1PGSTY~bookworm_arm64.deb
postgresql-16-pg-redis-pubsub0.0.1d13.x86_64pigsty12.3 KiBpostgresql-16-pg-redis-pubsub_0.0.1-1PGSTY~trixie_amd64.deb
postgresql-16-pg-redis-pubsub0.0.1d13.aarch64pigsty12.4 KiBpostgresql-16-pg-redis-pubsub_0.0.1-1PGSTY~trixie_arm64.deb
postgresql-16-pg-redis-pubsub0.0.1u22.x86_64pigsty13.2 KiBpostgresql-16-pg-redis-pubsub_0.0.1-1PGSTY~jammy_amd64.deb
postgresql-16-pg-redis-pubsub0.0.1u22.aarch64pigsty13.1 KiBpostgresql-16-pg-redis-pubsub_0.0.1-1PGSTY~jammy_arm64.deb
postgresql-16-pg-redis-pubsub0.0.1u24.x86_64pigsty12.9 KiBpostgresql-16-pg-redis-pubsub_0.0.1-1PGSTY~noble_amd64.deb
postgresql-16-pg-redis-pubsub0.0.1u24.aarch64pigsty12.8 KiBpostgresql-16-pg-redis-pubsub_0.0.1-1PGSTY~noble_arm64.deb
postgresql-16-pg-redis-pubsub0.0.1u26.x86_64pigsty12.9 KiBpostgresql-16-pg-redis-pubsub_0.0.1-1PGSTY~resolute_amd64.deb
postgresql-16-pg-redis-pubsub0.0.1u26.aarch64pigsty13.0 KiBpostgresql-16-pg-redis-pubsub_0.0.1-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_redis_pubsub_150.0.1el8.x86_64pigsty20.2 KiBpg_redis_pubsub_15-0.0.1-1PGSTY.el8.x86_64.rpm
pg_redis_pubsub_150.0.1el8.aarch64pigsty20.2 KiBpg_redis_pubsub_15-0.0.1-1PGSTY.el8.aarch64.rpm
pg_redis_pubsub_150.0.1el9.x86_64pigsty20.4 KiBpg_redis_pubsub_15-0.0.1-1PGSTY.el9.x86_64.rpm
pg_redis_pubsub_150.0.1el9.aarch64pigsty20.3 KiBpg_redis_pubsub_15-0.0.1-1PGSTY.el9.aarch64.rpm
pg_redis_pubsub_150.0.1el10.x86_64pigsty20.5 KiBpg_redis_pubsub_15-0.0.1-1PGSTY.el10.x86_64.rpm
pg_redis_pubsub_150.0.1el10.aarch64pigsty20.6 KiBpg_redis_pubsub_15-0.0.1-1PGSTY.el10.aarch64.rpm
postgresql-15-pg-redis-pubsub0.0.1d12.x86_64pigsty12.4 KiBpostgresql-15-pg-redis-pubsub_0.0.1-1PGSTY~bookworm_amd64.deb
postgresql-15-pg-redis-pubsub0.0.1d12.aarch64pigsty12.4 KiBpostgresql-15-pg-redis-pubsub_0.0.1-1PGSTY~bookworm_arm64.deb
postgresql-15-pg-redis-pubsub0.0.1d13.x86_64pigsty12.4 KiBpostgresql-15-pg-redis-pubsub_0.0.1-1PGSTY~trixie_amd64.deb
postgresql-15-pg-redis-pubsub0.0.1d13.aarch64pigsty12.5 KiBpostgresql-15-pg-redis-pubsub_0.0.1-1PGSTY~trixie_arm64.deb
postgresql-15-pg-redis-pubsub0.0.1u22.x86_64pigsty13.2 KiBpostgresql-15-pg-redis-pubsub_0.0.1-1PGSTY~jammy_amd64.deb
postgresql-15-pg-redis-pubsub0.0.1u22.aarch64pigsty13.1 KiBpostgresql-15-pg-redis-pubsub_0.0.1-1PGSTY~jammy_arm64.deb
postgresql-15-pg-redis-pubsub0.0.1u24.x86_64pigsty13.0 KiBpostgresql-15-pg-redis-pubsub_0.0.1-1PGSTY~noble_amd64.deb
postgresql-15-pg-redis-pubsub0.0.1u24.aarch64pigsty12.9 KiBpostgresql-15-pg-redis-pubsub_0.0.1-1PGSTY~noble_arm64.deb
postgresql-15-pg-redis-pubsub0.0.1u26.x86_64pigsty13.0 KiBpostgresql-15-pg-redis-pubsub_0.0.1-1PGSTY~resolute_amd64.deb
postgresql-15-pg-redis-pubsub0.0.1u26.aarch64pigsty13.1 KiBpostgresql-15-pg-redis-pubsub_0.0.1-1PGSTY~resolute_arm64.deb

源码

pig build pkg pg_redis_pubsub;		# build rpm/deb

安装

启用 PGDG 和 PIGSTY 仓库并更新缓存。

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

使用 pig 安装扩展。

pig install pg_redis_pubsub;		# install by package name
pig install redis;		# install by extension name

pig install redis -v 19;   # install for PG 19
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

在数据库中创建扩展。

CREATE EXTENSION redis;

用法

redis: 从 PostgreSQL 直接向 Redis 发送发布/订阅消息

redis 扩展(pg_redis_pubsub)允许 PostgreSQL 向 Redis 发布/订阅频道发布消息。目前仅支持发布端。

配置

通过 GUC 变量设置 Redis 连接参数:

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

也可以在数据库、角色或会话级别设置:

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

基本用法

CREATE EXTENSION redis;

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

可用函数

函数描述
redis_connect()使用 redis.host 和 redis.port 设置连接 Redis
redis_disconnect()断开 Redis 连接
redis_publish(channel text, message text)在指定频道发布消息
redis_status()返回 Redis 客户端状态

注意:redis_publish 在没有连接时会自动连接。

触发器示例

当表被修改时向 Redis 发布变更事件:

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();

这允许监听 Redis 频道的外部订阅者实时响应 PostgreSQL 数据变更。

表格阅读器