The Redis adapter allows querying of live data stored in Redis.Each Redis key/value pair is presented as a single row in Presto. Rows can be broken down into cells by using table definition files.
Redis `string` ,`hash`, `sets`, `zsets`, `list` value types are supported;
CSV format data
JSON format data
RAW format data
We inserted data in three formats, one in CSV format, one in JSON format, and one in RAW format. This is the three formats we currently support, which will be demonstrated separately.
Then you can define the corresponding mapping table in the JSON file:
Here are a few details about the fields:
keyDelimiter is used to split the value, the default is a colon, and the split value is used to map the field column. Only works for the CSV format.
Format is used to specify the format of the data in Redis. Currently, it supports: CSV, JSON and RAW. The raw format keeps the original redis key and value intact and only one field key is used for the query. The details are not described below.
The function of COLUMN_MAPPING is to map the columns of Redis to the underlying data. Since there is no concept of column under the Redis, the specific mapping method varies according to the format. For example, here CSV, we know that the CSV data will be formed after being parsed. A string array, the corresponding column_mapping is mapped to the index (subscript) of the underlying array. For example, here map id to subscript 2, map name to subscript 1 and so on.
You can query the data in the Redis database:
Mysql> select * from dla_person;
4 rows in set (0.18 sec)
Students who are familiar with SQL must feel very cool, you can go to the familiar SQL syntax to operate the Redis database.
The above demonstrates the data in CSV format. Let's try the data in JSON format. Let's create a new table:
Note that we have specified COLUMN_MAPPING here, because the JSON data has a field name, so the column name of the Redis layer is mapped to the name of the field in the JSON data. Here, the Redis id column is deliberately mapped to Redis for demonstration purposes. The age, let's look at the results:
Mysql> select * from dla_person_json;
4 rows in set (0.12 sec)
As we wish, the id column shows the value of the corresponding age field in Redis.