First patch your redis to enable the internal package module with the included patch:
patch -p1 < enable-lua-package.patch
Compile it as usual:
make distclean # In case it was built before
make
Grab the copy of LGMP from here: http://members.chello.nl/~w.couwenberg/ (make sure you pick the 5.1 version), direct link: http://members.chello.nl/~w.couwenberg/lgmp.zip
Unpack it to a location, e.g. ~/code/lgmp/ and compile it:
gcc -O2 -Wall -lgmp -o c-gmp.so lgmp.c -shared -fPIC -L ~/code/redis/deps/lua/src/ -I ~/code/redis/deps/lua/src
Adjust the paths for -L
and -I
to point to the Lua bundled with Redis.
When this is done, start Redis from the directory with the gmp.lua
and c-gmp.so
:
~/code/redis/src/redis-server &
Now fire up redis-cli
and use gmp:
~/code/redis/src/redis-cli
127.0.0.1:6379> eval "local gmp=require'gmp'; return gmp.version" 0
"6.0.0"
127.0.0.1:6379> eval "local gmp=require'gmp'; local x = gmp.z(123); local y = gmp.z(456); return x:add(y):__tostring()" 0
"579"