You need to enable JavaScript to run this app.
Cache for Redis

Cache for Redis

Copy page
Download PDF
Errors and exceptions
Why does it prompt "ERR unknown command 'READONLY'" when connecting Redis via Redission client?
Copy page
Download PDF
Why does it prompt "ERR unknown command 'READONLY'" when connecting Redis via Redission client?
Problem phenomenon​
When connecting to the Cache for Redis through the Redission client, this error message ERR unknown command 'READONLY' appears. You can view the error message in the following figure.​
​errorcode​​
Possible cause​
For the Redission client in Cluster mode, the default value of ReadMode is SLAVE. The Redission client sends the READONLY command to the Redis database by default. However, Cache for Redis does not support the READONLY command currently. When connecting to a Redis instance through the Redission client in Cluster mode, this error ERR unknown command 'READONLY' may appear. For more details about the commands supported by Cache for Redis, refer to Supported commands.​
Solution​
You can refer to any of the following methods to avoid the above errors.​
Method 1 (recommended): Set Single mode for the Redission client​
The Redission client in Single mode does not use Cluster-related commands (including the READONLY command) to avoid errors such as ERR unknown command 'READONLY'.​
Refer to the code below to set Single mode for the Redission client.​
​
Config config = new Config();​
// Use Single mode​
config.useSingleServer()​
// Access address of Redis instance​
.setAddress("redis://redis-shzlxvk38vs2j****.redis.volces.com:6379")​
// In the example of this article, the default account is used to connect to the Redis database. You only need to set the database login password​
.setPassword("YourPassword");​
RedissonClient redisson = Redisson.create(config);​
​
Method 2: Set ReadMode of Cluster mode to MASTER​
If you need to use the Cluster mode of the Redission client as required by business, you can set ReadMode to MASTER (read data from the primary node only). After setting, the Redission client will not send the READONLY command to a Redis database to avoid ERR unknown command 'READONLY'.​
Refer to the code below to set the ReadMode of the Redission client in Cluster mode to MASTER.​
​
Config config = new Config();​
// Use Cluster mode​
config.useClusterServers()​
// Set ReadMode to MASTER​
.setReadMode(ReadMode.MASTER)​
// Access address of Redis instance​
.addNodeAddress("redis://redis-shzlxvk38vs2j****.redis.volces.com:6379")​
// In the example of this article, the default account is used to connect to the Redis database. You only need to set the database login password​
.setPassword("YourPassword");​
RedissonClient redisson = Redisson.create(config);​
​
​
Last updated: 2025.11.04 21:37:56