We are trying to write a PowerShell script that invokes an external application -- a Redis client (redis-cli.exe
) -- and then sends multiple commands to that .exe. We have no issue sending individual commands like the below:
& redis-cli -h localhost -p 6379 SMEMBERS someKey
The problem is that this will start a Redis client, issue a single command, close the client, and then return control to PowerShell. We need to issue multiple commands in a transaction. For example, here are the commands that we want to send to the client:
MULTI
DEL someKey
DEL someSet
EXEC
The Redis client does support sending a LUA script string as a command, but this unfortunately doesn't support the MULTI/EXEC transactional commands. In other words, we need to be able to issue multiple commands like I listed above.
Since redis-cli
appears to read input from STDIN you could feed it an array with the command strings like this:
'MULTI', 'EXEC' | & redis-cli -h localhost -p 6379
Using echo
(alias for Write-Output
) is not required for feeding the array into the pipeline.
You could also store the command array in a variable first:
$cmds = 'MULTI', 'EXEC'
$cmds | & redis-cli -h localhost -p 6379
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With