Redis Adapter is the Redis adapter for Casbin. With this library, Casbin can load policy from Redis or save policy to it.
dotnet add package Casbin.NET.Adapter.Redis
using Casbin.Adapter.Redis;
using NetCasbin;
namespace ConsoleAppExample
{
public class Program
{
public static void Main(string[] args)
{
// Initialize a Redis adapter and use it in a Casbin enforcer:
var redisAdapter = new RedisAdapter("localhost:6379");
var e = new Enforcer("examples/rbac_model.conf", redisAdapter);
// Load the policy from Redis.
e.LoadPolicy();
// Check the permission.
e.Enforce("alice", "data1", "read");
// Modify the policy.
// e.AddPolicy(...)
// e.RemovePolicy(...)
// Save the policy back to Redis.[README.md](..%2Fcasbin-aspnetcore%2FREADME.md)
e.SavePolicy();
}
}
}
This project is under Apache 2.0 License. See the LICENSE file for the full license text.