Categorygithub.com/casbin/redis-adapter/v3
modulepackage
3.5.0
Repository: https://github.com/casbin/redis-adapter.git
Documentation: pkg.go.dev

# README

Redis Adapter

Go Report Card Build Coverage Status Godoc Release Discord Sourcegraph

Redis Adapter is the Redis adapter for Casbin. With this library, Casbin can load policy from Redis or save policy to it.

Installation

go get github.com/casbin/redis-adapter/v3

Simple Example

package main

import (
	"github.com/casbin/casbin/v2"
	"github.com/casbin/redis-adapter/v3"
)

func main() {
	// Direct Initialization:
	// Initialize a Redis adapter and use it in a Casbin enforcer:
	a, _ := redisadapter.NewAdapter("tcp", "127.0.0.1:6379") // Your Redis network and address.

	// Use the following if Redis has password like "123"
	// a, err := redisadapter.NewAdapterWithPassword("tcp", "127.0.0.1:6379", "123")

	// Use the following if you use Redis with a specific user 
	// a, err := redisadapter.NewAdapterWithUser("tcp", "127.0.0.1:6379", "username", "password")

	// Use the following if you use Redis connections pool
	// pool := &redis.Pool{}
	// a, err := redisadapter.NewAdapterWithPool(pool)

	// Initialization with different user options:
	// Use the following if you use Redis with passowrd like "123":
	// a, err := redisadapter.NewAdapterWithOption(redisadapter.WithNetwork("tcp"), redisadapter.WithAddress("127.0.0.1:6379"), redisadapter.WithPassword("123"))

	// Use the following if you use Redis with username, password, and TLS option:
	// var clientTLSConfig tls.Config
	// ...
	// a, err := redisadapter.NewAdapterWithOption(redisadapter.WithNetwork("tcp"), redisadapter.WithAddress("127.0.0.1:6379"), redisadapter.WithUsername("testAccount"), redisadapter.WithPassword("123456"), redisadapter.WithTls(&clientTLSConfig))

	e, _ := casbin.NewEnforcer("examples/rbac_model.conf", a)

	// Load the policy from DB.
	e.LoadPolicy()

	// Check the permission.
	e.Enforce("alice", "data1", "read")

	// Modify the policy.
	// e.AddPolicy(...)
	// e.RemovePolicy(...)

	// Save the policy back to DB.
	e.SavePolicy()
}

Getting Help

License

This project is under Apache 2.0 License. See the LICENSE file for the full license text.

# Functions

NewAdapter is the constructor for Adapter.
NewAdapterWithKey is the constructor for Adapter.
No description provided by the author
NewAdapterWithPassword is the constructor for Adapter.
NewAdapterWithPool is the constructor for Adapter.
NewAdapterWithPoolAndOptions is the constructor for Adapter.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

Adapter represents the Redis adapter for policy storage.
CasbinRule is used to determine which policy line to load.
No description provided by the author

# Type aliases

No description provided by the author