示例
var multiplexer = ConnectionMultiplexer.Connect("localhost");
IDatabase db = multiplexer.GetDatabase();
// 用空字符串初始化键
await db.StringSetAsync("key", "");
// 创建利用复用和流水线的事务
ITransaction transacton = db.CreateTransaction();
Task<long> appendA = transacton.StringAppendAsync("key", "a");
Task<long> appendB = transacton.StringAppendAsync("key", "b");
if (await transacton.ExecuteAsync()) // sends "MULTI APPEND KEY a APPEND KEY b EXEC
// 在对Redis服务器的单个请求中
{
// order here doesn't matter, result is always - "abc".
// 'a'和'b'总是附加在一起,与其他Redis命令隔离
// 'c' appends to "ab" because transaction is already executed successfully
await appendA;
await db.StringAppendAsync("key", "c");
await appendB;
}
string value = db.StringGet("key"); // value is "abc"