Categorygithub.com/go-codes/redis-watcher/v2
modulepackage
2.0.0
Repository: https://github.com/go-codes/redis-watcher.git
Documentation: pkg.go.dev

# README

Redis Watcher

Go report Coverage Status Go Reference Release

Redis Watcher is a Redis watcher for Casbin.

Installation

go get github.com/casbin/redis-watcher

Simple Example

package main

import (
	"log"

	"github.com/casbin/casbin/v2"
	watcher "github.com/casbin/redis-watcher"
	"github.com/go-redis/redis/v8"
)

func updateCallback(msg string) {
	log.Println(msg)
}

func main() {
	// Initialize the watcher.
	// Use the Redis host as parameter.
	w, _ := watcher.NewWatcher("localhost:6379", watcher.WatcherOptions{
		Options: redis.Options{
			Network:  "tcp",
			Password: "",
		},
		Channel:    "/casbin",
		IgnoreSelf: true,
	})

	// 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.

243bd42 (refactor)

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
NewPublishWatcher return a Watcher only publish but not subscribe.
NewWatcher creates a new Watcher to be used with a Casbin enforcer addr is a redis target string in the format "host:port" setters allows for inline WatcherOptions Example: w, err := rediswatcher.NewWatcher("127.0.0.1:6379",WatcherOptions{}) .

# Structs

No description provided by the author
No description provided by the author
No description provided by the author

# Type aliases

No description provided by the author