StackExchange.Redis simple C# Example

hellowahab picture hellowahab · Oct 1, 2015 · Viewed 39k times · Source

I am looking for a very simple starter C# application for using StackExchange.Redis I have search over the web and found StackExchange.Redis

But this doesn't seems like a quick startup example.

I have setup redis on windows using StackExchange.Redis exe

Can anyone help me locate a simple C# application connecting with redis server and setting and getting some keys.

Answer

thepirat000 picture thepirat000 · Oct 1, 2015

You can find C# examples in the readme file.

using StackExchange.Redis;
...

ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");
// ^^^ store and re-use this!!!

IDatabase db = redis.GetDatabase();
string value = "abcdefg";
db.StringSet("mykey", value);
...
string value = db.StringGet("mykey");
Console.WriteLine(value); // writes: "abcdefg"