Skip to content

casbin-net/redis-adapter

Repository files navigation

Casbin.NET Redis Adapter

Actions Status Coverage Status NuGet

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

Installation

dotnet add package Casbin.NET.Adapter.Redis

Simple Example

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();
        }
    }
}

Getting Help

License

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