apoc.redis.eval

Procedure APOC Full

apoc.redis.eval(uri, script, outputType, keys, values, {config}) | Execute the 'EVAL script' command. In the parameters provided to the procedure, keys are bound to the KEYS[n] like special array of the Lua script and values are bound to the ARGV[n] like special array of the Lua script.

Signature

apoc.redis.eval(uri :: STRING?, script :: STRING?, outputType :: STRING?, keys :: LIST? OF ANY?, values :: LIST? OF ANY?, config = {} :: MAP?) :: (value :: ANY?)

Input parameters

Name Type Default

uri

STRING?

null

script

STRING?

null

outputType

STRING?

null

keys

LIST? OF ANY?

null

values

LIST? OF ANY?

null

config

MAP?

{}

Output parameters

Name Type

value

ANY?

Usage Examples

We can do through the apoc.redis.eval procedure, any Lua script executable with the EVAL command

In this procedure, the third parameter in the procedure, in this case VALUE is the ScriptOutputType, that is, the return type of Lua script that can be a BOOLEAN, INTEGER, STATUS, VALUE or MULTI.

The fourth and fifth params, are bound respectively to the KEYS[n] and to the ARGV[n] like special array of the Lua script.

So, if we have a record with key testEval and value valueEval, we can execute the following query:

CALL apoc.redis.eval($uri, 'return redis.call("set", KEYS[1], ARGV[1])', 'VALUE', ['testEval'], ['key:name'], {})

that is equivalent to a redis-cli command eval "return redis.call('set', KEYS[1], ARGV[1])" 1 testEval key:name and returns

Table 1. Results
value

"OK"

Or also, we can execute (without ARGV[n]):

CALL apoc.redis.eval($uri, 'return redis.call("get", KEYS[1])', 'VALUE', ['testEval'], [], {})
Table 2. Results
value

key:name

that is equivalent to a redis-cli command eval "return redis.call('get', KEYS[1])" 1 testEval.