Warm tip: This article is reproduced from serverfault.com, please click

RediSql (for redis): Get column names as well as data type?

发布于 2020-12-01 09:20:27

I am using the excellent RediSql, a module for Redis, to get a powerful caching solution.

When sending a command to Redis, that interacts with the SqLite db in the background, like this:

REDISQL.EXEC db "SELECT * FROM jobcache"

I get a result like this:

enter image description here

I get a type for the integer column, but not for the string, and no column names are provided.

Is there a way to get column name and defined data type always? I would need this, as I need to convert the results back to a more standard sql result format.

Questioner
Ted
Viewed
0
Siscia 2020-12-01 17:42:41

unfortunately, at the moment this is not possible with the EXEC command.

You can use the QUERY.INTO command reference

QUERY.INTO add the result of your query into a stream, it adds the column and the values for each row. Then you can consume the stream in whichever way you prefer.

When doing query (reads) against RediSQL is a good practice to use the .QUERY family of commands, this avoids useless replication of data, in the case you are in a cluster setup.

Moreover, it is possible to use the .QUERY commands also against replica of the main redis instance, while the .EXEC commands can be used only against the primary instance.