Skip to content

Instantly share code, notes, and snippets.

@cbrunnkvist
Forked from rbraband/example 1
Last active October 31, 2019 13:04
Show Gist options
  • Save cbrunnkvist/4fafaf32b3c854b042f6408f0117808a to your computer and use it in GitHub Desktop.
Save cbrunnkvist/4fafaf32b3c854b042f6408f0117808a to your computer and use it in GitHub Desktop.
Howto implement stored procedures within Redis (-with enable_strict_lua)
# Step 0 -- create test data
redis-cli HSET :object:30343552:data foo bar
# Step 1 -- store sample function 'sampleFunction'
redis-cli SET :functions:sample1 "
redis.call('SELECT', 0);
local data = redis.call('HGETALL', ':object:' .. ARGV[1] .. ':data');
return table.concat(data, '+');
"
# Step 2 -- create function loader
functionId=$( redis-cli SCRIPT LOAD "return loadstring(redis.call('get',':functions:' .. KEYS[1])) ()" )
echo $functionId
# ->
# f7f45841b566126a895857bb2e87890ee94f11bc
# Step 3 -- test
redis-cli EVALSHA $functionId 1 sample1 30343552
# ->
# "foo+bar"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment