X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/6eaad66373982aa9c1c0ff6b584c542670548d0e..c0caa1cf542d452fdc1eb74a7e5511c683ec5d5d:/deps/hiredis/hiredis.h?ds=inline diff --git a/deps/hiredis/hiredis.h b/deps/hiredis/hiredis.h index 1412a344..a73f50e9 100644 --- a/deps/hiredis/hiredis.h +++ b/deps/hiredis/hiredis.h @@ -1,6 +1,6 @@ /* - * Copyright (c) 2009-2010, Salvatore Sanfilippo - * Copyright (c) 2010, Pieter Noordhuis + * Copyright (c) 2009-2011, Salvatore Sanfilippo + * Copyright (c) 2010-2011, Pieter Noordhuis * * All rights reserved. * @@ -33,10 +33,11 @@ #define __HIREDIS_H #include /* for size_t */ #include /* for va_list */ +#include /* for struct timeval */ #define HIREDIS_MAJOR 0 -#define HIREDIS_MINOR 9 -#define HIREDIS_PATCH 2 +#define HIREDIS_MINOR 10 +#define HIREDIS_PATCH 1 #define REDIS_ERR -1 #define REDIS_OK 0 @@ -45,10 +46,11 @@ * error that occured. REDIS_ERR_IO means there was an I/O error and you * should use the "errno" variable to find out what is wrong. * For other values, the "errstr" field will hold a description. */ -#define REDIS_ERR_IO 1 /* error in read or write */ -#define REDIS_ERR_EOF 3 /* eof */ -#define REDIS_ERR_PROTOCOL 4 /* protocol error */ -#define REDIS_ERR_OTHER 2 /* something else */ +#define REDIS_ERR_IO 1 /* Error in read or write */ +#define REDIS_ERR_EOF 3 /* End of file */ +#define REDIS_ERR_PROTOCOL 4 /* Protocol error */ +#define REDIS_ERR_OOM 5 /* Out of memory */ +#define REDIS_ERR_OTHER 2 /* Everything else... */ /* Connection type can be blocking or non-blocking and is set in the * least significant bit of the flags field in redisContext. */ @@ -64,6 +66,16 @@ * should be terminated once all replies have been read. */ #define REDIS_DISCONNECTING 0x4 +/* Flag specific to the async API which means that the context should be clean + * up as soon as possible. */ +#define REDIS_FREEING 0x8 + +/* Flag that is set when an async callback is executed. */ +#define REDIS_IN_CALLBACK 0x10 + +/* Flag that is set when the async context has one or more subscriptions. */ +#define REDIS_SUBSCRIBED 0x20 + #define REDIS_REPLY_STRING 1 #define REDIS_REPLY_ARRAY 2 #define REDIS_REPLY_INTEGER 3 @@ -102,41 +114,63 @@ typedef struct redisReplyObjectFunctions { void (*freeObject)(void*); } redisReplyObjectFunctions; -struct redisContext; /* need forward declaration of redisContext */ - -/* Context for a connection to Redis */ -typedef struct redisContext { - int fd; - int flags; - char *obuf; /* Write buffer */ +/* State for the protocol parser */ +typedef struct redisReader { int err; /* Error flags, 0 when there is no error */ - char *errstr; /* String representation of error when applicable */ + char errstr[128]; /* String representation of error when applicable */ - /* Function set for reply buildup and reply reader */ - redisReplyObjectFunctions *fn; - void *reader; -} redisContext; + char *buf; /* Read buffer */ + size_t pos; /* Buffer cursor */ + size_t len; /* Buffer length */ + redisReadTask rstack[9]; + int ridx; /* Index of current read task */ + void *reply; /* Temporary reply pointer */ + + redisReplyObjectFunctions *fn; + void *privdata; +} redisReader; + +/* Public API for the protocol parser. */ +redisReader *redisReaderCreate(void); +void redisReaderFree(redisReader *r); +int redisReaderFeed(redisReader *r, const char *buf, size_t len); +int redisReaderGetReply(redisReader *r, void **reply); + +/* Backwards compatibility, can be removed on big version bump. */ +#define redisReplyReaderCreate redisReaderCreate +#define redisReplyReaderFree redisReaderFree +#define redisReplyReaderFeed redisReaderFeed +#define redisReplyReaderGetReply redisReaderGetReply +#define redisReplyReaderSetPrivdata(_r, _p) (int)(((redisReader*)(_r))->privdata = (_p)) +#define redisReplyReaderGetObject(_r) (((redisReader*)(_r))->reply) +#define redisReplyReaderGetError(_r) (((redisReader*)(_r))->errstr) + +/* Function to free the reply objects hiredis returns by default. */ void freeReplyObject(void *reply); -void *redisReplyReaderCreate(); -int redisReplyReaderSetReplyObjectFunctions(void *reader, redisReplyObjectFunctions *fn); -int redisReplyReaderSetPrivdata(void *reader, void *privdata); -void *redisReplyReaderGetObject(void *reader); -char *redisReplyReaderGetError(void *reader); -void redisReplyReaderFree(void *ptr); -void redisReplyReaderFeed(void *reader, char *buf, size_t len); -int redisReplyReaderGetReply(void *reader, void **reply); /* Functions to format a command according to the protocol. */ int redisvFormatCommand(char **target, const char *format, va_list ap); int redisFormatCommand(char **target, const char *format, ...); int redisFormatCommandArgv(char **target, int argc, const char **argv, const size_t *argvlen); +/* Context for a connection to Redis */ +typedef struct redisContext { + int err; /* Error flags, 0 when there is no error */ + char errstr[128]; /* String representation of error when applicable */ + int fd; + int flags; + char *obuf; /* Write buffer */ + redisReader *reader; /* Protocol reader */ +} redisContext; + redisContext *redisConnect(const char *ip, int port); +redisContext *redisConnectWithTimeout(const char *ip, int port, struct timeval tv); redisContext *redisConnectNonBlock(const char *ip, int port); redisContext *redisConnectUnix(const char *path); +redisContext *redisConnectUnixWithTimeout(const char *path, struct timeval tv); redisContext *redisConnectUnixNonBlock(const char *path); -int redisSetReplyObjectFunctions(redisContext *c, redisReplyObjectFunctions *fn); +int redisSetTimeout(redisContext *c, struct timeval tv); void redisFree(redisContext *c); int redisBufferRead(redisContext *c); int redisBufferWrite(redisContext *c, int *done); @@ -150,9 +184,9 @@ int redisGetReplyFromReader(redisContext *c, void **reply); /* Write a command to the output buffer. Use these functions in blocking mode * to get a pipeline of commands. */ -void redisvAppendCommand(redisContext *c, const char *format, va_list ap); -void redisAppendCommand(redisContext *c, const char *format, ...); -void redisAppendCommandArgv(redisContext *c, int argc, const char **argv, const size_t *argvlen); +int redisvAppendCommand(redisContext *c, const char *format, va_list ap); +int redisAppendCommand(redisContext *c, const char *format, ...); +int redisAppendCommandArgv(redisContext *c, int argc, const char **argv, const size_t *argvlen); /* Issue a command to Redis. In a blocking context, it is identical to calling * redisAppendCommand, followed by redisGetReply. The function will return