How to install redis on ubuntu ?
https://redis.io/docs/latest/operate/oss_and_stack/install/install-stack/apt/
I am using Ubuntu 24.04 so I installed with these commands :
sudo apt-get install lsb-release curl gpg
curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
sudo chmod 644 /usr/share/keyrings/redis-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list
sudo apt-get update
sudo apt-get install redis
sudo systemctl enable redis-server
You can check redis with :
redis-cli
Creating dotnet project
Install nuget package :
https://www.nuget.org/packages/stackexchange.redis
dotnet add package StackExchange.Redis --version 2.10.1
nano Program.cs
paste :
using StackExchange.Redis;
ConnectionMultiplexer connectionMultiplexer = ConnectionMultiplexer.Connect("localhost");
var database = connectionMultiplexer.GetDatabase();
database.StringSet("yourFirstCodeKey", "yourFirstCodeValue");
var yourFirstCodeKeyValue = database.StringGet("yourFirstCodeKey");
System.Console.WriteLine(yourFirstCodeKeyValue);
dotnet run
$ redis-cli
127.0.0.1:6379> get yourFirstCodeKey
"yourFirstCodeValue"
These are most basics steps.
Happy creating.







Top comments (0)