TDV Adapter for Redis

Build 21.0.8137

Running Redis Commands Directly

Running Redis Commands Directly

If you need to run a command directly that isn't exposed by the usual CRUD operations on tables, you can use the adapter's RunCommand stored procedure. For example, the FLUSHDB command removes all keys from the current database:

EXECUTE RunCommand @CommandLine = 'FLUSHDB'

You can also run commands which require parameters by separating them with spaces, the same as in redis-cli. Double-quotes are also available if you need to embed spaces into a parameter value:

EXECUTE RunCommand @CommandLine = 'INFO "CPU"'

The adapter will process the results of the command and return them in the appropriate format. For cases like FLUSHDB or INFO where the result is a simple value or a flat array, each element will be returned as a separate row.

'# CPU'

More complex results, like the values returned from the COMMAND command, will be separated by row and then converted to JSON for final output.


Batching Multiple Redis Commands

You can also execute multiple commands in one operation using the RunBatchCommand stored procedure. If you are running large numbers of commands at once, batch commands are much more efficient because the adapter does not need to send and wait for single commands to complete. Instead, the adapter will send several commands and wait for them as a group.

To use RunBatchCommand, you will need to populate a temporary table with the commands you want to run. The table should have only one column called CommandLine:

INSERT INTO Commands#TEMP(CommandLine) VALUES ('SET key:1 value')
INSERT INTO Commands#TEMP(CommandLine) VALUES ('SET key:2 value')
-- etc.
INSERT INTO Commands#TEMP(CommandLine) VALUES ('SET key:10000 value')

Once the temporary table is populated, you can invoke RunBatchCommand. It will return results similar to RunCommand, but with an extra CommandIndex output which shows which command each result came from.

EXECUTE RunBatchCommand @CommandTable = 'Commands#TEMP'

You can also execute commands from a table stored in a text file. The adapter will read from this file and execute the commands founds within it. Each command must be on a separate line.

/* commands.txt contents
SET key:1 value
SET key:2 value
SET key:3 value
SET key:10000 value
EXECUTE RunBatchCommand @CommandFile = 'commands.txt'

Copyright (c) 2022 CData Software, Inc. - All rights reserved.
Build 21.0.8137