Scripts
Apply lua scripts on redis server

Overview

Running lua scripts can be done using the runScripts method
1
runScripts(...scripts: Array<ScriptResource>): Promise<any>
Copied!
The ScriptResource provides an API for loading inline scripts and file scripts

Inline scripts

Using the ofScript method allows us to create a script from inline text

Example:

1
const inlineScriptResource = ScriptResource.OfScript('return redis.call("HSET",KEYS[1],ARGV[1],ARGV[2])')
2
.setKeys('myKey')
3
.setArgs('FIELD', 'myValue');
4
await RedisProvider.GetConnection().runScripts(inlineScriptResource);
Copied!

File scripts

Using the ofFile method allows us to create a script from inline text

Example:

1
const fileScriptResource = OfFile(__dirname + '/lua-scripts/myScript.lua')
2
.setKeys('myKey')
3
.setArgs('FIELD', 'myValue');
4
await RedisProvider.GetConnection().runScripts(fileScriptResource);
Copied!
Last modified 2yr ago