-
-
Save cbrunnkvist/4fafaf32b3c854b042f6408f0117808a to your computer and use it in GitHub Desktop.
Howto implement stored procedures within Redis (-with enable_strict_lua)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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