Creating a Redis Table

Create a Redis table to interconnect with the source stream so that data can be output to the DCS Redis table.

For details about DCS, see the Distributed Cache Service User Guide.

For details about the JOIN syntax, see JOIN Between Stream Data and Table Data.

Syntax

Syntax

CREATE TABLE table_id (key_attr_name STRING(, hash_key_attr_name STRING)?, value_attr_name STRING)WITH (type = "dcs_redis",cluster_address = ""(,password = "")?,value_type= "",key_column= ""(,hash_key_column="")?);

Description

Table 1 Parameter description in the syntax

Parameter

Mandatory

Description

type

Yes

Indicates the output channel type. Value dcs_redis indicates that data is exported to DCS Redis.

cluster_address

Yes

Indicates the Redis instance connection address.

password

No

Indicates the Redis instance connection password. This parameter is not required if password-free access is used.

value_type

Yes

Indicates the field data type. Supported data types include string, list, hash, set, and zset.

key_column

Yes

Indicates the column name of the Redis key attribute.

hash_key_column

No

If value_type is set to hash, this field must be specified as the column name of the level-2 key attribute.

cache_max_num

No

Indicates the maximum number of cached query results. The default value is 32768.

cache_time

No

Indicates the maximum duration for caching database query results in the memory. The unit is millisecond. The default value is 10000. The value 0 indicates that caching is disabled.

Precautions

  1. Ensure that you have created a Redis cache instance on DCS using your account.

    For details about how to create a Redis cache instance, see the Distributed Cache Service User Guide.

  2. In this scenario, jobs must run on the exclusive cluster of CS. Therefore, CS must interconnect with the VPC that has been connected with DCS clusters. You can also set the security group rules as required.

    For details about how to set up the VPC peering connection, see VPC Peering Connection in the Cloud Stream Service User Guide.

    For details about how to configure security group rules, see Security Group in the Virtual Private Cloud User Guide.

Example

The Redis table is used to connect to the source stream.
CREATE TABLE table_a (attr1 string, attr2 string, attr3 string)
WITH (
  type = "dcs_redis",
  value_type = "hash",
  key_column = "attr1",
  hash_key_column = "attr2",
  cluster_address = "192.168.1.238:6379",
  password = "xxxxxxxx"
);