Oguz Karadenizli
Oguz Karadenizli

Reputation: 3505

How to combine multiple IRedisTypedTransaction<T> in ServiceStack RedisClient

I'm trying to achieve transactional StoreRelatedEntities. So I need to access RedisClient from ITypedRedisClient or this:

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

Is it proper way? Or I have to

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

Or I have to?

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

Upvotes: 1

Views: 400

Answers (1)

mythz
mythz

Reputation: 143399

This looks like the easiest, so it would be my pick:

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

But there's no right/wrong, way just do whatever you're more comfortable with. Each client either inherits or contains an instance of the RedisNativeClient which encapsulates a tcp socket connection with the Redis server. The relationship between the different classes are below:

Upvotes: 1

Related Questions