I need to run several ft.aggregate and ft.search queries in a row – the first query result is the input of the second one and so on. I would like to limit redis round trips so I thought I might use pipeline for that. I was look at some examples in official docs but nothing about querying can be found. The question is – if I have some set of values being returned for one query – is it possible to pass it in the pipeline to the second query?
2
Answers
Unfortunately, what you would like to do is not possible as it contradicts what pipelining is. Pipelining works by, essentially, shoving requests in and not waiting for a response. This means that the request and the response are disconnected by design.
To make this work you would need to pipeline in a single request, wait for the response, and then pipeline in the next request. There is no difference between this and just making a series of calls on a single connection.
Bottom lineāif you need to do something with the response before sending the next request, you can’t use pipelining.
Have you considered scripting this with Lua?
Basically you’d have to write a script that runs the first command and passes the result to the second command then execute the script from Lettuce using the Scripting and Functions approach. See this example for instance Redis multiple calls vs lua script
This should take only one round trip to the server instead of two, as per your initial request. It does have some disadvantages and complications when you have a distributed environment for instance.