Redis with C#.net

RuzeriE K.
3 min readFeb 25, 2021

Connect redis in C# and try to set and get data.

Install Redis

On Windows use this link (check Latest release & select .msi) to install, you will see port 6379 setting.

don’t miss to check Latest release first

After install try redis-cli in command line and use ping

redis server on, OK

Radis Data Types

Redis use key and value to keep data, when we refer to data type it mean to the value of data.

  • STRING:
command reference
> set key value
> get key
> incr key
> incrby key value
> mset key1 value1 key2 value2 ...
> mget key1 key2 ...
try command with string type
  • LIST
command reference
> rpush key value...
> lpush key value...
> lrange key start stop
> rpop key
> lpop key
try command with list type
  • HASH
command reference
> hmset hash_key field_key1 field_value1 field_key2 field_value2 ...
> hget hash_key field_key
> hgetall hash_key
> hmget hash_key field_key ... no-such-field
try command with hash type

Extra with keys command use for select data.

example keys command

If you want to try more, goto this, and dig into redis command.

Start C# APP

Run Visual Studio, then create new project with console type. After project created, use NuGet Tool to install StackExchange.Redis package.

Visual Studio new project
NuGet browse
select and install

StackExchange.Redis Package Document here

Create Redis Class

Create class to set connection

use Redis in C#

  • connect redis
  • try string command
  • try list command
  • try hash command

That all!!. You can find example code on Github.com

And if you liked this post, please clap your hands 👏👏👏

Bye!

Ref:

--

--

RuzeriE K.

Like to be a Agriculturist and career is Developer around 10+ years but I feel like, I'm still a novice.