JSON fixes.

master
Nicolas Favre-Felix 14 years ago
parent 2507fcee72
commit fcb4ed5e2c

@ -1,6 +1,6 @@
# About
A very simple prototype providing an HTTP interface to Redis.
A very simple prototype providing an HTTP interface to Redis. It uses [hiredis](https://github.com/antirez/hiredis) and [jansson](https://github.com/akheron/jansson).
<pre>
make clean all
@ -19,12 +19,12 @@ curl -d "GET/hello" http://127.0.0.1:7379/
* Add meta-data info per key (MIME type in a second key, for instance)
* Find a way to format multi-bulk data
* Support PUT, DELETE, HEAD?
* Add JSON output
* Add JSONP callbacks
* Add support for Redis UNIX socket
* Enrich config file
* Provide timeout
* Restrict commands by IP range
* Add your own here or send your suggestions on twitter [@yowgi](http://twitter.com/yowgi).
# HTTP error codes
* Missing key: 404 Not Found
@ -34,10 +34,27 @@ curl -d "GET/hello" http://127.0.0.1:7379/
# JSON output
## /GET/x
`{"GET": "value here"}`
The URI `/COMMAND/arg0/arg1/.../argN` returns a JSON object with the command as a key and the result as a value.
## /INCR/y
`{"INCR": 42}`
**Examples:**
<pre>
// string
$ curl http://127.0.0.1:7379/GET/y
{"GET":"42"}
// 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'"]}
</pre>

@ -61,20 +61,19 @@ json_encode(const struct cmd *cmd, const redisReply *r) {
switch(r->type) {
case REDIS_REPLY_STATUS:
case REDIS_REPLY_ERROR:
jlist = json_array();
json_array_append_new(jlist,
r->type == REDIS_REPLY_ERROR ? json_false() : json_true());
json_array_append_new(jlist, json_string(r->str));
json_object_set(jroot, verb, jlist);
json_object_set_new(jroot, verb, jlist);
break;
case REDIS_REPLY_STRING:
json_object_set(jroot, verb, json_string(r->str));
json_object_set_new(jroot, verb, json_string(r->str));
break;
case REDIS_REPLY_INTEGER:
json_object_set(jroot, verb, json_integer(r->integer));
json_object_set_new(jroot, verb, json_integer(r->integer));
break;
case REDIS_REPLY_ARRAY:
@ -93,11 +92,11 @@ json_encode(const struct cmd *cmd, const redisReply *r) {
break;
}
}
json_object_set(jroot, verb, jlist);
json_object_set_new(jroot, verb, jlist);
break;
default:
json_object_set(jroot, verb, json_null());
json_object_set_new(jroot, verb, json_null());
break;
}

Loading…
Cancel
Save