Get subscription relationship from Redis

Set up the Redis environment, and take MacOS X as an example:

  1. $ wget http://download.redis.io/releases/redis-4.0.14.tar.gz
  2. $ tar xzf redis-4.0.14.tar.gz
  3. $ cd redis-4.0.14
  4. $ make && make install
  5. # Start redis
  6. $ redis-server

Create rules:

Open EMQX DashboardGet subscription from Redis - 图1 (opens new window) and select the “Rules” tab on the left.

Then fill in the rule SQL:

  1. SELECT * FROM "$events/client_connected"

Get subscription from Redis - 图2

Related actions:

Select “Add Action” on the “Response Action” interface, and then select “Get Subscription List from Redis” in the “Add Action” drop-down box.

Get subscription from Redis - 图3

Fill in the action parameters:

The action of “Get subscription list from Redis” requires one parameter:

1). Associated resources. The resource drop-down box is empty now, and you can click “New” in the upper right corner to create a Redis resource:

Get subscription from Redis - 图4

Select “Redis single-node mode resources”.

Get subscription from Redis - 图5

Fill in the resource configuration:

Fill in the real Redis server address and keep other configurations at default values. Then, click the “Test Connection” button to ensure that the connection test is successful.

Finally click the “Create” button.

Get subscription from Redis - 图6

Return to the response action interface and click “OK”.

Get subscription from Redis - 图7

Return to the rule creation interface and click “Create”.

Get subscription from Redis - 图8

The rule has been created, and you can insert a subscription relationship into Redis through Redis CLI:

  1. HSET mqtt:sub:test t1 1

Get subscription from Redis - 图9

Log in to the device whose clientid is test via Dashboard:

Get subscription from Redis - 图10

Check the subscription list, and you can see that the test device has subscribed to the t1 topic:

Get subscription from Redis - 图11