Monday, April 27, 2020

Redis with C#

Redis is a Key Value, very fast NoSql Database.

Extract the Window Redis Zip. Inside the 64 folder you can find redis-server and redis-cli. Double click redis-server to start the Redis Server.


Double click the redis-cli to open the Redis Command Line Interface.

set command is used to set a value to a Key. get command is used to get the value of a key.



setnx
 If you issue set command to a key which already has a value then the existing value will be replaced with the new value. setnx command is used to create a value for a key which doesn't exist.

incr and decr

incr command is used to increment a value by 1.  decr is used to decrement a value by 1.





 I have create a Console Application and Set reference to StackExchange.Redis. 






using System;
using StackExchange.Redis;
..
static void Main(string[] args)
{
    IConnectionMultiplexer redisCon = ConnectionMultiplexer.Connect("localhost");
    IDatabase db = redisCon.GetDatabase();
    db.StringSet("MyName", "Shalivn P D");
    Console.WriteLine(db.StringGet("MyName"));
    Console.WriteLine("Hello World!");
}

No comments:

Post a Comment