StackExchange.Redis is a high performance general purpose redis client for .NET languages (C#, etc.), and is designed for Windows / .NET SDK environments. On other hand, it is possible now install .NET SDK and run PowerShell commands on Linux environments. This article describes how to install and link all together to have a Linux environment to run some commands and connect to any Redis service using StackExchange.Redis client library. This can be used for test proposes, and there are no support to run this on production. Try and test this at your own risk and responsibility. This was tested on Linux Ubuntu v20.04.02 LTS, .NET SDK v7.0.403, Stackexchange.Redis v2.7.4, and PowerShell v220.127.116.11. There are no guarantees this will work with all scenarios and versions.
High performance multiplexed design, allowing for efficient use of shared connections from multiple calling threads
Abstraction over redis node configuration: the client can silently negotiate multiple redis servers for robustness and availability
Convenient access to the full redis feature-set
Full dual programming model both synchronous and asynchronous usage, without requiring “sync over async” usage of the TPL
Support for redis “cluster”
StackExchange.Redis implementation on Linux Ubuntu
To have a working scenario on a Linux VM , be able to connect to some Redis server using StackExchange.Redis client library, follow these steps:
Create a directory for your project, navigate to it, and create a PowerShell script file with a .ps1 extension.
Install the StackExchange.Redis library:
This will create a basic .NET Core console application and add the StackExchange.Redis package to your project.
sudo dotnet new console
sudo dotnet add package StackExchange.Redis
Edit your PowerShell script:
Open the connect-redis.ps1 script in a text editor (ex: vi) and add your PowerShell code to connect to the Redis server, using the StackExchange.Redis library.
# Load the StackExchange.Redis library
Add-Type -Path "/home/<user>/my-redis-project/bin/Debug/net7.0/StackExchange.Redis.dll"
# see note (**) below to find StackExchange.Redis.dll location
# Define the Redis server endpoint and SSL port used (example for Azure Cahe for Redis service)
$redisServerEndpoint = "<redisName>.redis.cache.windows.net:6380"
# Create a ConfigurationOptions instance to configure the connection
$redisConfig = New-Object StackExchange.Redis.ConfigurationOptions
$redisConfig.Password = "<redisAccessKey>" # Replace with your actual Redis password
# Create a connection to the Redis server
$redisConnection = [StackExchange.Redis.ConnectionMultiplexer]::Connect($redisConfig)
# Get a reference to the Redis database (by default, database 0)
$redisDatabase = $redisConnection.GetDatabase()
# Perform Redis operations
$redisDatabase.StringSet("mykey", "Hello, Redis from Linux PowerShell!")
$value = $redisDatabase.StringGet("mykey")
Write-Host "Redis Value: $value"
# Close the connection
6. Run your PowerShell script:
To check Linux distribution and version:
To check PowerShell installed version:
To check installed .NET SDKs on your system:
To check Stackexchange.Redis installed version:
sudo dotnet new console
sudo dotnet list package
To check default .NET SDK version
sudo dotnet --version
To rebuild your project, if needed, and to check the path for StackExchange.Redis.dll provided in the PS script (**)
sudo dotnet build
(**) You should obtain something like this: my-redis-project -> /home/<user>/my-redis-project/bin/Debug/net7.0/my-redis-project.dll StackExchange.Redis.dll should be in the same path
Install the required .NET dependencies, if needed:
Despite the target of this article describes not being to deploy solutions for production environments, this is a good way to test connectivity and run some Redis commands on a Redis service, from Linux environments, using Stackexchange.Redis client library.