redis - 如何在 ServiceStack RedisClient 中组合多个 IRedisTypedTransaction<T>

标签 redis servicestack

我正在尝试实现事务性 StoreRelatedEntities。所以我需要从 ITypedRedisClient 或这个访问 RedisClient:

using (var trans1 = redis.As<X>().CreateTransaction())
using (var trans2=  redis.As<Y>().CreateTransaction())
{
   .....
   trans1.Join(trans2); // :) Fantasy
   trans2.Commit(); 
}                

这是正确的方法吗?或者我必须

using (var trans1=redis.As<X>().CreateTransaction())
{
  trans.QueueCommand(p => ((RedisClient)((RedisTypedClient<T>)p).NativeClient).AddRangeToList(.....);
}

或者我必须这样做?

using (var trans=redis.CreateTransaction())
{
   trans.QueueCommand(p=>p.As<X>()....); // Casting to Typed RedisClient in Command
   trans.QueueCommand(p=>p.As<Y>()....);
}

最佳答案

这看起来是最简单的,所以这是我的选择:

using (var trans=redis.CreateTransaction())
{
   trans.QueueCommand(p=>p.As<X>()....); // Casting to Typed RedisClient in Command
   trans.QueueCommand(p=>p.As<Y>()....);
}

但是没有对错之分,只要你觉得舒服就好。每个客户端都继承或包含 RedisNativeClient 的一个实例,该实例封装了与 Redis 服务器的 tcp 套接字连接。不同类之间的关系如下:

关于redis - 如何在 ServiceStack RedisClient 中组合多个 IRedisTypedTransaction<T>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10876043/

相关文章:

unity-game-engine - 如何在 Unity C# 脚本中引用 ServiceStack 库?

asp.net-mvc - 使用 MVC Controller 进行 ServiceStack 身份验证

c# - 如何将 ServiceStack 客户端与 Xamarin.Android 独立许可证一起使用

python - 使用 Python 和 Redis 进行优雅的缓存

php - 取消 Laravel 中的作业

Node.js - 使用 Redis 原子更新进行扩展

c# - ServiceStack - 工作单元和结构图

c# - ServiceStack TypeSerializer : ISO8601 and culture with dot as TimeSeparator

python - python 3.5 中的 json.loads 和 Redis

perl - 如何手动安装 Redis perl 库,即离线。以及从哪里可以获取所有要安装的依赖项