百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
C

casbin-redis-adapter

> 数据库
开源

用于 Casbin 的 Redis 适配器

200 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

用于 Casbin 的 Redis 适配器

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 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Goaccess-controladapterauthauthorization

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类数据库
定价开源

> 相关工具

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