billcobbler / casbin-redis-watcher

Redis watcher for Casbin https://github.com/casbin/casbin
Apache License 2.0
19 stars 23 forks source link
casbin golang redis

Redis Watcher Build Status

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.