6

I'm trying to get Redis to allow EVAL (http://redis.io/commands/EVAL) to make HTTP requests.

Two modules: LuaCURL and Luasocket give this ability. The Redis source code has a directory with additional modules (such as cjson) http://download.redis.io/redis-stable/deps/lua/src/, I tried adding luacurl.c but I recieved error after error. I have managed to compile it enabling os.execute - by editing scripting.c - which allows me to run the curl command but that is a bad solution.

How do I compile HTTP requests in Redis's Lua?

Presumably the easiest way to do this would to be have a standalone luasocket.so file, but I'm not sure how to do that.

user3786834
  • 127
  • 8

2 Answers2

3

No worries, all I required was a nights sleep to have a fresh mind.

I downloaded http://files.luaforge.net/releases/luacurl/luacurl and move the luacurl.c into the /deps/lua/src/ folder and edited line 23 from

#include <lauxlib.h>

to

#include "lauxlib.h"

and then in /deps/lua/src/Makefile (Lua's makefile, not Redis's) go to line 30 and find

lua_cjson.o

add "luacurl.o" spaced next to it like so

lua_cjson.o luacurl.o

and then in /src/Makefile (Redis's makefile, not Lua's) change line 54 from

FINAL_LIBS=-lm

to

FINAL_LIBS=-lm -lcurl

Finally, make sure you have installed "yum install curl-devel" and then compile it.

Keep in mind that no other client can execute commands whilst the server is busy with Lua scripts.

user3786834
  • 127
  • 8
0

Installing custom Lua modules in Redis requires recompiling Redis from source, using a procedure like user3786834 laid out. If you really need to use some particular module, that might be your only choice.

However, if your library uses only Lua code (no C code), the simplest option, which also increases your application's portability, might be to include that module's source code directly into your EVAL script.

sffc
  • 382
  • 1
  • 3
  • 11