Troubleshooting Redis Connection Failures
Overview
This topic describes why Redis connection problems occur and how to solve the problems.
Problem Classification
To troubleshoot abnormal connections to a Redis instance, check the following items:
Connection Between Redis and the ECS
The ECS where the client is located must be in the same VPC as the Redis instance and be able to communicate with the Redis instance.
- For a Redis 3.0 instance, check the security group rules of the instance and the ECS.
Correctly configure security group rules for the ECS and the Redis instance to allow the Redis instance to be accessed. For details, see Security Group Configurations.
- For a DCS Redis 4.0/5.0/6.0 instance, check the whitelist of the instance.
If the instance has a whitelist, ensure that the client IP address is included in the whitelist. Otherwise, the connection will fail. For details, see Managing IP Address Whitelist. If the client IP address has changed, add the new IP address to the whitelist.
- Check the regions of the Redis instance and the ECS.
If the Redis instance and the ECS are not in the same region, create another Redis instance in the same region as the ECS and migrate data from the old instance to the new instance by referring to the Data Migration Guide.
- Check the VPCs of the Redis instance and the ECS.
Different VPCs cannot communicate with each other. An ECS cannot access a Redis instance if they are in different VPCs. You can establish VPC peering connections to allow the ECS to access the Redis instance across VPCs.
For details, see "VPC Peering Connection" in the Virtual Private Cloud User Guide.
Password
If the instance password is incorrect, the port can still be accessed but the authentication will fail. If you forget the password, you can reset the password.
Instance Configuration
If a connection to Redis is rejected, log in to the DCS console, go to the instance details page, and modify the maxclients parameter. For details, see Modifying Configuration Parameters.
Client Connections
- The connection fails when you use redis-cli to connect to a Redis Cluster instance.
Solution: Check whether -c is added to the connection command. Ensure that the correct connection command is used when connecting to the cluster nodes.
For details, see Accessing a DCS Redis Instance Through redis-cli.
- Error "Read timed out" or "Could not get a resource from the pool" occurs.
- Check if the KEYS command has been used. This command consumes a lot of resources and can easily block Redis. Instead, use the SCAN command and avoid executing the command frequently.
- Check if the DCS instance is Redis 3.0. Redis 3.0 uses SATA disks. During AOF persistence, the disk performance may occasionally deteriorate and cause a connection failure. In this case, disable AOF persistence if data persistence is not required. Alternatively, you can use a DCS Redis 4.0 or 5.0 instance because they use SSD disks that offer higher performance.
- Error "unexpected end of stream" occurs and causes service exceptions.
- Optimize the Jedis connection pool by referring to Recommended Jedis Parameter Settings.
- Check whether there are many big keys. For details, see How Do I Avoid Big Keys and Hot Keys?
- The connection is interrupted.
- Modify the application timeout duration.
- Optimize the service to avoid slow queries.
- Replace the KEYS command with the SCAN command.
- If an error occurs when you use the Jedis connection pool, see What Should I Do If an Error Is Returned When I Use the Jedis Connection Pool?
Bandwidth
If the bandwidth reaches the upper limit of the corresponding instance specifications, Redis connections may time out.
You can view the Flow Control Times metric to check whether the bandwidth has reached the upper limit.
Then, check whether the instance has big keys and hot keys. If a single key is too large or overloaded, operations on the key may occupy too many bandwidth resources. For details about big keys and hot keys, see Analyzing Big Keys and Hot Keys.
Redis Performance
Connections to an instance may become slow or time out if the CPU usage spikes due to resource-consuming commands such as KEYS, or too much memory is used because the expiration time is not set for the instance or expired keys remain in the memory. In these cases, do as follows:
- Use the SCAN command instead of the KEYS command, or disable the KEYS command.
- Check the monitoring data and configure alarm rules. For details, see Configuring Alarm Rules for Critical Metrics.
For example, you can view the Memory Usage and Used Memory metrics to keep track of the instance memory usage, and view the Connected Clients metric to determine whether the instance connections limit has been reached.
- Check whether the instance has big keys and hot keys.
For details about the operations of big key and hot key analysis, see Analyzing Big Keys and Hot Keys.
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