ApsaraDB for Redis instances of all editions support Lua commands.

Support for Lua commands

The use of Lua scripts improves the performance of Redis. With the built-in Lua support, Redis is able to perform an efficient check-and-set (CAS) operation on commands. It also allows you to combine and run multiple commands in an efficient manner.

Note If you fail to run an EVAL command and the error message ERR command eval not support for normal user is returned, you can upgrade the minor version and try again. For more information, see Upgrade the minor version. During the upgrade, the instance may be disconnected and become read-only within seconds. We recommend that you upgrade the version of an instance during off-peak hours.

Limits on Lua scripts

To ensure that all operations in a Lua script are performed in the same hash slot, the cluster edition of ApsaraDB for Redis sets the following limits on a Lua script:

  • The Lua script uses the redis.call/redis.pcall function to call Redis commands. For these commands, all the keys must be passed by using the KEYS array, which cannot be replaced by Lua variables. Otherwise, the following error message is returned:
    -ERR bad lua script for redis cluster, all the keys that the script uses should be passed using the KEYS arrayrn
  • All the keys that the script uses must be allocated in the same hash slot. Otherwise, the following error message is returned:
    -ERR eval/evalsha command keys must be in same slotrn
  • Keys must be passed for all the commands to be called. Otherwise, the following error message is returned:
    -ERR for redis cluster, eval/evalsha number of keys can't be negative or zerorn
Note If you can ensure that all operations are performed in the same hash slot in the code and want to break the Lua limits of Redis Cluster, you can set the script_check_enable parameter to 0 in the console. Then, the system does not check the Lua script at the backend. For more information about how to set this parameter, see Set parameters.