Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
C

casbin-redis-adapter

> 数据库
Open source

Redis adapter for Casbin

200 stars0 likes2 views
WebsiteGitHub

About

Redis adapter for Casbin

Redis Adapter

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

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

…

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

License

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

Issues· 1 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Goaccess-controladapterauthauthorization

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category数据库
PricingOpen source

> Related tools

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库