{"id":13705717,"url":"https://github.com/brettlaforge/pg_redis_pubsub","last_synced_at":"2025-05-05T16:33:48.483Z","repository":{"id":150195593,"uuid":"102603134","full_name":"brettlaforge/pg_redis_pubsub","owner":"brettlaforge","description":"Redis Publish from PostgreSQL","archived":false,"fork":false,"pushed_at":"2019-11-05T00:25:00.000Z","size":17,"stargazers_count":21,"open_issues_count":0,"forks_count":7,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-08-03T22:15:50.303Z","etag":null,"topics":["hiredis","postgresql","postgresql-extension","redis"],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brettlaforge.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-09-06T11:59:32.000Z","updated_at":"2023-12-28T02:20:11.000Z","dependencies_parsed_at":null,"dependency_job_id":"ff4a335d-9590-4cf0-ad25-f4884970e0dc","html_url":"https://github.com/brettlaforge/pg_redis_pubsub","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brettlaforge%2Fpg_redis_pubsub","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brettlaforge%2Fpg_redis_pubsub/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brettlaforge%2Fpg_redis_pubsub/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brettlaforge%2Fpg_redis_pubsub/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brettlaforge","download_url":"https://codeload.github.com/brettlaforge/pg_redis_pubsub/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224455911,"owners_count":17314204,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hiredis","postgresql","postgresql-extension","redis"],"created_at":"2024-08-02T22:00:46.618Z","updated_at":"2024-11-13T13:30:49.718Z","avatar_url":"https://github.com/brettlaforge.png","language":"C","funding_links":[],"categories":["C"],"sub_categories":[],"readme":"# Redis Publish PostgreSQL Extension\n\nThis PostgreSQL extension allows you to connect to Redis and publish messages on a Redis channel from PostgreSQL.\n\n## Requirements\n\nTo build you must have:\n\n- PostgreSQL 9.1+\n- HIREDIS C Client 13.0+\n\n#### HIREDIS\n\nThe [HIREDIS C client library](https://github.com/redis/hiredis) is a minimalistic C client library for the Redis database.\n\nOn Ubuntu 12.04+, it can be installed using the apt-get package [libhiredis-dev](https://launchpad.net/ubuntu/+source/hiredis).\n\n```sh\nsudo apt-get install libhiredis-dev\n```\n\nOn Centos 7.6 you should build HIREDIS from source, or search for recent RPMs as system repository only has version 12 available which is too old for `pg_redis_pubsub`. For example, you can use [hiredis-last-0.13.3-1.el7.remi.x86_64.rpm](https://rpms.southbridge.ru/rhel7/stable/x86_64/hiredis-last-0.13.3-1.el7.remi.x86_64.rpm) and [hiredis-last-devel-0.13.3-1.el7.remi.x86_64.rpm](https://rpms.southbridge.ru/rhel7/stable/x86_64/hiredis-last-devel-0.13.3-1.el7.remi.x86_64.rpm). Download two RPMs and run:\n\n```sh\nsudo yum install \\\n  hiredis-last-devel-0.13.3-1.el7.remi.x86_64.rpm \\\n  hiredis-last-0.13.3-1.el7.remi.x86_64.rpm\n```\n\n## Installation\n\nThis code is a standard PostgreSQL extension so all you need to run is:\n\n```sh\nmake clean install\n```\n\nAnd then in the database:\n\n```sql\nCREATE EXTENSION redis;\n```\n\n## Settings\n\nSettings can be \n* specified globally using `postgresql.conf` or `ALTER SYSTEM ... SET var = 'val'`\n* specified at the database level using `ALTER DATABASE ... SET var = 'val'`\n* specified at the role level using `ALTER ROLE ... SET var = 'val'`\n* specified at the session level using `SET var = 'val'`\n\n### GUC settings\n\nYou can set/change the following variables with commands described above:\n\n* **redis.host** - Redis client host setting.\n* **redis.port** - Redis client port setting.\n\n## Usage\n\n**redis_status**()\n\nReturns the status of the Redis client.\n\n**redis_connect**()\n\nConnects the Redis client using the **redis.host** and **redis.port** configuratin settings.\n\n**redis_disconnect**()\n\nDisconnects the Redis client.\n\n**redis_publish**(*channel* text, *message* text)\n\nPublishes a message on the channel provided.\n\nIf the Redis client is not currently connected, it will first create a new connection before attempting to publish the message.\n\n## Roadmap\n\n- Return record with columns host text, port int, connected boolean.\n- Add a set of Redis connections to use?\n- Add subscribe and psubscribe support that executes a PostgreSQL function?\n\n## Examples\n\n### Basic Example\n\n```sql\nCREATE EXTENSION IF NOT EXISTS redis;\n\nSELECT redis_connect();\n\nSELECT redis_publish('mychannel', 'Hello World');\n\nSELECT redis_disconnect();\n```\n\n### Trigger Example\n\n```sql\nCREATE EXTENSION IF NOT EXISTS redis;\n\nCREATE TABLE IF NOT EXISTS products (\n    id serial,\n    name varchar(255)\n);\n\nCREATE OR REPLACE FUNCTION after_change()\n    RETURNS TRIGGER AS\n    $$\n        DECLARE\n            channel text;\n            message json;\n        BEGIN\n            channel = 'products:' || NEW.id::text;\n            message = to_jsonb(NEW);\n\n            PERFORM redis_publish(channel, message::text);\n            RETURN NULL;\n        END;\n    $$\n    LANGUAGE plpgsql;\n\nCREATE TRIGGER products_after_change\n    AFTER INSERT OR UPDATE ON products\n    FOR EACH ROW\n    EXECUTE PROCEDURE after_change();\n\nINSERT INTO products (name) VALUES ('Ale'), ('Beer'), ('Cider');\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrettlaforge%2Fpg_redis_pubsub","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrettlaforge%2Fpg_redis_pubsub","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrettlaforge%2Fpg_redis_pubsub/lists"}