Microsoft.Orleans.Persistence.Redis 9.2.0-preview3

Microsoft Orleans Persistence for Redis

Introduction

Microsoft Orleans Persistence for Redis provides grain persistence for Microsoft Orleans using Redis. This allows your grains to persist their state in Redis and reload it when they are reactivated, leveraging Redis's in-memory data store for fast access.

Getting Started

To use this package, install it via NuGet:

dotnet add package Microsoft.Orleans.Persistence.Redis

Example - Configuring Redis Persistence

using Microsoft.Extensions.Hosting;
using Orleans.Configuration;
using Orleans.Hosting;

var builder = Host.CreateApplicationBuilder(args)
    .UseOrleans(siloBuilder =>
    {
        siloBuilder
            .UseLocalhostClustering()
            // Configure Redis as grain storage
            .AddRedisGrainStorage(
                name: "redisStore",
                configureOptions: options =>
                {
                    options.ConnectionString = "localhost:6379";
                    options.Database = 0;
                    options.UseJson = true; // Serializes grain state as JSON
                    options.KeyPrefix = "grain-"; // Optional prefix for Redis keys
                });
    });

// Run the host
await builder.RunAsync();

Example - Using Grain Storage in a Grain

// Define grain state class

public class MyGrainState
{
    public string Data { get; set; }
    public int Version { get; set; }
}

// Grain implementation that uses Redis storage
public class MyGrain : Grain, IMyGrain, IGrainWithStringKey
{
    private readonly IPersistentState<MyGrainState> _state;

    public MyGrain([PersistentState("state", "redisStore")] IPersistentState<MyGrainState> state)
    {
        _state = state;
    }

    public async Task SetData(string data)
    {
        _state.State.Data = data;
        _state.State.Version++;
        await _state.WriteStateAsync();
    }

    public Task<string> GetData()
    {
        return Task.FromResult(_state.State.Data);
    }
}

Documentation

For more comprehensive documentation, please refer to:

Feedback & Contributing

No packages depend on Microsoft.Orleans.Persistence.Redis.

Version Downloads Last updated
9.2.0-preview3 1 6/15/2025
9.2.0-preview2 1 6/9/2025
9.2.0-preview1 1 6/9/2025
9.1.2 1 6/9/2025
9.0.1 1 6/9/2025
9.0.0 1 6/9/2025
8.2.0 1 6/9/2025
8.2.0-preview1 1 6/9/2025
8.1.0 1 6/8/2025
8.1.0-preview3 2 6/8/2025
8.1.0-preview2 1 6/9/2025
8.1.0-preview1 1 6/9/2025
8.0.0 1 6/9/2025
8.0.0-rc2 1 6/9/2025
8.0.0-rc1 1 6/9/2025
7.2.7 1 6/9/2025
7.2.6 1 6/9/2025
7.2.5 1 6/9/2025
7.2.4 1 6/9/2025
7.2.3 1 6/9/2025
7.2.2 1 6/9/2025
7.2.1 1 6/9/2025
7.2.0 1 6/9/2025
7.1.2-beta1 1 6/9/2025
7.1.1-beta1 1 6/9/2025
7.1.0-beta1 1 6/9/2025