Home

Awesome

AlibabaCloud-CSharp-sdk

English | 简体中文

A client packaged based on StackExchange.Redis that operates Tair For Redis Modules.

Example

Connection

private static readonly ConnectionMultiplexer connDC = ConnectionMultiplexer.Connect("localhost");
private readonly TairString tair = new(connDC, 0);

Use ConnectionMultiplexer.Connect to create a ConnectionMultiplexer instance. Connection can be passed a configuration string or a ConfigurationOptions object. Once a ConnectionMultiplexer instance is created, a redis database (whether standalone or clustered) can be accessed.

Next, create the corresponding Module object, and then access the database. In addition, redis supports multiple databases, so when new an object, specify the corresponding database through the second parameter. (Clusters do not support this feature)

Async

For StackExchange.Redis, use ExecuteAsync to return the result as Task<RedisResult> type, you can use the following methods to get the real result

var ret1 = tairStringAsync.exset("key", "value");
Console.WriteLine(ResultHelper.Long(ret1.Result));//output "OK"

.Result is used to get the result of Async execution, ResultHelper.Long is used to convert RedisResult to the result required by the user.

API

An example of TairString is as follows:

using System.Text;
using Alibaba.TairSDK.TairString;
using StackExchange.Redis;

namespace TestString
{
    public class Program
    {
        private static readonly ConnectionMultiplexer connDC = ConnectionMultiplexer.Connect("localhost:6379");
        private static readonly TairString tair = new(connDC, 0);
        
        static void Main(string[] args)
        {
            var bkey = Encoding.UTF8.GetBytes("bkey");
            var bvalue = Encoding.UTF8.GetBytes("bvalue");
            var key = "key";
            var value = "value";

            //string
            var ret = tair.exset(key, value);
            Console.WriteLine(ret);
            var result = tair.exget(key);
            Console.WriteLine(result.getValue());
            Console.WriteLine(result.getVersion());
            

            //binary
            ret = tair.exset(bkey, bvalue);
            Console.WriteLine(ret);
            var bresult = tair.exget(bkey);
            Console.WriteLine(Encoding.UTF8.GetString(bresult.getValue()));
            Console.WriteLine(bresult.getVersion());
        }
    } 

}

Package Status

PackageNuGet StableDownloads
AlibabaCloud.TairSDKAlibabaCloud.TairSDKAlibabaCloud.TairSDK

Tair All SDK

languageGitHub
Javahttps://github.com/alibaba/alibabacloud-tairjedis-sdk
Pythonhttps://github.com/alibaba/tair-py
Gohttps://github.com/alibaba/tair-go
.Nethttps://github.com/alibaba/AlibabaCloud.TairSDK