A Redis HTTP interface with JSON output
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
Nicolas Favre-Felix de5c2839e4 Added IP range restriction. 14 years ago
formats Improved raw Redis output. 14 years ago
hiredis Added UNIX socket support. 14 years ago
jansson Small refactoring. 14 years ago
Makefile Better default CFLAGS. 14 years ago
README.markdown Added IP range restriction. 14 years ago
cmd.c Added IP range restriction. 14 years ago
cmd.h Added IP range restriction. 14 years ago
conf.c Added IP range restriction. 14 years ago
conf.h Added IP range restriction. 14 years ago
server.c Removed global variables. 14 years ago
server.h Removed global variables. 14 years ago
turnip.c Added IP range restriction. 14 years ago
turnip.json Added IP range restriction. 14 years ago

README.markdown

About

A very simple prototype providing an HTTP interface to Redis. It uses hiredis and jansson.

make clean all
./turnip &
curl http://127.0.0.1:7379/SET/hello/world
→ {"SET":[true,"OK"]}
curl http://127.0.0.1:7379/GET/hello
→ {"GET":"world"}

curl -d "GET/hello" http://127.0.0.1:7379/
→ {"GET":"world"}

Features

  • GET and POST are supported.
  • JSON output by default, optional JSONP parameter.
  • Raw Redis 2.0 protocol output with ?format=raw
  • HTTP 1.1 pipelining (45 kqps on a desktop Linux machine.)
  • Connects to Redis using a TCP or UNIX socket.
  • Restricted commands by IP range (CIDR subnet + mask), returning 403 errors.

Ideas, TODO...

  • Add meta-data info per key (MIME type in a second key, for instance).
  • Support PUT, DELETE, HEAD?
  • Support pub/sub.
  • Disable MULTI/EXEC/DISCARD/WATCH.
  • Add logging.
  • Enrich config file:
    • Provide timeout (this needs to be added to hiredis first.)
  • Get config file path from command line.
  • Send your ideas using the github tracker or on twitter @yowgi.

HTTP error codes

  • Unknown HTTP verb: 405 Method Not Allowed
  • Redis is unreachable: 503 Service Unavailable
  • Could also be used:
    • Timeout on the redis side: 503 Service Unavailable
    • Missing key: 404 Not Found
    • Unauthorized command (disabled in config file): 403 Forbidden

Command format

The URI /COMMAND/arg0/arg1/.../argN executes the command on Redis and returns the response to the client. GET and POST are supported:

  • GET /COMMAND/arg0/.../argN
  • POST / with COMMAND/arg0/.../argN in the HTTP body.

JSON output

JSON is the default output format. Each command returns a JSON object with the command as a key and the result as a value.

Examples:

// string
$ curl http://127.0.0.1:7379/GET/y
{"GET":"41"}

// number
$ curl http://127.0.0.1:7379/INCR/y
{"INCR":42}

// list
$ curl http://127.0.0.1:7379/LRANGE/x/0/1
{"LRANGE":["abc","def"]}

// status
$ curl http://127.0.0.1:7379/TYPE/y
{"TYPE":[true,"string"]}

// error, which is basically a status
$ curl http://127.0.0.1:7379/MAKE-ME-COFFEE
{"MAKE-ME-COFFEE":[false,"ERR unknown command 'MAKE-ME-COFFEE'"]}

// JSONP callback:
$ curl  "http://127.0.0.1:7379/TYPE/y?jsonp=myCustomFunction"
myCustomFunction({"TYPE":[true,"string"]})

RAW output

This is the raw output of Redis; enable it with ?format=raw.


// string
$ curl http://127.0.0.1:7379/GET/z?format=raw
$5
hello

// number
curl http://127.0.0.1:7379/INCR/a?format=raw
:2

// list
$ curl http://127.0.0.1:7379/LRANGE/x/0/-1?format=raw
*2
$3
abc
$3
def

// status
$ curl http://127.0.0.1:7379/TYPE/y?format=raw
+zset

// error, which is basically a status
$ curl http://127.0.0.1:7379/MAKE-ME-COFFEE?format=raw
-ERR unknown command 'MAKE-ME-COFFEE'