Redis with C#.net
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.
After install try redis-cli
in command line and use ping
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 ...
- LIST
command reference
> rpush key value...
> lpush key value...
> lrange key start stop
> rpop key
> lpop key
- 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
Extra with keys
command use for select data.
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.
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: