KO
|
EN
gitlite — search
Search
#python
#typescript
#react
#python3
#mysql
#discord
#rust
#javascript
#reactjs
#go
#website
#game
casbin-redis-adapter
★ 200
Open GitHub ↗
Redis adapter for Casbin
Download README (.md)
Explore Similar Repositories
uvicorn-gunicorn-starlette-docker
:
Docker image with Uvicorn managed by Gunicorn for high-performance Starlette web applications in Python with performance auto-tuning.
angular-6-registration-login-example
:
Angular 6 User Registration and Login Example
yggdrasil
:
Envoy Control Plane for Kubernetes Multi-cluster Ingress
datafusion-dft
:
Batteries included CLI, TUI, and server implementations for DataFusion.
EvoTrees.jl
:
Boosted trees in Julia
// repository documentation
Was this content helpful?
★ 0
(0 ratings)
Select Rating:
★
★
★
★
★
Submit Feedback
Recent Feedback
×
Download README
Do you want to download the
README.md
file for
casbin-redis-adapter
?
Download (.md)
Redis Adapter ==== [](https://goreportcard.com/report/github.com/casbin/redis-adapter) [](https://github.com/casbin/redis-adapter/actions/workflows/ci.yml) [](https://coveralls.io/github/casbin/redis-adapter?branch=master) [](https://pkg.go.dev/github.com/casbin/redis-adapter/v3) [](https://github.com/casbin/redis-adapter/releases/latest) [](https://discord.gg/S5UjpzGZjN) [](https://sourcegraph.com/github.com/casbin/redis-adapter?badge) Redis Adapter is the [Redis](https://redis.io/) adapter for [Casbin](https://github.com/casbin/casbin). With this library, Casbin can load policy from Redis or save policy to it. ## Installation go get github.com/casbin/redis-adapter/v3 ## Configuration Options The `Config` struct supports the following options: - `Network` (string): Network type, e.g., "tcp", "unix" (required when not using Pool) - `Address` (string): Redis server address, e.g., "127.0.0.1:6379" (required when not using Pool) - `Key` (string): Redis key to store Casbin rules (default: "casbin_rules") - `Username` (string): Username for Redis authentication (optional) - `Password` (string): Password for Redis authentication (optional) - `TLSConfig` (*tls.Config): TLS configuration for secure connections (optional) - `Pool` (*redis.Pool): Existing Redis connection pool (optional, if provided, other connection options are ignored) ## Usage Examples ### Basic Usage ```go package main import ( "github.com/casbin/casbin/v2" "github.com/casbin/redis-adapter/v3" ) func main() { // Recommended approach using Config config := &redisadapter.Config{Network: "tcp", Address: "127.0.0.1:6379"} a, _ := redisadapter.NewAdapter(config) // With password authentication // config := &redisadapter.Config{Network: "tcp", Address: "127.0.0.1:6379", Password: "123"} // a, _ := redisadapter.NewAdapter(config) // With user credentials // config := &redisadapter.Config{Network: "tcp", Address: "127.0.0.1:6379", Username: "user", Password: "pass"} // a, _ := redisadapter.NewAdapter(config) // With TLS configuration // var clientTLSConfig tls.Config // ... // config := &redisadapter.Config{Network: "tcp", Address: "127.0.0.1:6379", Username: "testAccount", Password: "123456", TLSConfig: &clientTLSConfig} // a, _ := redisadapter.NewAdapter(config) 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() } ``` ### With Connection Pool ```go package main import ( "github.com/casbin/casbin/v2" "github.com/casbin/redis-adapter/v3" "github.com/gomodule/redigo/redis" ) func main() { pool := &redis.Pool{Dial: func() (redis.Conn, error) { return redis.Dial("tcp", "127.0.0.1:6379") }} config := &redisadapter.Config{Pool: pool, Key: "casbin_rules"} a, _ := redisadapter.NewAdapter(config) e, _ := casbin.NewEnforcer("examples/rbac_model.conf", a) // Load the policy from DB. e.LoadPolicy() // Check the permission. e.Enforce("alice", "data1", "read") // Save the policy back to DB. e.SavePolicy() } ``` ## Getting Help - [Casbin](https://github.com/casbin/casbin) ## License This project is under Apache 2.0 License. See the [LICENSE](LICENSE) file for the full license text.