This topic describes how to use a Redis data table.


CREATE TABLE tbName[(columnName dataType [,columnName dataType]*)]
USING redis
OPTIONS(propertyKey=propertyValue[, propertyKey=propertyValue]*);

Configuration parameters

Parameter Description Required

The prefix added to all keys of data written to Redis. The format of a key is ${table}:${key.column}. In the format, ${table} indicates the prefix and ${key.column} indicates the key specified by the key.column parameter.

Yes The processing method used if data to be written already exists in Redis. Valid values: append (appends data to be written to the existing data), overwrite (overwrites the existing data), errorifexists (throws an exception), and ignore (discards the existing data). Default value: append. No

The storage format of data. Valid values: hash and binary. Default value: hash.

No Specifies whether to filter out data that is not stored in the format specified by the model parameter. Default value: false. No
key.column The column of a row that is used as a key to write data to Redis. By default, a universally unique identifier (UUID) is auto-generated as a key. No
ttl The time-to-live (TTL) of a key. If you do not set this parameter, data is stored permanently by default. If you set this parameter, the parameter value indicates the expiration time. Unit: seconds. No

The maximum number of bulk data write operations that a pipeline can support. Default value: 100.

host The host to connect to Redis on. Default value: localhost. No
port The port to connect to Redis on. Default value: 6379. No
dbNum The number of databases from which data is stored in Redis. Default value: 0. No

Table schema

When creating a Redis data table, you must explicitly define the fields in the data table. For example, a valid table creation statement is as follows:

spark-sql> CREATE TABLE redis_test_table(`key0` STRING, `value0` STRING, `key1` STRING, `value1` STRING)
         > USING redis
         > OPTIONS(
         > table="test",
         > model="hash",
         > key.column="uuid",
         > max.pipeline.size="100",
         > host="localhot",
         > port="6379",
         > dbNum="0");