{"id":21252613,"url":"https://github.com/jcasbin/redis-watcher","last_synced_at":"2025-07-11T01:33:04.133Z","repository":{"id":38314710,"uuid":"357152547","full_name":"jcasbin/redis-watcher","owner":"jcasbin","description":"Redis watcher for jCasbin","archived":false,"fork":false,"pushed_at":"2024-09-27T16:25:32.000Z","size":36,"stargazers_count":4,"open_issues_count":0,"forks_count":12,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-09T20:08:22.514Z","etag":null,"topics":["abac","acl","auth","authorization","authz","casbin","java","jcasbin","rbac","redis","watcher"],"latest_commit_sha":null,"homepage":"https://github.com/casbin/jcasbin","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jcasbin.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-04-12T10:34:18.000Z","updated_at":"2024-09-27T16:24:24.000Z","dependencies_parsed_at":"2024-05-17T10:40:18.481Z","dependency_job_id":null,"html_url":"https://github.com/jcasbin/redis-watcher","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcasbin%2Fredis-watcher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcasbin%2Fredis-watcher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcasbin%2Fredis-watcher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcasbin%2Fredis-watcher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jcasbin","download_url":"https://codeload.github.com/jcasbin/redis-watcher/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225669664,"owners_count":17505386,"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":["abac","acl","auth","authorization","authz","casbin","java","jcasbin","rbac","redis","watcher"],"created_at":"2024-11-21T03:48:06.644Z","updated_at":"2024-11-21T03:48:07.153Z","avatar_url":"https://github.com/jcasbin.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"Redis Watcher \n---\n\n[![GitHub Actions](https://github.com/jcasbin/redis-watcher/actions/workflows/maven-ci.yml/badge.svg)](https://github.com/jcasbin/redis-watcher/actions/workflows/maven-ci.yml)\n![License](https://img.shields.io/github/license/jcasbin/redis-watcher)\n[![Javadoc](https://javadoc.io/badge2/org.casbin/jcasbin-redis-watcher/javadoc.svg)](https://javadoc.io/doc/org.casbin/jcasbin-redis-watcher)\n[![codecov](https://codecov.io/gh/jcasbin/redis-watcher/branch/master/graph/badge.svg?token=ENt9xr4nFg)](https://codecov.io/gh/jcasbin/redis-watcher)\n[![codebeat badge](https://codebeat.co/badges/8b3da1c4-3a61-4123-a3d4-002b2598a297)](https://codebeat.co/projects/github-com-jcasbin-redis-watcher-master)\n[![Maven Central](https://img.shields.io/maven-central/v/org.casbin/jcasbin-redis-watcher.svg)](https://mvnrepository.com/artifact/org.casbin/jcasbin-redis-watcher/latest)\n[![Release](https://img.shields.io/github/release/jcasbin/redis-watcher.svg)](https://github.com/jcasbin/redis-watcher/releases/latest)\n[![Discord](https://img.shields.io/discord/1022748306096537660?logo=discord\u0026label=discord\u0026color=5865F2)](https://discord.gg/S5UjpzGZjN)\n\n\nRedis Watcher is a [Redis](http://redis.io) watcher for [jCasbin](https://github.com/casbin/jcasbin).\n\n## Installation\n\n**For Maven**\n\n ```\n \u003cdependency\u003e\n     \u003cgroupId\u003eorg.casbin\u003c/groupId\u003e\n     \u003cartifactId\u003ejcasbin-redis-watcher\u003c/artifactId\u003e\n     \u003cversion\u003e1.0-SNAPSHOT\u003c/version\u003e\n \u003c/dependency\u003e\n ```\n\n## Publish and Subscribe\n\nPlease learn redis [publish and subscribe](https://redisbook.readthedocs.io/en/latest/feature/pubsub.html) first.\n\nCreating a ``redis-watcher`` will create a new thread for subscribing to the ``topic (Channel)`` of redis. Multiple instances create multiple watchers and corresponding threads subscribe to the same topic. When one of the instances executes the action of the update policy (such as ``e.addPolicy``, ``e.removePolicy`` ...), it will send a message to the topic, and then other instances that have subscribed to the topic will receive the notification and execute the ``updateCallback`` method. The default ``updateCallback`` is to call ``e.LoadPolicy``, which is the reload policy. (When you call ``e.setWatcher(redisWatcher)``, it will set default updateCallback)\n\n## Simple Example\n\nif you have two casbin instances A and B\n\n**A:**  **Producer**\n\n```java\nString redisTopic=\"jcasbin-topic\";\nRedisWatcher redisWatcher = new RedisWatcher(\"127.0.0.1\",6379, redisTopic);\n// Support for connecting to redis with timeout and password\n// RedisWatcher redisWatcher = new RedisWatcher(\"127.0.0.1\",6379, redisTopic, 2000, \"foobared\");\n\nEnforcer enforcer = new SyncedEnforcer(\"examples/rbac_model.conf\", \"examples/rbac_policy.csv\");\nenforcer.setWatcher(redisWatcher);\n\n// The following code is not necessary and generally does not need to be written unless you understand what you want to do\n/*\nRunnable updateCallback = ()-\u003e{\n    // Custom behavior\n};\n\nredisWatcher.setUpdateCallback(updateCallback);\n*/\n\n// Modify policy, it will notify B\nenforcer.addPolicy(...);\n```\n\n**B:** **Consumer**\n\n````Java\nString redisTopic=\"jcasbin-topic\";\nRedisWatcher redisWatcher = new RedisWatcher(\"127.0.0.1\",6379, redisTopic);\n\nEnforcer enforcer = new SyncedEnforcer(\"examples/rbac_model.conf\", \"examples/rbac_policy.csv\");\nenforcer.setWatcher(redisWatcher);\n// B set watcher and subscribe redisTopic, then it will receive the notification of A, and then call LoadPolicy to reload policy\n````\n\n## Getting Help\n\n- [jCasbin](https://github.com/casbin/jCasbin)\n- [jedis](https://github.com/redis/jedis)\n\n## License\n\nThis project is under Apache 2.0 License. See the [LICENSE](https://github.com/jcasbin/redis-watcher/blob/master/LICENSE) file for the full license text.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcasbin%2Fredis-watcher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjcasbin%2Fredis-watcher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcasbin%2Fredis-watcher/lists"}