diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2026-01-21 22:52:54 +0100 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2026-01-21 22:52:54 +0100 |
| commit | dcacc00e3750300617ba6e16eb346713f91a783a (patch) | |
| tree | 38e2d4fb5ed9d119711d4295c6eda4b014af73fd /examples/redis-unstable/deps/hiredis/hiredis.h | |
| parent | 58dac10aeb8f5a041c46bddbeaf4c7966a99b998 (diff) | |
| download | crep-dcacc00e3750300617ba6e16eb346713f91a783a.tar.gz | |
Remove testing data
Diffstat (limited to 'examples/redis-unstable/deps/hiredis/hiredis.h')
| -rw-r--r-- | examples/redis-unstable/deps/hiredis/hiredis.h | 362 |
1 files changed, 0 insertions, 362 deletions
diff --git a/examples/redis-unstable/deps/hiredis/hiredis.h b/examples/redis-unstable/deps/hiredis/hiredis.h deleted file mode 100644 index 635988b..0000000 --- a/examples/redis-unstable/deps/hiredis/hiredis.h +++ /dev/null | |||
| @@ -1,362 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2009-2011, Salvatore Sanfilippo <antirez at gmail dot com> | ||
| 3 | * Copyright (c) 2010-2014, Pieter Noordhuis <pcnoordhuis at gmail dot com> | ||
| 4 | * Copyright (c) 2015, Matt Stancliff <matt at genges dot com>, | ||
| 5 | * Jan-Erik Rediger <janerik at fnordig dot com> | ||
| 6 | * | ||
| 7 | * All rights reserved. | ||
| 8 | * | ||
| 9 | * Redistribution and use in source and binary forms, with or without | ||
| 10 | * modification, are permitted provided that the following conditions are met: | ||
| 11 | * | ||
| 12 | * * Redistributions of source code must retain the above copyright notice, | ||
| 13 | * this list of conditions and the following disclaimer. | ||
| 14 | * * Redistributions in binary form must reproduce the above copyright | ||
| 15 | * notice, this list of conditions and the following disclaimer in the | ||
| 16 | * documentation and/or other materials provided with the distribution. | ||
| 17 | * * Neither the name of Redis nor the names of its contributors may be used | ||
| 18 | * to endorse or promote products derived from this software without | ||
| 19 | * specific prior written permission. | ||
| 20 | * | ||
| 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
| 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 31 | * POSSIBILITY OF SUCH DAMAGE. | ||
| 32 | */ | ||
| 33 | |||
| 34 | #ifndef __HIREDIS_H | ||
| 35 | #define __HIREDIS_H | ||
| 36 | #include "read.h" | ||
| 37 | #include <stdarg.h> /* for va_list */ | ||
| 38 | #ifndef _MSC_VER | ||
| 39 | #include <sys/time.h> /* for struct timeval */ | ||
| 40 | #else | ||
| 41 | struct timeval; /* forward declaration */ | ||
| 42 | typedef long long ssize_t; | ||
| 43 | #endif | ||
| 44 | #include <stdint.h> /* uintXX_t, etc */ | ||
| 45 | #include "sds.h" /* for hisds */ | ||
| 46 | #include "alloc.h" /* for allocation wrappers */ | ||
| 47 | |||
| 48 | #define HIREDIS_MAJOR 1 | ||
| 49 | #define HIREDIS_MINOR 2 | ||
| 50 | #define HIREDIS_PATCH 0 | ||
| 51 | #define HIREDIS_SONAME 1.1.0 | ||
| 52 | |||
| 53 | /* Connection type can be blocking or non-blocking and is set in the | ||
| 54 | * least significant bit of the flags field in redisContext. */ | ||
| 55 | #define REDIS_BLOCK 0x1 | ||
| 56 | |||
| 57 | /* Connection may be disconnected before being free'd. The second bit | ||
| 58 | * in the flags field is set when the context is connected. */ | ||
| 59 | #define REDIS_CONNECTED 0x2 | ||
| 60 | |||
| 61 | /* The async API might try to disconnect cleanly and flush the output | ||
| 62 | * buffer and read all subsequent replies before disconnecting. | ||
| 63 | * This flag means no new commands can come in and the connection | ||
| 64 | * should be terminated once all replies have been read. */ | ||
| 65 | #define REDIS_DISCONNECTING 0x4 | ||
| 66 | |||
| 67 | /* Flag specific to the async API which means that the context should be clean | ||
| 68 | * up as soon as possible. */ | ||
| 69 | #define REDIS_FREEING 0x8 | ||
| 70 | |||
| 71 | /* Flag that is set when an async callback is executed. */ | ||
| 72 | #define REDIS_IN_CALLBACK 0x10 | ||
| 73 | |||
| 74 | /* Flag that is set when the async context has one or more subscriptions. */ | ||
| 75 | #define REDIS_SUBSCRIBED 0x20 | ||
| 76 | |||
| 77 | /* Flag that is set when monitor mode is active */ | ||
| 78 | #define REDIS_MONITORING 0x40 | ||
| 79 | |||
| 80 | /* Flag that is set when we should set SO_REUSEADDR before calling bind() */ | ||
| 81 | #define REDIS_REUSEADDR 0x80 | ||
| 82 | |||
| 83 | /* Flag that is set when the async connection supports push replies. */ | ||
| 84 | #define REDIS_SUPPORTS_PUSH 0x100 | ||
| 85 | |||
| 86 | /** | ||
| 87 | * Flag that indicates the user does not want the context to | ||
| 88 | * be automatically freed upon error | ||
| 89 | */ | ||
| 90 | #define REDIS_NO_AUTO_FREE 0x200 | ||
| 91 | |||
| 92 | /* Flag that indicates the user does not want replies to be automatically freed */ | ||
| 93 | #define REDIS_NO_AUTO_FREE_REPLIES 0x400 | ||
| 94 | |||
| 95 | /* Flags to prefer IPv6 or IPv4 when doing DNS lookup. (If both are set, | ||
| 96 | * AF_UNSPEC is used.) */ | ||
| 97 | #define REDIS_PREFER_IPV4 0x800 | ||
| 98 | #define REDIS_PREFER_IPV6 0x1000 | ||
| 99 | |||
| 100 | #define REDIS_KEEPALIVE_INTERVAL 15 /* seconds */ | ||
| 101 | |||
| 102 | /* number of times we retry to connect in the case of EADDRNOTAVAIL and | ||
| 103 | * SO_REUSEADDR is being used. */ | ||
| 104 | #define REDIS_CONNECT_RETRIES 10 | ||
| 105 | |||
| 106 | /* Forward declarations for structs defined elsewhere */ | ||
| 107 | struct redisAsyncContext; | ||
| 108 | struct redisContext; | ||
| 109 | |||
| 110 | /* RESP3 push helpers and callback prototypes */ | ||
| 111 | #define redisIsPushReply(r) (((redisReply*)(r))->type == REDIS_REPLY_PUSH) | ||
| 112 | typedef void (redisPushFn)(void *, void *); | ||
| 113 | typedef void (redisAsyncPushFn)(struct redisAsyncContext *, void *); | ||
| 114 | |||
| 115 | #ifdef __cplusplus | ||
| 116 | extern "C" { | ||
| 117 | #endif | ||
| 118 | |||
| 119 | /* This is the reply object returned by redisCommand() */ | ||
| 120 | typedef struct redisReply { | ||
| 121 | int type; /* REDIS_REPLY_* */ | ||
| 122 | long long integer; /* The integer when type is REDIS_REPLY_INTEGER */ | ||
| 123 | double dval; /* The double when type is REDIS_REPLY_DOUBLE */ | ||
| 124 | size_t len; /* Length of string */ | ||
| 125 | char *str; /* Used for REDIS_REPLY_ERROR, REDIS_REPLY_STRING | ||
| 126 | REDIS_REPLY_VERB, REDIS_REPLY_DOUBLE (in additional to dval), | ||
| 127 | and REDIS_REPLY_BIGNUM. */ | ||
| 128 | char vtype[4]; /* Used for REDIS_REPLY_VERB, contains the null | ||
| 129 | terminated 3 character content type, such as "txt". */ | ||
| 130 | size_t elements; /* number of elements, for REDIS_REPLY_ARRAY */ | ||
| 131 | struct redisReply **element; /* elements vector for REDIS_REPLY_ARRAY */ | ||
| 132 | } redisReply; | ||
| 133 | |||
| 134 | redisReader *redisReaderCreate(void); | ||
| 135 | |||
| 136 | /* Function to free the reply objects hiredis returns by default. */ | ||
| 137 | void freeReplyObject(void *reply); | ||
| 138 | |||
| 139 | /* Functions to format a command according to the protocol. */ | ||
| 140 | int redisvFormatCommand(char **target, const char *format, va_list ap); | ||
| 141 | int redisFormatCommand(char **target, const char *format, ...); | ||
| 142 | long long redisFormatCommandArgv(char **target, int argc, const char **argv, const size_t *argvlen); | ||
| 143 | long long redisFormatSdsCommandArgv(hisds *target, int argc, const char ** argv, const size_t *argvlen); | ||
| 144 | void redisFreeCommand(char *cmd); | ||
| 145 | void redisFreeSdsCommand(hisds cmd); | ||
| 146 | |||
| 147 | enum redisConnectionType { | ||
| 148 | REDIS_CONN_TCP, | ||
| 149 | REDIS_CONN_UNIX, | ||
| 150 | REDIS_CONN_USERFD | ||
| 151 | }; | ||
| 152 | |||
| 153 | struct redisSsl; | ||
| 154 | |||
| 155 | #define REDIS_OPT_NONBLOCK 0x01 | ||
| 156 | #define REDIS_OPT_REUSEADDR 0x02 | ||
| 157 | #define REDIS_OPT_NOAUTOFREE 0x04 /* Don't automatically free the async | ||
| 158 | * object on a connection failure, or | ||
| 159 | * other implicit conditions. Only free | ||
| 160 | * on an explicit call to disconnect() | ||
| 161 | * or free() */ | ||
| 162 | #define REDIS_OPT_NO_PUSH_AUTOFREE 0x08 /* Don't automatically intercept and | ||
| 163 | * free RESP3 PUSH replies. */ | ||
| 164 | #define REDIS_OPT_NOAUTOFREEREPLIES 0x10 /* Don't automatically free replies. */ | ||
| 165 | #define REDIS_OPT_PREFER_IPV4 0x20 /* Prefer IPv4 in DNS lookups. */ | ||
| 166 | #define REDIS_OPT_PREFER_IPV6 0x40 /* Prefer IPv6 in DNS lookups. */ | ||
| 167 | #define REDIS_OPT_PREFER_IP_UNSPEC (REDIS_OPT_PREFER_IPV4 | REDIS_OPT_PREFER_IPV6) | ||
| 168 | |||
| 169 | /* In Unix systems a file descriptor is a regular signed int, with -1 | ||
| 170 | * representing an invalid descriptor. In Windows it is a SOCKET | ||
| 171 | * (32- or 64-bit unsigned integer depending on the architecture), where | ||
| 172 | * all bits set (~0) is INVALID_SOCKET. */ | ||
| 173 | #ifndef _WIN32 | ||
| 174 | typedef int redisFD; | ||
| 175 | #define REDIS_INVALID_FD -1 | ||
| 176 | #else | ||
| 177 | #ifdef _WIN64 | ||
| 178 | typedef unsigned long long redisFD; /* SOCKET = 64-bit UINT_PTR */ | ||
| 179 | #else | ||
| 180 | typedef unsigned long redisFD; /* SOCKET = 32-bit UINT_PTR */ | ||
| 181 | #endif | ||
| 182 | #define REDIS_INVALID_FD ((redisFD)(~0)) /* INVALID_SOCKET */ | ||
| 183 | #endif | ||
| 184 | |||
| 185 | typedef struct { | ||
| 186 | /* | ||
| 187 | * the type of connection to use. This also indicates which | ||
| 188 | * `endpoint` member field to use | ||
| 189 | */ | ||
| 190 | int type; | ||
| 191 | /* bit field of REDIS_OPT_xxx */ | ||
| 192 | int options; | ||
| 193 | /* timeout value for connect operation. If NULL, no timeout is used */ | ||
| 194 | const struct timeval *connect_timeout; | ||
| 195 | /* timeout value for commands. If NULL, no timeout is used. This can be | ||
| 196 | * updated at runtime with redisSetTimeout/redisAsyncSetTimeout. */ | ||
| 197 | const struct timeval *command_timeout; | ||
| 198 | union { | ||
| 199 | /** use this field for tcp/ip connections */ | ||
| 200 | struct { | ||
| 201 | const char *source_addr; | ||
| 202 | const char *ip; | ||
| 203 | int port; | ||
| 204 | } tcp; | ||
| 205 | /** use this field for unix domain sockets */ | ||
| 206 | const char *unix_socket; | ||
| 207 | /** | ||
| 208 | * use this field to have hiredis operate an already-open | ||
| 209 | * file descriptor */ | ||
| 210 | redisFD fd; | ||
| 211 | } endpoint; | ||
| 212 | |||
| 213 | /* Optional user defined data/destructor */ | ||
| 214 | void *privdata; | ||
| 215 | void (*free_privdata)(void *); | ||
| 216 | |||
| 217 | /* A user defined PUSH message callback */ | ||
| 218 | redisPushFn *push_cb; | ||
| 219 | redisAsyncPushFn *async_push_cb; | ||
| 220 | } redisOptions; | ||
| 221 | |||
| 222 | /** | ||
| 223 | * Helper macros to initialize options to their specified fields. | ||
| 224 | */ | ||
| 225 | #define REDIS_OPTIONS_SET_TCP(opts, ip_, port_) do { \ | ||
| 226 | (opts)->type = REDIS_CONN_TCP; \ | ||
| 227 | (opts)->endpoint.tcp.ip = ip_; \ | ||
| 228 | (opts)->endpoint.tcp.port = port_; \ | ||
| 229 | } while(0) | ||
| 230 | |||
| 231 | #define REDIS_OPTIONS_SET_UNIX(opts, path) do { \ | ||
| 232 | (opts)->type = REDIS_CONN_UNIX; \ | ||
| 233 | (opts)->endpoint.unix_socket = path; \ | ||
| 234 | } while(0) | ||
| 235 | |||
| 236 | #define REDIS_OPTIONS_SET_PRIVDATA(opts, data, dtor) do { \ | ||
| 237 | (opts)->privdata = data; \ | ||
| 238 | (opts)->free_privdata = dtor; \ | ||
| 239 | } while(0) | ||
| 240 | |||
| 241 | typedef struct redisContextFuncs { | ||
| 242 | void (*close)(struct redisContext *); | ||
| 243 | void (*free_privctx)(void *); | ||
| 244 | void (*async_read)(struct redisAsyncContext *); | ||
| 245 | void (*async_write)(struct redisAsyncContext *); | ||
| 246 | |||
| 247 | /* Read/Write data to the underlying communication stream, returning the | ||
| 248 | * number of bytes read/written. In the event of an unrecoverable error | ||
| 249 | * these functions shall return a value < 0. In the event of a | ||
| 250 | * recoverable error, they should return 0. */ | ||
| 251 | ssize_t (*read)(struct redisContext *, char *, size_t); | ||
| 252 | ssize_t (*write)(struct redisContext *); | ||
| 253 | } redisContextFuncs; | ||
| 254 | |||
| 255 | |||
| 256 | /* Context for a connection to Redis */ | ||
| 257 | typedef struct redisContext { | ||
| 258 | const redisContextFuncs *funcs; /* Function table */ | ||
| 259 | |||
| 260 | int err; /* Error flags, 0 when there is no error */ | ||
| 261 | char errstr[128]; /* String representation of error when applicable */ | ||
| 262 | redisFD fd; | ||
| 263 | int flags; | ||
| 264 | char *obuf; /* Write buffer */ | ||
| 265 | redisReader *reader; /* Protocol reader */ | ||
| 266 | |||
| 267 | enum redisConnectionType connection_type; | ||
| 268 | struct timeval *connect_timeout; | ||
| 269 | struct timeval *command_timeout; | ||
| 270 | |||
| 271 | struct { | ||
| 272 | char *host; | ||
| 273 | char *source_addr; | ||
| 274 | int port; | ||
| 275 | } tcp; | ||
| 276 | |||
| 277 | struct { | ||
| 278 | char *path; | ||
| 279 | } unix_sock; | ||
| 280 | |||
| 281 | /* For non-blocking connect */ | ||
| 282 | struct sockaddr *saddr; | ||
| 283 | size_t addrlen; | ||
| 284 | |||
| 285 | /* Optional data and corresponding destructor users can use to provide | ||
| 286 | * context to a given redisContext. Not used by hiredis. */ | ||
| 287 | void *privdata; | ||
| 288 | void (*free_privdata)(void *); | ||
| 289 | |||
| 290 | /* Internal context pointer presently used by hiredis to manage | ||
| 291 | * SSL connections. */ | ||
| 292 | void *privctx; | ||
| 293 | |||
| 294 | /* An optional RESP3 PUSH handler */ | ||
| 295 | redisPushFn *push_cb; | ||
| 296 | } redisContext; | ||
| 297 | |||
| 298 | redisContext *redisConnectWithOptions(const redisOptions *options); | ||
| 299 | redisContext *redisConnect(const char *ip, int port); | ||
| 300 | redisContext *redisConnectWithTimeout(const char *ip, int port, const struct timeval tv); | ||
| 301 | redisContext *redisConnectNonBlock(const char *ip, int port); | ||
| 302 | redisContext *redisConnectBindNonBlock(const char *ip, int port, | ||
| 303 | const char *source_addr); | ||
| 304 | redisContext *redisConnectBindNonBlockWithReuse(const char *ip, int port, | ||
| 305 | const char *source_addr); | ||
| 306 | redisContext *redisConnectUnix(const char *path); | ||
| 307 | redisContext *redisConnectUnixWithTimeout(const char *path, const struct timeval tv); | ||
| 308 | redisContext *redisConnectUnixNonBlock(const char *path); | ||
| 309 | redisContext *redisConnectFd(redisFD fd); | ||
| 310 | |||
| 311 | /** | ||
| 312 | * Reconnect the given context using the saved information. | ||
| 313 | * | ||
| 314 | * This re-uses the exact same connect options as in the initial connection. | ||
| 315 | * host, ip (or path), timeout and bind address are reused, | ||
| 316 | * flags are used unmodified from the existing context. | ||
| 317 | * | ||
| 318 | * Returns REDIS_OK on successful connect or REDIS_ERR otherwise. | ||
| 319 | */ | ||
| 320 | int redisReconnect(redisContext *c); | ||
| 321 | |||
| 322 | redisPushFn *redisSetPushCallback(redisContext *c, redisPushFn *fn); | ||
| 323 | int redisSetTimeout(redisContext *c, const struct timeval tv); | ||
| 324 | int redisEnableKeepAlive(redisContext *c); | ||
| 325 | int redisEnableKeepAliveWithInterval(redisContext *c, int interval); | ||
| 326 | int redisSetTcpUserTimeout(redisContext *c, unsigned int timeout); | ||
| 327 | void redisFree(redisContext *c); | ||
| 328 | redisFD redisFreeKeepFd(redisContext *c); | ||
| 329 | int redisBufferRead(redisContext *c); | ||
| 330 | int redisBufferWrite(redisContext *c, int *done); | ||
| 331 | |||
| 332 | /* In a blocking context, this function first checks if there are unconsumed | ||
| 333 | * replies to return and returns one if so. Otherwise, it flushes the output | ||
| 334 | * buffer to the socket and reads until it has a reply. In a non-blocking | ||
| 335 | * context, it will return unconsumed replies until there are no more. */ | ||
| 336 | int redisGetReply(redisContext *c, void **reply); | ||
| 337 | int redisGetReplyFromReader(redisContext *c, void **reply); | ||
| 338 | |||
| 339 | /* Write a formatted command to the output buffer. Use these functions in blocking mode | ||
| 340 | * to get a pipeline of commands. */ | ||
| 341 | int redisAppendFormattedCommand(redisContext *c, const char *cmd, size_t len); | ||
| 342 | |||
| 343 | /* Write a command to the output buffer. Use these functions in blocking mode | ||
| 344 | * to get a pipeline of commands. */ | ||
| 345 | int redisvAppendCommand(redisContext *c, const char *format, va_list ap); | ||
| 346 | int redisAppendCommand(redisContext *c, const char *format, ...); | ||
| 347 | int redisAppendCommandArgv(redisContext *c, int argc, const char **argv, const size_t *argvlen); | ||
| 348 | |||
| 349 | /* Issue a command to Redis. In a blocking context, it is identical to calling | ||
| 350 | * redisAppendCommand, followed by redisGetReply. The function will return | ||
| 351 | * NULL if there was an error in performing the request, otherwise it will | ||
| 352 | * return the reply. In a non-blocking context, it is identical to calling | ||
| 353 | * only redisAppendCommand and will always return NULL. */ | ||
| 354 | void *redisvCommand(redisContext *c, const char *format, va_list ap); | ||
| 355 | void *redisCommand(redisContext *c, const char *format, ...); | ||
| 356 | void *redisCommandArgv(redisContext *c, int argc, const char **argv, const size_t *argvlen); | ||
| 357 | |||
| 358 | #ifdef __cplusplus | ||
| 359 | } | ||
| 360 | #endif | ||
| 361 | |||
| 362 | #endif | ||
