![]() According to the documentation: Redis uses the same Lua interpreter to run all the commands In the case of the set command, these arguments are key and value. The first argument is the name of this command followed by its parameters. With redis.call you can execute any Redis command. Our first script consists of a single statement: the redis.call function: redis.call(‘set’, KEYS, ARGV) Can you explain the script? Doge after seeing the script above The output should be ”value”, which means that the previous script successfully set the key “key:name”. We are going to do this by running another script which gets the key from Redis:Įval “return redis.call(‘get’, KEYS)” 1 key:name Let’s now check if the script completed successfully. So you shouldn’t specify KEYS as 0 and then provide all keys within the ARGV table. It is considered a good practice to provide keys which the script uses as KEYS, and all other arguments as ARGV. As you already guessed, the above command sets the key key:name to value value. In this example, we provide a single ARGV-argument: string value. We can provide any number of arguments after the keys, which will be available in Lua as the ARGV table. Note, that Lua indexed tables start with index 1, not 0. In our case, it contains a single value key:name at index 1. They are accessible as KEYS table within the script. Immediately after this number, we need to provide these keys, one after another. We specify how many keys the script requires with the number immediately following it. Script arguments fall into two groups: KEYS and ARGV. ![]() The ”redis.call(‘set’, KEYS, ARGV)”string is our script which is functionally identical to the Redis’s set command. The EVAL command is what tells Redis to run the script which follows. Now run the following command: eval “redis.call(‘set’, KEYS, ARGV)” 1 key:name value Let’s start by running scripts via redis-cli. Also, I am providing working examples in this article. If you know any language of the C family, you should be okay with Lua. But I don’t know any Lua A person who doesn't know any luaĭon’t worry, Lua is not very hard to understand. I describe this in detail closer to the end of this article. No other Redis command can run while a script is executing.įor example, I use Lua scripts to change JSON strings stored in Redis. ![]() Also, all steps within a script are executed in an atomic way.Instead of doing these steps in the language of your application, you can do it inside Redis with Lua. Most tasks you do in Redis involve many steps. It might be helpful to check Redis commands reference while reading. You should have Redis installed on your system to follow this guide. ![]() You might’ve heard that it lets you run Lua scripts, but you are still not sure why. Redis is a popular in-memory grid used for interprocess communication and data storage. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |