rediswatcher

package module
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 9, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

README

casbin-redis-watcher

casbin redis 观察者

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewWatcher

func NewWatcher(addr string, setters ...WatcherOption) (persist.Watcher, error)

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", rediswatcher.Password("pass"), rediswatcher.Channel("/yourchan"))

A custom redis.Conn can be provided to NewWatcher

Example: c, err := redis.Dial("tcp", ":6379") w, err := rediswatcher.NewWatcher("", rediswatcher.WithRedisConnection(c) //

Types

type Watcher

type Watcher struct {
	// contains filtered or unexported fields
}

func (*Watcher) Close

func (w *Watcher) Close()

Close disconnects the watcher from redis

func (*Watcher) SetUpdateCallback

func (w *Watcher) SetUpdateCallback(callback func(string)) error

SetUpdateCallBack sets the update callback function invoked by the watcher when the policy is updated. Defaults to Enforcer.LoadPolicy()

func (*Watcher) Update

func (w *Watcher) Update() error

Update publishes a message to all other casbin instances telling them to invoke their update callback

type WatcherOption

type WatcherOption func(*WatcherOptions)

func Channel

func Channel(subject string) WatcherOption

func Password

func Password(password string) WatcherOption

func Protocol

func Protocol(protocol string) WatcherOption

func WithRedisPubConnection

func WithRedisPubConnection(connection *redis.Client) WatcherOption

func WithRedisSubConnection

func WithRedisSubConnection(connection *redis.Client) WatcherOption

type WatcherOptions

type WatcherOptions struct {
	Channel  string
	PubConn  *redis.Client
	SubConn  *redis.Client
	Password string
	Protocol string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL