Redis Watcher
For Go 1.17+, use v2.4.0+ ,
For Go 1.16 and below, stay on v2.3.0.
Redis Watcher is a Redis watcher for Casbin.
Installation
go get github.com/casbin/redis-watcher/v2
Simple Example
package main
import (
"log"
"github.com/casbin/casbin/v2"
rediswatcher "github.com/casbin/redis-watcher/v2"
"github.com/redis/go-redis/v9"
)
func updateCallback(msg string) {
log.Println(msg)
}
func main() {
w, _ := rediswatcher.NewWatcher("localhost:6379", rediswatcher.WatcherOptions{
Options: redis.Options{
Network: "tcp",
Password: "",
},
Channel: "/casbin",
IgnoreSelf: false,
})
e, _ := casbin.NewEnforcer("examples/rbac_model.conf", "examples/rbac_policy.csv")
_ = e.SetWatcher(w)
_ = w.SetUpdateCallback(updateCallback)
_ = e.SavePolicy()
fmt.Scanln()
}
Getting Help
License
This project is under Apache 2.0 License. See the LICENSE file for the full license text.