RespClient is a minimal RESP(REdis Serialization Protocol) client for C# and PowerShell.
.NET has several Redis Client, BookSleeve (and it's wrapper CloudStructures), ServiceStack.Redis, etc. There are heavy for command line usage. RespClient is focusing on simple command usage like Redis-Cli. It's higher match for PowerShell.
Binary is registered at NuGet, RespClient.
# Standalone PowerShell Cmdlet and .NET Client, requires System.Management.Automation
PM> Install-Package RespClient
# Module is provided by dll
Import-Module RespClient.dll
# Connect to RedisServer. Connection is effective during powershell session.
# other parameter, -Host, -Port, -Timeout
Connect-RedisServer 127.0.0.1
# Send Command to RedisServer. Return value was decoded UTF8 string.
Send-RedisCommand "set test abcde"
# Support pipeline mode.
Begin-RedisPipeline
Send-RedisCommand "set test fghijk"
Send-RedisCommand "incr testb"
Send-RedisCommand "incr testc"
Send-RedisCommand "get test"
Execute-RedisPipeline
# Cleanup Connection explicitly
Disconnect-RedisServer
If use raw RespClient, you can send binary value and choose other decoder(besides Encoding.UTF8).
using (var client = new Redis.Protocol.RespClient())
{
// string command
client.SendCommand("set a 100", Encoding.UTF8.GetString);
// binary safe command
client.SendCommand("set", new[] { Encoding.UTF8.GetBytes("test"), Encoding.UTF8.GetBytes("abcde") }, Encoding.UTF8.GetString);
// use pipeline
var results = client.UsePipeline()
.QueueCommand("incr a")
.QueueCommand("incrby b 10")
.QueueCommand("get a", Encoding.UTF8.GetString)
.Execute();
} // disconnect on dispose