![]() 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. If you skipped the Introduction, we strongly recommend reading it before moving on to the rest of the documentation.Redis is a popular in-memory grid used for interprocess communication and data storage. If you intend to use Composition API without a build step, consult the usage of the setup() option. Many of the examples for Composition API will be using the syntax. Using Composition API without a Build Step # If you are using VSCode, you can install the es6-string-html extension and prefix the strings with a /*html*/ comment to get syntax highlighting for them. You may have noticed that the imported component's template is inlined as a JavaScript string. You can also use any other HTTP server that can serve static files with the correct MIME types. To start a local HTTP server, first install Node.js and then run npx serve from the command line in the same directory where your HTML file is. In order for this to work, you need to serve your index.html over the protocol, with a local HTTP server. If you directly open the above index.html in your browser, you will find that it throws an error because ES modules cannot work over the file:// protocol. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |