Execute custom commands in redis pipeline

Is there any way to execute a custom command in a pipeline?

Here’s what I’m looking for:

var results = new List<RedisText>();

using (var pipeline = redis.CreatePipeline())
{
    foreach (var cmdWithArgs in commands)
    {
       pipeline.QueueCommand(
           r => r.Custom(cmdWithArgs),
           (RedisText result) => results.add(result));
    }
    
    pipeline.Flush();
}

This doesn’t work, because it looks like Custom has not been implemented.

I can use the low-level pipeline API to execute the commands:

var pipeline = ((RedisNativeClient)redis).CreatePipelineCommand();

foreach (var cmdWithArgs in commands)
{
    pipeline.WriteCommand(
        cmdWithArgs
            .Select(x => x.ToString().ToUtf8Bytes())
            .ToArray());
}

pipeline.Flush();

But I can’t find a way to get the results when doing this.

Which commands are you trying to execute? I’ve run following sample and it adds results to pipeline, number of items is 3 and the text of items in array is : "OK", "OK, "3":


RedisManagerPool manager = new RedisManagerPool("localhost:6379");

var results = new List<RedisText>();

using (var client = manager.GetClient())
{
    using (var pipe = client.CreatePipeline())
    {
        pipe.QueueCommand(p => p.Custom("set", "test", "2"), r => results.Add(r));
        pipe.QueueCommand(p => p.Custom("set", "test", "3"), r => results.Add(r));
        pipe.QueueCommand(p => p.Custom("get", "test"), r => results.Add(r));
        pipe.Flush();
    }

    Console.WriteLine("number of items = {0}", results.Count);
}

Ah, I see the problem.

I’m using an older version of ServiceStack.Redis, which doesn’t yet have the RedisText overloads for QueueCommand:

void QueueCommand(Func<IRedisClient, RedisText> command);
void QueueCommand(Func<IRedisClient, RedisText> command, Action<RedisText> onSuccessCallback);
void QueueCommand(Func<IRedisClient, RedisText> command, Action<RedisText> onSuccessCallback, Action<Exception> onErrorCallback);

I’ll have to upgrade to a newer version.