Using Redis from Scratch
This section describes how to create a Redis cluster, connect to the Redis cluster, and write and read data.
Prerequisites
- The client has been installed, for example, in /opt/client. The client directory in the following operations is only an example. Change it based on site requirements.
- A role (for example, Redisrole) has been created on Manager by referring to Creating a Redis Role.
- A Human-Machine user (for example, jedis) has been created on Manager and bound to the Redisrole role.
Procedure
- Create a Redis cluster. For details, see Creating a Redis Cluster.
- Log in to the node where the client is located and run the following commands to authenticate user jedis: Assume that the client installation path is /opt/client.
cd /opt/client
source bigdata_env
kinit jedis (For a cluster in security mode, you need to change the password upon the first login. For a cluster in common mode, you do not need to run this command.)
- Run the following command to connect to the Redis cluster:
/opt/client/Redis/bin/redis-cli -h <hostip> -p <Port> -c --realm hadoop.com
- hostip indicates the IP address (service plane) of an instance in the Redis cluster.
- Port indicates the port number of the Redis instance.
The formula for calculating the port number of the Redis instance is: 22400 + Instance ID – 1.
To view the instance ID, choose Cluster > Name of the desired cluster > Service > Redis > Redis Manager on FusionInsight Manager and click the target Redis cluster name.
For example, in the Redis cluster, the port number of the Redis instance that corresponds to the role R1 port is 22400 (22400 + 1 – 1 = 22400).
- Enabling channel encryption for Redis
Log in to FusionInsight Manager, choose Cluster > Services > Redis > Configurations > All Configurations, search for REDIS_SSL_ON, and set the parameter value to true to enable SSL channel encryption for Redis. Channel encryption encrypts data during data transfer but affects performance. Do not enable this function (set REDIS_SSL_ON to false) when Redis does not contain important or sensitive data.
After the channel encryption is enabled, run the following command to connect to the cluster:
/opt/client/Redis/bin/redis-cli -h <hostip> -p <Port> --tls -c --realm hadoop.com
- Run the set command to write data:
hostip:Port> set myname "redis"
The following command output is displayed:
hostip:Port> set myname "redis" -> Redirected to slot [12807] located at 10.112.17.189:22404 OK
- Run the get command to read data:
hostip:Port> get myname
The following command output is displayed:
hostip:Port> get myname "redis"
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot