RediPal gives you the ability to read and write dotnet objects in and out of redis
https://www.nuget.org/packages/RediPal/
- Creating the Connection
var redi = new Redipal("Redis-Address");
- Write your object
var obj = new TestObject
{
ID = "test",
NestedObject = new TestObject2
{
ID = "Was Nested"
}
};
redi.Write.Object(obj, "keyspace", "objectid");
- Read the object back
var testObj = redi.Read.Object<TestObject>("keyspace", "objectid");
if (testObj != null)
Console.WriteLine($"ID: {testObj.ID} NestID: {testObj.NestedObject.ID}");
Create using an anonymous connection
var redi = new Redipal("Redis-Address");
Create using an existing connection
var existingRedis = ConnectionMultiplexer.Connect("Redis-Addres");
var redi = new Redipal(existingRedis);
Create using configuration options
var redisConfig = new ConfigurationOptions
{
Password = "Example",
User = "Example"
};
redisConfig.EndPoints.Add("Redis-Address");
var redi = new Redipal(redisConfig);
var dictionary = new Dictionary<string, TestObject>()
{
{"test1", new TestObject() },
{"test2", new TestObject() },
{"test3", new TestObject() }
};
redi.Write.Dictionary(dictionary, "testobjects");
This will write all the keys in the dictionary as a set to "testobjects" and write each object under the key of "testobject".
var list = new List<TestObject>()
{
new TestObject(),
new TestObject(),
new TestObject()
};
redi.Write.List(list, "testobjects");
This will write each object under the key of "testobject" and add an index to the set of "testobjects".
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.