The Redis library is optional. In order to use this library, you must require it in one of your source files (preferably main.lua) prior to use. It only needs to be required once in a single file. It is recommended you do this at the top of your main.lua file, outside of any functions or other code, and you may do this by using this code:
Instantiates a new Redis client object. The constructor has no side effects and accepts no parameters.
You must call the connect() method to initiate a connection to a Redis server.
Connects to a remote Redis server. All parameters are optional. If you do not specify a hostname or port, defaults "127.0.0.1" and 6379 will be used.
Closes the connection to the Redis server; this will completely destroy and free the socket.
Sends a command to the remote Redis server. The result of the operation will be returned.
Retrieve the value for a key stored in Redis. Returns
Redis:get() should only be used with key-value pairs and not against a list (see: Redis:push()).
Sets a value in Redis with optional expiry. If expiry is not given, then the key will persist until the delete command is called. If expiry is given, it should be in seconds. Floating-point numbers (for example, 1.5) are acceptable.
If everything went well, either "OK" or the previous value will be returned. If there was an error,
then
Removes a key from the Redis store. The number of items removed will be returned.
Return a list of keys that match a given pattern. This function can be relatively slow for larger databases and it is recommended that you only use this for debugging.
See also: Redis:scan()
Iterates over the database and returns keys that match a given pattern. If no pattern is given, then all available keys should be returned. You may use "*" as a wildcard character.
Adds one or more items to the end of the list for the given key. Any given items will preserve the order they were pushed in. That is, if you push the values "a", "b" and "c", then push "d", "e" and "f", the full list will contain "a", "b", "c", "d", "e", "f".
If the list with the given key does not exist, one will be created for you.
Exactly the same as Redis:push(), except that this adds the items to the front of the list.
Items will retain the order they were pushed. For example if you push "a", "b" and "c", then push "1", "2" and "3", the full list will be "1", "2", "3", "a", "b", "c"
Removes items from the end of the list. If `count` is given, then that many items will be removed, otherwise only the last item will be removed.
Removed items will also be returned.
Exactly like Redis:pop(), except that it removes items from the front of the list.
Can be used to retrieve items from within a list. If neither `from` nor `to` are given, the full list will be returned. If only `from` is given, then items beginning on that index until the end of the list will be returned.
The indexes are 0-based. That means that the first item is index 0, the second item is index 1, and so on. Therefore, a value of 1 for `from` will result in returning items beginning on the second item.
You may pass negative numbers to specify values relative to the end of the list. -1 would be the last item in the list, -2 the second to last, and so on. For example, to return only the last 3 items, you could pass -3 for `from`.
Increments a value by the given amount. If the `amount` isn't given, a value of 1 will be assumed. If the key does not already exist, it will be assumed to have been 0.
Exactly the same as Redis:increment(), except that this will subtract rather than add.
Page last updated at 2021-11-01 18:59:26