casbin-redis-watcher
casbin-redis-watcher copied to clipboard
Redis watcher for Casbin https://github.com/casbin/casbin
Redis Watcher 
Redis Watcher is a Redis watcher for Casbin.
Installation
go get github.com/billcobbler/casbin-redis-watcher/v2
Simple Example
package main
import (
"github.com/casbin/casbin"
"github.com/casbin/casbin/util"
"github.com/billcobbler/casbin-redis-watcher/v2"
)
func updateCallback(msg string) {
util.LogPrint(msg)
}
func main() {
// Initialize the watcher.
// Use the Redis host as parameter.
w, _ := rediswatcher.NewWatcher("127.0.0.1:6379")
// Initialize the enforcer.
e := casbin.NewEnforcer("examples/rbac_model.conf", "examples/rbac_policy.csv")
// Set the watcher for the enforcer.
e.SetWatcher(w)
// Set callback to local example
w.SetUpdateCallback(updateCallback)
// Update the policy to test the effect.
// You should see "[casbin rules updated]" in the log.
e.SavePolicy()
}
Getting Help
License
This project is under Apache 2.0 License. See the LICENSE file for the full license text.