Commit 8b8b7afe authored by Pieter Noordhuis's avatar Pieter Noordhuis
Browse files

Change README to Markdown

parent 3dfacba4
...@@ -8,7 +8,7 @@ at the same time it uses an high level printf-alike API in order to make it ...@@ -8,7 +8,7 @@ at the same time it uses an high level printf-alike API in order to make it
much higher level than otherwise suggested by its minimal code base and the much higher level than otherwise suggested by its minimal code base and the
lack of explicit bindings for every Redis command. lack of explicit bindings for every Redis command.
Hiredis only supports the Redis new protocol, so you can use it with any Hiredis only supports the new Redis protocol, so you can use it with any
Redis version >= 1.2.0. Redis version >= 1.2.0.
HIREDIS API HIREDIS API
...@@ -16,9 +16,9 @@ HIREDIS API ...@@ -16,9 +16,9 @@ HIREDIS API
Hiredis exports only three function calls: Hiredis exports only three function calls:
redisReply *redisConnect(int *fd, char *ip, int port); redisReply *redisConnect(int *fd, char *ip, int port);
redisReply *redisCommand(int fd, char *format, ...); redisReply *redisCommand(int fd, char *format, ...);
void freeReplyObject(redisReply *r); void freeReplyObject(redisReply *r);
The first function is used in order to create a connection to the Redis server: The first function is used in order to create a connection to the Redis server:
...@@ -37,18 +37,18 @@ is not NULL: ...@@ -37,18 +37,18 @@ is not NULL:
} }
When a reply object returns an error, the reply->type is set to the value When a reply object returns an error, the reply->type is set to the value
REDIS_REPLY_ERROR, and reply->reply points to a C string with the description `REDIS_REPLY_ERROR`, and reply->reply points to a C string with the description
of the error. of the error.
In the above example we don't check for reply->type as redisConnect() can In the above example we don't check for reply->type as `redisConnect()` can
only return NULL or a reply object that is actually an error. only return `NULL` or a reply object that is actually an error.
As you can see redisConnect() will just set (by reference) the fd variable As you can see `redisConnect()` will just set (by reference) the `fd` variable
to the file descriptor of the open socket connected to our Redis server. to the file descriptor of the open socket connected to our Redis server.
Calls to redisCommand() will require this file descriptor as first argument. Calls to `redisCommand()` will require this file descriptor as first argument.
SENDING COMMNADS SENDING COMMANDS
---------------- ----------------
Commands are sent using a printf-alike format. In the simplest form it is Commands are sent using a printf-alike format. In the simplest form it is
...@@ -61,7 +61,7 @@ printf-alike fashion: ...@@ -61,7 +61,7 @@ printf-alike fashion:
reply = redisComand("SET foo %s", somevalue); reply = redisComand("SET foo %s", somevalue);
If your arguments are binary safe, you can use %b that receives the pointer If your arguments are binary safe, you can use "%b" that receives the pointer
to the buffer and a size_t integer with the length of the buffer. to the buffer and a size_t integer with the length of the buffer.
reply = redisCommand("SET %s %b", "foo", somevalue, somevalue_length); reply = redisCommand("SET %s %b", "foo", somevalue, somevalue_length);
...@@ -76,35 +76,35 @@ The following example is valid: ...@@ -76,35 +76,35 @@ The following example is valid:
USING REPLIES USING REPLIES
------------- -------------
redisCommand() returns a reply object. In order to use this object you `redisCommand()` returns a reply object. In order to use this object you
need to test the reply->type field, that can be one of the following types: need to test the reply->type field, that can be one of the following types:
REDIS_REPLY_ERROR * `REDIS_REPLY_ERROR`:
The command returned an error string, that can be read accessing to The command returned an error string, that can be read accessing to
the reply->reply field. the reply->reply field.
REDIS_REPLY_STRING * `REDIS_REPLY_STRING`:
The command returned a string, that can be read accessing to the The command returned a string, that can be read accessing to the
reply->reply field. The string is always nul-termined, but when you reply->reply field. The string is always null-terminated, but when you
need to work with binary-safe strings you can obtain the exact length need to work with binary-safe strings you can obtain the exact length
of the reply with: sdslen(reply->reply). of the reply with: `sdslen(reply->reply)`.
REDIS_REPLY_ARRAY * `REDIS_REPLY_ARRAY`:
The command returned an array of reply->elements elements. The command returned an array of reply->elements elements.
Every element is a redisReply object, stored at redis->element[..index..] Every element is a redisReply object, stored at redis->element[..index..]
Redis may reply with nexted arrays but this is fully supported. Redis may reply with nested arrays but this is fully supported.
REDIS_REPLY_INTEGER * `REDIS_REPLY_INTEGER`:
The command replies with an integer. It's possible to access this integer The command replies with an integer. It's possible to access this integer
using the reply->integer field that is of type "long long". using the reply->integer field that is of type "long long".
REDIS_REPLY_NIL * `REDIS_REPLY_NIL`:
The command replies with a NIL special object. There is no data to access. The command replies with a NIL special object. There is no data to access.
FREEING REPLIES FREEING REPLIES
--------------- ---------------
Replies should be freed using the freeReplyObject() function. Replies should be freed using the `freeReplyObject()` function.
Note that this function will take care of freeing sub-replies objects Note that this function will take care of freeing sub-replies objects
contained in arrays and nested arrays, so there is no need for the user to contained in arrays and nested arrays, so there is no need for the user to
free the sub replies (it is actually harmful and will corrupt the memory). free the sub replies (it is actually harmful and will corrupt the memory).
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment