]> git.saurik.com Git - redis.git/blob - src/redis.h
8b262171c4e970df9b22292b4a85dee19b4fbd8e
[redis.git] / src / redis.h
1 #ifndef __REDIS_H
2 #define __REDIS_H
3
4 #include "fmacros.h"
5 #include "config.h"
6
7 #if defined(__sun)
8 #include "solarisfixes.h"
9 #endif
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <time.h>
15 #include <limits.h>
16 #include <unistd.h>
17 #include <errno.h>
18 #include <inttypes.h>
19 #include <pthread.h>
20 #include <syslog.h>
21 #include <netinet/in.h>
22 #include <lua.h>
23 #include <signal.h>
24
25 #include "ae.h" /* Event driven programming library */
26 #include "sds.h" /* Dynamic safe strings */
27 #include "dict.h" /* Hash tables */
28 #include "adlist.h" /* Linked lists */
29 #include "zmalloc.h" /* total memory usage aware version of malloc/free */
30 #include "anet.h" /* Networking the easy way */
31 #include "zipmap.h" /* Compact string -> string data structure */
32 #include "ziplist.h" /* Compact list data structure */
33 #include "intset.h" /* Compact integer set structure */
34 #include "version.h" /* Version macro */
35 #include "util.h" /* Misc functions useful in many places */
36
37 /* Error codes */
38 #define REDIS_OK 0
39 #define REDIS_ERR -1
40
41 /* Static server configuration */
42 #define REDIS_SERVERPORT 6379 /* TCP port */
43 #define REDIS_MAXIDLETIME 0 /* default client timeout: infinite */
44 #define REDIS_DEFAULT_DBNUM 16
45 #define REDIS_CONFIGLINE_MAX 1024
46 #define REDIS_EXPIRELOOKUPS_PER_CRON 10 /* lookup 10 expires per loop */
47 #define REDIS_MAX_WRITE_PER_EVENT (1024*64)
48 #define REDIS_SHARED_INTEGERS 10000
49 #define REDIS_MAX_LOGMSG_LEN 1024 /* Default maximum length of syslog messages */
50 #define REDIS_AOF_REWRITE_PERC 100
51 #define REDIS_AOF_REWRITE_MIN_SIZE (1024*1024)
52 #define REDIS_AOF_REWRITE_ITEMS_PER_CMD 64
53 #define REDIS_SLOWLOG_LOG_SLOWER_THAN 10000
54 #define REDIS_SLOWLOG_MAX_LEN 64
55 #define REDIS_MAX_CLIENTS 10000
56
57 #define REDIS_REPL_TIMEOUT 60
58 #define REDIS_REPL_PING_SLAVE_PERIOD 10
59
60 /* Protocol and I/O related defines */
61 #define REDIS_MAX_QUERYBUF_LEN (1024*1024*1024) /* 1GB max query buffer. */
62 #define REDIS_IOBUF_LEN (1024*16) /* Generic I/O buffer size */
63 #define REDIS_REPLY_CHUNK_BYTES (16*1024) /* 16k output buffer */
64 #define REDIS_INLINE_MAX_SIZE (1024*64) /* Max size of inline reads */
65 #define REDIS_MBULK_BIG_ARG (1024*32)
66
67 /* Hash table parameters */
68 #define REDIS_HT_MINFILL 10 /* Minimal hash table fill 10% */
69
70 /* Command flags. Please check the command table defined in the redis.c file
71 * for more information about the meaning of every flag. */
72 #define REDIS_CMD_WRITE 1 /* "w" flag */
73 #define REDIS_CMD_READONLY 2 /* "r" flag */
74 #define REDIS_CMD_DENYOOM 4 /* "m" flag */
75 #define REDIS_CMD_FORCE_REPLICATION 8 /* "f" flag */
76 #define REDIS_CMD_ADMIN 16 /* "a" flag */
77 #define REDIS_CMD_PUBSUB 32 /* "p" flag */
78 #define REDIS_CMD_NOSCRIPT 64 /* "s" flag */
79 #define REDIS_CMD_RANDOM 128 /* "R" flag */
80
81 /* Object types */
82 #define REDIS_STRING 0
83 #define REDIS_LIST 1
84 #define REDIS_SET 2
85 #define REDIS_ZSET 3
86 #define REDIS_HASH 4
87 #define REDIS_VMPOINTER 8
88
89 /* Objects encoding. Some kind of objects like Strings and Hashes can be
90 * internally represented in multiple ways. The 'encoding' field of the object
91 * is set to one of this fields for this object. */
92 #define REDIS_ENCODING_RAW 0 /* Raw representation */
93 #define REDIS_ENCODING_INT 1 /* Encoded as integer */
94 #define REDIS_ENCODING_HT 2 /* Encoded as hash table */
95 #define REDIS_ENCODING_ZIPMAP 3 /* Encoded as zipmap */
96 #define REDIS_ENCODING_LINKEDLIST 4 /* Encoded as regular linked list */
97 #define REDIS_ENCODING_ZIPLIST 5 /* Encoded as ziplist */
98 #define REDIS_ENCODING_INTSET 6 /* Encoded as intset */
99 #define REDIS_ENCODING_SKIPLIST 7 /* Encoded as skiplist */
100
101 /* Defines related to the dump file format. To store 32 bits lengths for short
102 * keys requires a lot of space, so we check the most significant 2 bits of
103 * the first byte to interpreter the length:
104 *
105 * 00|000000 => if the two MSB are 00 the len is the 6 bits of this byte
106 * 01|000000 00000000 => 01, the len is 14 byes, 6 bits + 8 bits of next byte
107 * 10|000000 [32 bit integer] => if it's 01, a full 32 bit len will follow
108 * 11|000000 this means: specially encoded object will follow. The six bits
109 * number specify the kind of object that follows.
110 * See the REDIS_RDB_ENC_* defines.
111 *
112 * Lenghts up to 63 are stored using a single byte, most DB keys, and may
113 * values, will fit inside. */
114 #define REDIS_RDB_6BITLEN 0
115 #define REDIS_RDB_14BITLEN 1
116 #define REDIS_RDB_32BITLEN 2
117 #define REDIS_RDB_ENCVAL 3
118 #define REDIS_RDB_LENERR UINT_MAX
119
120 /* When a length of a string object stored on disk has the first two bits
121 * set, the remaining two bits specify a special encoding for the object
122 * accordingly to the following defines: */
123 #define REDIS_RDB_ENC_INT8 0 /* 8 bit signed integer */
124 #define REDIS_RDB_ENC_INT16 1 /* 16 bit signed integer */
125 #define REDIS_RDB_ENC_INT32 2 /* 32 bit signed integer */
126 #define REDIS_RDB_ENC_LZF 3 /* string compressed with FASTLZ */
127
128 /* AOF states */
129 #define REDIS_AOF_OFF 0 /* AOF is off */
130 #define REDIS_AOF_ON 1 /* AOF is on */
131 #define REDIS_AOF_WAIT_REWRITE 2 /* AOF waits rewrite to start appending */
132
133 /* Client flags */
134 #define REDIS_SLAVE 1 /* This client is a slave server */
135 #define REDIS_MASTER 2 /* This client is a master server */
136 #define REDIS_MONITOR 4 /* This client is a slave monitor, see MONITOR */
137 #define REDIS_MULTI 8 /* This client is in a MULTI context */
138 #define REDIS_BLOCKED 16 /* The client is waiting in a blocking operation */
139 #define REDIS_DIRTY_CAS 64 /* Watched keys modified. EXEC will fail. */
140 #define REDIS_CLOSE_AFTER_REPLY 128 /* Close after writing entire reply. */
141 #define REDIS_UNBLOCKED 256 /* This client was unblocked and is stored in
142 server.unblocked_clients */
143 #define REDIS_LUA_CLIENT 512 /* This is a non connected client used by Lua */
144 #define REDIS_ASKING 1024 /* Client issued the ASKING command */
145
146 /* Client request types */
147 #define REDIS_REQ_INLINE 1
148 #define REDIS_REQ_MULTIBULK 2
149
150 /* Client classes for client limits, currently used only for
151 * the max-client-output-buffer limit implementation. */
152 #define REDIS_CLIENT_LIMIT_CLASS_NORMAL 0
153 #define REDIS_CLIENT_LIMIT_CLASS_SLAVE 1
154 #define REDIS_CLIENT_LIMIT_CLASS_PUBSUB 2
155
156 /* Slave replication state - slave side */
157 #define REDIS_REPL_NONE 0 /* No active replication */
158 #define REDIS_REPL_CONNECT 1 /* Must connect to master */
159 #define REDIS_REPL_CONNECTING 2 /* Connecting to master */
160 #define REDIS_REPL_TRANSFER 3 /* Receiving .rdb from master */
161 #define REDIS_REPL_CONNECTED 4 /* Connected to master */
162
163 /* Synchronous read timeout - slave side */
164 #define REDIS_REPL_SYNCIO_TIMEOUT 5
165
166 /* Slave replication state - from the point of view of master
167 * Note that in SEND_BULK and ONLINE state the slave receives new updates
168 * in its output queue. In the WAIT_BGSAVE state instead the server is waiting
169 * to start the next background saving in order to send updates to it. */
170 #define REDIS_REPL_WAIT_BGSAVE_START 3 /* master waits bgsave to start feeding it */
171 #define REDIS_REPL_WAIT_BGSAVE_END 4 /* master waits bgsave to start bulk DB transmission */
172 #define REDIS_REPL_SEND_BULK 5 /* master is sending the bulk DB */
173 #define REDIS_REPL_ONLINE 6 /* bulk DB already transmitted, receive updates */
174
175 /* List related stuff */
176 #define REDIS_HEAD 0
177 #define REDIS_TAIL 1
178
179 /* Sort operations */
180 #define REDIS_SORT_GET 0
181 #define REDIS_SORT_ASC 1
182 #define REDIS_SORT_DESC 2
183 #define REDIS_SORTKEY_MAX 1024
184
185 /* Log levels */
186 #define REDIS_DEBUG 0
187 #define REDIS_VERBOSE 1
188 #define REDIS_NOTICE 2
189 #define REDIS_WARNING 3
190 #define REDIS_LOG_RAW (1<<10) /* Modifier to log without timestamp */
191
192 /* Anti-warning macro... */
193 #define REDIS_NOTUSED(V) ((void) V)
194
195 #define ZSKIPLIST_MAXLEVEL 32 /* Should be enough for 2^32 elements */
196 #define ZSKIPLIST_P 0.25 /* Skiplist P = 1/4 */
197
198 /* Append only defines */
199 #define AOF_FSYNC_NO 0
200 #define AOF_FSYNC_ALWAYS 1
201 #define AOF_FSYNC_EVERYSEC 2
202
203 /* Zip structure related defaults */
204 #define REDIS_HASH_MAX_ZIPMAP_ENTRIES 512
205 #define REDIS_HASH_MAX_ZIPMAP_VALUE 64
206 #define REDIS_LIST_MAX_ZIPLIST_ENTRIES 512
207 #define REDIS_LIST_MAX_ZIPLIST_VALUE 64
208 #define REDIS_SET_MAX_INTSET_ENTRIES 512
209 #define REDIS_ZSET_MAX_ZIPLIST_ENTRIES 128
210 #define REDIS_ZSET_MAX_ZIPLIST_VALUE 64
211
212 /* Sets operations codes */
213 #define REDIS_OP_UNION 0
214 #define REDIS_OP_DIFF 1
215 #define REDIS_OP_INTER 2
216
217 /* Redis maxmemory strategies */
218 #define REDIS_MAXMEMORY_VOLATILE_LRU 0
219 #define REDIS_MAXMEMORY_VOLATILE_TTL 1
220 #define REDIS_MAXMEMORY_VOLATILE_RANDOM 2
221 #define REDIS_MAXMEMORY_ALLKEYS_LRU 3
222 #define REDIS_MAXMEMORY_ALLKEYS_RANDOM 4
223 #define REDIS_MAXMEMORY_NO_EVICTION 5
224
225 /* Scripting */
226 #define REDIS_LUA_TIME_LIMIT 5000 /* milliseconds */
227
228 /* Units */
229 #define UNIT_SECONDS 0
230 #define UNIT_MILLISECONDS 1
231
232 /* SHUTDOWN flags */
233 #define REDIS_SHUTDOWN_SAVE 1 /* Force SAVE on SHUTDOWN even if no save
234 points are configured. */
235 #define REDIS_SHUTDOWN_NOSAVE 2 /* Don't SAVE on SHUTDOWN. */
236
237 /* We can print the stacktrace, so our assert is defined this way: */
238 #define redisAssertWithInfo(_c,_o,_e) ((_e)?(void)0 : (_redisAssertWithInfo(_c,_o,#_e,__FILE__,__LINE__),_exit(1)))
239 #define redisAssert(_e) ((_e)?(void)0 : (_redisAssert(#_e,__FILE__,__LINE__),_exit(1)))
240 #define redisPanic(_e) _redisPanic(#_e,__FILE__,__LINE__),_exit(1)
241
242 /*-----------------------------------------------------------------------------
243 * Data types
244 *----------------------------------------------------------------------------*/
245
246 /* A redis object, that is a type able to hold a string / list / set */
247
248 /* The actual Redis Object */
249 #define REDIS_LRU_CLOCK_MAX ((1<<21)-1) /* Max value of obj->lru */
250 #define REDIS_LRU_CLOCK_RESOLUTION 10 /* LRU clock resolution in seconds */
251 typedef struct redisObject {
252 unsigned type:4;
253 unsigned notused:2; /* Not used */
254 unsigned encoding:4;
255 unsigned lru:22; /* lru time (relative to server.lruclock) */
256 int refcount;
257 void *ptr;
258 } robj;
259
260 /* Macro used to initalize a Redis object allocated on the stack.
261 * Note that this macro is taken near the structure definition to make sure
262 * we'll update it when the structure is changed, to avoid bugs like
263 * bug #85 introduced exactly in this way. */
264 #define initStaticStringObject(_var,_ptr) do { \
265 _var.refcount = 1; \
266 _var.type = REDIS_STRING; \
267 _var.encoding = REDIS_ENCODING_RAW; \
268 _var.ptr = _ptr; \
269 } while(0);
270
271 typedef struct redisDb {
272 dict *dict; /* The keyspace for this DB */
273 dict *expires; /* Timeout of keys with a timeout set */
274 dict *blocking_keys; /* Keys with clients waiting for data (BLPOP) */
275 dict *watched_keys; /* WATCHED keys for MULTI/EXEC CAS */
276 int id;
277 } redisDb;
278
279 /* Client MULTI/EXEC state */
280 typedef struct multiCmd {
281 robj **argv;
282 int argc;
283 struct redisCommand *cmd;
284 } multiCmd;
285
286 typedef struct multiState {
287 multiCmd *commands; /* Array of MULTI commands */
288 int count; /* Total number of MULTI commands */
289 } multiState;
290
291 typedef struct blockingState {
292 robj **keys; /* The key we are waiting to terminate a blocking
293 * operation such as BLPOP. Otherwise NULL. */
294 int count; /* Number of blocking keys */
295 time_t timeout; /* Blocking operation timeout. If UNIX current time
296 * is >= timeout then the operation timed out. */
297 robj *target; /* The key that should receive the element,
298 * for BRPOPLPUSH. */
299 } blockingState;
300
301 /* With multiplexing we need to take per-clinet state.
302 * Clients are taken in a liked list. */
303 typedef struct redisClient {
304 int fd;
305 redisDb *db;
306 int dictid;
307 sds querybuf;
308 int argc;
309 robj **argv;
310 struct redisCommand *cmd, *lastcmd;
311 int reqtype;
312 int multibulklen; /* number of multi bulk arguments left to read */
313 long bulklen; /* length of bulk argument in multi bulk request */
314 list *reply;
315 unsigned long reply_bytes; /* Tot bytes of objects in reply list */
316 int sentlen;
317 time_t lastinteraction; /* time of the last interaction, used for timeout */
318 int flags; /* REDIS_SLAVE | REDIS_MONITOR | REDIS_MULTI ... */
319 int slaveseldb; /* slave selected db, if this client is a slave */
320 int authenticated; /* when requirepass is non-NULL */
321 int replstate; /* replication state if this is a slave */
322 int repldbfd; /* replication DB file descriptor */
323 long repldboff; /* replication DB file offset */
324 off_t repldbsize; /* replication DB file size */
325 multiState mstate; /* MULTI/EXEC state */
326 blockingState bpop; /* blocking state */
327 list *io_keys; /* Keys this client is waiting to be loaded from the
328 * swap file in order to continue. */
329 list *watched_keys; /* Keys WATCHED for MULTI/EXEC CAS */
330 dict *pubsub_channels; /* channels a client is interested in (SUBSCRIBE) */
331 list *pubsub_patterns; /* patterns a client is interested in (SUBSCRIBE) */
332
333 /* Response buffer */
334 int bufpos;
335 char buf[REDIS_REPLY_CHUNK_BYTES];
336 } redisClient;
337
338 struct saveparam {
339 time_t seconds;
340 int changes;
341 };
342
343 struct sharedObjectsStruct {
344 robj *crlf, *ok, *err, *emptybulk, *czero, *cone, *cnegone, *pong, *space,
345 *colon, *nullbulk, *nullmultibulk, *queued,
346 *emptymultibulk, *wrongtypeerr, *nokeyerr, *syntaxerr, *sameobjecterr,
347 *outofrangeerr, *noscripterr, *loadingerr, *slowscripterr, *plus,
348 *select0, *select1, *select2, *select3, *select4,
349 *select5, *select6, *select7, *select8, *select9,
350 *messagebulk, *pmessagebulk, *subscribebulk, *unsubscribebulk, *mbulk3,
351 *mbulk4, *psubscribebulk, *punsubscribebulk,
352 *integers[REDIS_SHARED_INTEGERS];
353 };
354
355 /* ZSETs use a specialized version of Skiplists */
356 typedef struct zskiplistNode {
357 robj *obj;
358 double score;
359 struct zskiplistNode *backward;
360 struct zskiplistLevel {
361 struct zskiplistNode *forward;
362 unsigned int span;
363 } level[];
364 } zskiplistNode;
365
366 typedef struct zskiplist {
367 struct zskiplistNode *header, *tail;
368 unsigned long length;
369 int level;
370 } zskiplist;
371
372 typedef struct zset {
373 dict *dict;
374 zskiplist *zsl;
375 } zset;
376
377 /*-----------------------------------------------------------------------------
378 * Redis cluster data structures
379 *----------------------------------------------------------------------------*/
380
381 #define REDIS_CLUSTER_SLOTS 4096
382 #define REDIS_CLUSTER_OK 0 /* Everything looks ok */
383 #define REDIS_CLUSTER_FAIL 1 /* The cluster can't work */
384 #define REDIS_CLUSTER_NEEDHELP 2 /* The cluster works, but needs some help */
385 #define REDIS_CLUSTER_NAMELEN 40 /* sha1 hex length */
386 #define REDIS_CLUSTER_PORT_INCR 10000 /* Cluster port = baseport + PORT_INCR */
387
388 struct clusterNode;
389
390 /* clusterLink encapsulates everything needed to talk with a remote node. */
391 typedef struct clusterLink {
392 int fd; /* TCP socket file descriptor */
393 sds sndbuf; /* Packet send buffer */
394 sds rcvbuf; /* Packet reception buffer */
395 struct clusterNode *node; /* Node related to this link if any, or NULL */
396 } clusterLink;
397
398 /* Node flags */
399 #define REDIS_NODE_MASTER 1 /* The node is a master */
400 #define REDIS_NODE_SLAVE 2 /* The node is a slave */
401 #define REDIS_NODE_PFAIL 4 /* Failure? Need acknowledge */
402 #define REDIS_NODE_FAIL 8 /* The node is believed to be malfunctioning */
403 #define REDIS_NODE_MYSELF 16 /* This node is myself */
404 #define REDIS_NODE_HANDSHAKE 32 /* We have still to exchange the first ping */
405 #define REDIS_NODE_NOADDR 64 /* We don't know the address of this node */
406 #define REDIS_NODE_MEET 128 /* Send a MEET message to this node */
407 #define REDIS_NODE_NULL_NAME "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
408
409 struct clusterNode {
410 char name[REDIS_CLUSTER_NAMELEN]; /* Node name, hex string, sha1-size */
411 int flags; /* REDIS_NODE_... */
412 unsigned char slots[REDIS_CLUSTER_SLOTS/8]; /* slots handled by this node */
413 int numslaves; /* Number of slave nodes, if this is a master */
414 struct clusterNode **slaves; /* pointers to slave nodes */
415 struct clusterNode *slaveof; /* pointer to the master node */
416 time_t ping_sent; /* Unix time we sent latest ping */
417 time_t pong_received; /* Unix time we received the pong */
418 char *configdigest; /* Configuration digest of this node */
419 time_t configdigest_ts; /* Configuration digest timestamp */
420 char ip[16]; /* Latest known IP address of this node */
421 int port; /* Latest known port of this node */
422 clusterLink *link; /* TCP/IP link with this node */
423 };
424 typedef struct clusterNode clusterNode;
425
426 typedef struct {
427 char *configfile;
428 clusterNode *myself; /* This node */
429 int state; /* REDIS_CLUSTER_OK, REDIS_CLUSTER_FAIL, ... */
430 int node_timeout;
431 dict *nodes; /* Hash table of name -> clusterNode structures */
432 clusterNode *migrating_slots_to[REDIS_CLUSTER_SLOTS];
433 clusterNode *importing_slots_from[REDIS_CLUSTER_SLOTS];
434 clusterNode *slots[REDIS_CLUSTER_SLOTS];
435 zskiplist *slots_to_keys;
436 } clusterState;
437
438 /* Redis cluster messages header */
439
440 /* Note that the PING, PONG and MEET messages are actually the same exact
441 * kind of packet. PONG is the reply to ping, in the extact format as a PING,
442 * while MEET is a special PING that forces the receiver to add the sender
443 * as a node (if it is not already in the list). */
444 #define CLUSTERMSG_TYPE_PING 0 /* Ping */
445 #define CLUSTERMSG_TYPE_PONG 1 /* Pong (reply to Ping) */
446 #define CLUSTERMSG_TYPE_MEET 2 /* Meet "let's join" message */
447 #define CLUSTERMSG_TYPE_FAIL 3 /* Mark node xxx as failing */
448 #define CLUSTERMSG_TYPE_PUBLISH 4 /* Pub/Sub Publish propatagion */
449
450 /* Initially we don't know our "name", but we'll find it once we connect
451 * to the first node, using the getsockname() function. Then we'll use this
452 * address for all the next messages. */
453 typedef struct {
454 char nodename[REDIS_CLUSTER_NAMELEN];
455 uint32_t ping_sent;
456 uint32_t pong_received;
457 char ip[16]; /* IP address last time it was seen */
458 uint16_t port; /* port last time it was seen */
459 uint16_t flags;
460 uint32_t notused; /* for 64 bit alignment */
461 } clusterMsgDataGossip;
462
463 typedef struct {
464 char nodename[REDIS_CLUSTER_NAMELEN];
465 } clusterMsgDataFail;
466
467 typedef struct {
468 uint32_t channel_len;
469 uint32_t message_len;
470 unsigned char bulk_data[8]; /* defined as 8 just for alignment concerns. */
471 } clusterMsgDataPublish;
472
473 union clusterMsgData {
474 /* PING, MEET and PONG */
475 struct {
476 /* Array of N clusterMsgDataGossip structures */
477 clusterMsgDataGossip gossip[1];
478 } ping;
479
480 /* FAIL */
481 struct {
482 clusterMsgDataFail about;
483 } fail;
484
485 /* PUBLISH */
486 struct {
487 clusterMsgDataPublish msg;
488 } publish;
489 };
490
491 typedef struct {
492 uint32_t totlen; /* Total length of this message */
493 uint16_t type; /* Message type */
494 uint16_t count; /* Only used for some kind of messages. */
495 char sender[REDIS_CLUSTER_NAMELEN]; /* Name of the sender node */
496 unsigned char myslots[REDIS_CLUSTER_SLOTS/8];
497 char slaveof[REDIS_CLUSTER_NAMELEN];
498 char configdigest[32];
499 uint16_t port; /* Sender TCP base port */
500 unsigned char state; /* Cluster state from the POV of the sender */
501 unsigned char notused[5]; /* Reserved for future use. For alignment. */
502 union clusterMsgData data;
503 } clusterMsg;
504
505 /*-----------------------------------------------------------------------------
506 * Global server state
507 *----------------------------------------------------------------------------*/
508
509 struct redisServer {
510 /* General */
511 redisDb *db;
512 dict *commands; /* Command table hahs table */
513 aeEventLoop *el;
514 unsigned lruclock:22; /* Clock incrementing every minute, for LRU */
515 unsigned lruclock_padding:10;
516 int shutdown_asap; /* SHUTDOWN needed ASAP */
517 int activerehashing; /* Incremental rehash in serverCron() */
518 char *requirepass; /* Pass for AUTH command, or NULL */
519 char *pidfile; /* PID file path */
520 /* Networking */
521 int port; /* TCP listening port */
522 char *bindaddr; /* Bind address or NULL */
523 char *unixsocket; /* UNIX socket path */
524 mode_t unixsocketperm; /* UNIX socket permission */
525 int ipfd; /* TCP socket file descriptor */
526 int sofd; /* Unix socket file descriptor */
527 int cfd; /* Cluster bus lisetning socket */
528 list *clients; /* List of active clients */
529 list *slaves, *monitors; /* List of slaves and MONITORs */
530 redisClient *current_client; /* Current client, only used on crash report */
531 char neterr[ANET_ERR_LEN]; /* Error buffer for anet.c */
532 /* RDB / AOF loading information */
533 int loading; /* We are loading data from disk if true */
534 off_t loading_total_bytes;
535 off_t loading_loaded_bytes;
536 time_t loading_start_time;
537 /* Fast pointers to often looked up command */
538 struct redisCommand *delCommand, *multiCommand;
539 int cronloops; /* Number of times the cron function run */
540 time_t lastsave; /* Unix time of last save succeeede */
541 /* Fields used only for stats */
542 time_t stat_starttime; /* Server start time */
543 long long stat_numcommands; /* Number of processed commands */
544 long long stat_numconnections; /* Number of connections received */
545 long long stat_expiredkeys; /* Number of expired keys */
546 long long stat_evictedkeys; /* Number of evicted keys (maxmemory) */
547 long long stat_keyspace_hits; /* Number of successful lookups of keys */
548 long long stat_keyspace_misses; /* Number of failed lookups of keys */
549 size_t stat_peak_memory; /* Max used memory record */
550 long long stat_fork_time; /* Time needed to perform latets fork() */
551 long long stat_rejected_conn; /* Clients rejected because of maxclients */
552 list *slowlog; /* SLOWLOG list of commands */
553 long long slowlog_entry_id; /* SLOWLOG current entry ID */
554 long long slowlog_log_slower_than; /* SLOWLOG time limit (to get logged) */
555 unsigned long slowlog_max_len; /* SLOWLOG max number of items logged */
556 /* Configuration */
557 int verbosity; /* Loglevel in redis.conf */
558 int maxidletime; /* Client timeout in seconds */
559 size_t client_max_querybuf_len; /* Limit for client query buffer length */
560 int dbnum; /* Total number of configured DBs */
561 int daemonize; /* True if running as a daemon */
562 /* AOF persistence */
563 int aof_state; /* REDIS_AOF_(ON|OFF|WAIT_REWRITE) */
564 int aof_fsync; /* Kind of fsync() policy */
565 char *aof_filename; /* Name of the AOF file */
566 int aof_no_fsync_on_rewrite; /* Don't fsync if a rewrite is in prog. */
567 int aof_rewrite_perc; /* Rewrite AOF if % growth is > M and... */
568 off_t aof_rewrite_min_size; /* the AOF file is at least N bytes. */
569 off_t aof_rewrite_base_size; /* AOF size on latest startup or rewrite. */
570 off_t aof_current_size; /* AOF current size. */
571 int aof_rewrite_scheduled; /* Rewrite once BGSAVE terminates. */
572 pid_t aof_child_pid; /* PID if rewriting process */
573 sds aof_rewrite_buf; /* buffer taken by parent during oppend only rewrite */
574 sds aof_buf; /* AOF buffer, written before entering the event loop */
575 int aof_fd; /* File descriptor of currently selected AOF file */
576 int aof_selected_db; /* Currently selected DB in AOF */
577 time_t aof_flush_postponed_start; /* UNIX time of postponed AOF flush */
578 time_t aof_last_fsync; /* UNIX time of last fsync() */
579 /* RDB persistence */
580 long long dirty; /* Changes to DB from the last save */
581 long long dirty_before_bgsave; /* Used to restore dirty on failed BGSAVE */
582 pid_t rdb_child_pid; /* PID of RDB saving child */
583 struct saveparam *saveparams; /* Save points array for RDB */
584 int saveparamslen; /* Number of saving points */
585 char *rdb_filename; /* Name of RDB file */
586 int rdb_compression; /* Use compression in RDB? */
587 /* Logging */
588 char *logfile; /* Path of log file */
589 int syslog_enabled; /* Is syslog enabled? */
590 char *syslog_ident; /* Syslog ident */
591 int syslog_facility; /* Syslog facility */
592 /* Slave specific fields */
593 char *masterauth; /* AUTH with this password with master */
594 char *masterhost; /* Hostname of master */
595 int masterport; /* Port of master */
596 int repl_ping_slave_period; /* Master pings the salve every N seconds */
597 int repl_timeout; /* Timeout after N seconds of master idle */
598 redisClient *master; /* Client that is master for this slave */
599 int repl_syncio_timeout; /* Timeout for synchronous I/O calls */
600 int repl_state; /* Replication status if the instance is a slave */
601 off_t repl_transfer_left; /* Bytes left reading .rdb */
602 int repl_transfer_s; /* Slave -> Master SYNC socket */
603 int repl_transfer_fd; /* Slave -> Master SYNC temp file descriptor */
604 char *repl_transfer_tmpfile; /* Slave-> master SYNC temp file name */
605 time_t repl_transfer_lastio; /* Unix time of the latest read, for timeout */
606 int repl_serve_stale_data; /* Serve stale data when link is down? */
607 time_t repl_down_since; /* Unix time at which link with master went down */
608 /* Limits */
609 unsigned int maxclients; /* Max number of simultaneous clients */
610 unsigned long long maxmemory; /* Max number of memory bytes to use */
611 int maxmemory_policy; /* Policy for key evition */
612 int maxmemory_samples; /* Pricision of random sampling */
613 /* Blocked clients */
614 unsigned int bpop_blocked_clients; /* Number of clients blocked by lists */
615 list *unblocked_clients; /* list of clients to unblock before next loop */
616 /* Sort parameters - qsort_r() is only available under BSD so we
617 * have to take this state global, in order to pass it to sortCompare() */
618 int sort_desc;
619 int sort_alpha;
620 int sort_bypattern;
621 /* Zip structure config, see redis.conf for more information */
622 size_t hash_max_zipmap_entries;
623 size_t hash_max_zipmap_value;
624 size_t list_max_ziplist_entries;
625 size_t list_max_ziplist_value;
626 size_t set_max_intset_entries;
627 size_t zset_max_ziplist_entries;
628 size_t zset_max_ziplist_value;
629 time_t unixtime; /* Unix time sampled every second. */
630 /* Pubsub */
631 dict *pubsub_channels; /* Map channels to list of subscribed clients */
632 list *pubsub_patterns; /* A list of pubsub_patterns */
633 /* Cluster */
634 int cluster_enabled; /* Is cluster enabled? */
635 clusterState cluster; /* State of the cluster */
636 /* Scripting */
637 lua_State *lua; /* The Lua interpreter. We use just one for all clients */
638 redisClient *lua_client; /* The "fake client" to query Redis from Lua */
639 redisClient *lua_caller; /* The client running EVAL right now, or NULL */
640 dict *lua_scripts; /* A dictionary of SHA1 -> Lua scripts */
641 long long lua_time_limit; /* Script timeout in seconds */
642 long long lua_time_start; /* Start time of script */
643 int lua_write_dirty; /* True if a write command was called during the
644 execution of the current script. */
645 int lua_random_dirty; /* True if a random command was called during the
646 execution of the current script. */
647 int lua_timedout; /* True if we reached the time limit for script
648 execution. */
649 int lua_kill; /* Kill the script if true. */
650 /* Assert & bug reportign */
651 char *assert_failed;
652 char *assert_file;
653 int assert_line;
654 int bug_report_start; /* True if bug report header was already logged. */
655 };
656
657 typedef struct pubsubPattern {
658 redisClient *client;
659 robj *pattern;
660 } pubsubPattern;
661
662 typedef void redisCommandProc(redisClient *c);
663 typedef int *redisGetKeysProc(struct redisCommand *cmd, robj **argv, int argc, int *numkeys, int flags);
664 struct redisCommand {
665 char *name;
666 redisCommandProc *proc;
667 int arity;
668 char *sflags; /* Flags as string represenation, one char per flag. */
669 int flags; /* The actual flags, obtained from the 'sflags' field. */
670 /* Use a function to determine keys arguments in a command line.
671 * Used for Redis Cluster redirect. */
672 redisGetKeysProc *getkeys_proc;
673 /* What keys should be loaded in background when calling this command? */
674 int firstkey; /* The first argument that's a key (0 = no keys) */
675 int lastkey; /* THe last argument that's a key */
676 int keystep; /* The step between first and last key */
677 long long microseconds, calls;
678 };
679
680 struct redisFunctionSym {
681 char *name;
682 unsigned long pointer;
683 };
684
685 typedef struct _redisSortObject {
686 robj *obj;
687 union {
688 double score;
689 robj *cmpobj;
690 } u;
691 } redisSortObject;
692
693 typedef struct _redisSortOperation {
694 int type;
695 robj *pattern;
696 } redisSortOperation;
697
698 /* Structure to hold list iteration abstraction. */
699 typedef struct {
700 robj *subject;
701 unsigned char encoding;
702 unsigned char direction; /* Iteration direction */
703 unsigned char *zi;
704 listNode *ln;
705 } listTypeIterator;
706
707 /* Structure for an entry while iterating over a list. */
708 typedef struct {
709 listTypeIterator *li;
710 unsigned char *zi; /* Entry in ziplist */
711 listNode *ln; /* Entry in linked list */
712 } listTypeEntry;
713
714 /* Structure to hold set iteration abstraction. */
715 typedef struct {
716 robj *subject;
717 int encoding;
718 int ii; /* intset iterator */
719 dictIterator *di;
720 } setTypeIterator;
721
722 /* Structure to hold hash iteration abstration. Note that iteration over
723 * hashes involves both fields and values. Because it is possible that
724 * not both are required, store pointers in the iterator to avoid
725 * unnecessary memory allocation for fields/values. */
726 typedef struct {
727 int encoding;
728 unsigned char *zi;
729 unsigned char *zk, *zv;
730 unsigned int zklen, zvlen;
731
732 dictIterator *di;
733 dictEntry *de;
734 } hashTypeIterator;
735
736 #define REDIS_HASH_KEY 1
737 #define REDIS_HASH_VALUE 2
738
739 /*-----------------------------------------------------------------------------
740 * Extern declarations
741 *----------------------------------------------------------------------------*/
742
743 extern struct redisServer server;
744 extern struct sharedObjectsStruct shared;
745 extern dictType setDictType;
746 extern dictType zsetDictType;
747 extern dictType clusterNodesDictType;
748 extern dictType dbDictType;
749 extern double R_Zero, R_PosInf, R_NegInf, R_Nan;
750 dictType hashDictType;
751
752 /*-----------------------------------------------------------------------------
753 * Functions prototypes
754 *----------------------------------------------------------------------------*/
755
756 /* Utils */
757 long long ustime(void);
758 long long mstime(void);
759
760 /* networking.c -- Networking and Client related operations */
761 redisClient *createClient(int fd);
762 void closeTimedoutClients(void);
763 void freeClient(redisClient *c);
764 void resetClient(redisClient *c);
765 void sendReplyToClient(aeEventLoop *el, int fd, void *privdata, int mask);
766 void addReply(redisClient *c, robj *obj);
767 void *addDeferredMultiBulkLength(redisClient *c);
768 void setDeferredMultiBulkLength(redisClient *c, void *node, long length);
769 void addReplySds(redisClient *c, sds s);
770 void processInputBuffer(redisClient *c);
771 void acceptTcpHandler(aeEventLoop *el, int fd, void *privdata, int mask);
772 void acceptUnixHandler(aeEventLoop *el, int fd, void *privdata, int mask);
773 void readQueryFromClient(aeEventLoop *el, int fd, void *privdata, int mask);
774 void addReplyBulk(redisClient *c, robj *obj);
775 void addReplyBulkCString(redisClient *c, char *s);
776 void addReplyBulkCBuffer(redisClient *c, void *p, size_t len);
777 void addReplyBulkLongLong(redisClient *c, long long ll);
778 void acceptHandler(aeEventLoop *el, int fd, void *privdata, int mask);
779 void addReply(redisClient *c, robj *obj);
780 void addReplySds(redisClient *c, sds s);
781 void addReplyError(redisClient *c, char *err);
782 void addReplyStatus(redisClient *c, char *status);
783 void addReplyDouble(redisClient *c, double d);
784 void addReplyLongLong(redisClient *c, long long ll);
785 void addReplyMultiBulkLen(redisClient *c, long length);
786 void copyClientOutputBuffer(redisClient *dst, redisClient *src);
787 void *dupClientReplyValue(void *o);
788 void getClientsMaxBuffers(unsigned long *longest_output_list,
789 unsigned long *biggest_input_buffer);
790 sds getClientInfoString(redisClient *client);
791 sds getAllClientsInfoString(void);
792 void rewriteClientCommandVector(redisClient *c, int argc, ...);
793 void rewriteClientCommandArgument(redisClient *c, int i, robj *newval);
794 unsigned long getClientOutputBufferMemoryUsage(redisClient *c);
795
796 #ifdef __GNUC__
797 void addReplyErrorFormat(redisClient *c, const char *fmt, ...)
798 __attribute__((format(printf, 2, 3)));
799 void addReplyStatusFormat(redisClient *c, const char *fmt, ...)
800 __attribute__((format(printf, 2, 3)));
801 #else
802 void addReplyErrorFormat(redisClient *c, const char *fmt, ...);
803 void addReplyStatusFormat(redisClient *c, const char *fmt, ...);
804 #endif
805
806 /* List data type */
807 void listTypeTryConversion(robj *subject, robj *value);
808 void listTypePush(robj *subject, robj *value, int where);
809 robj *listTypePop(robj *subject, int where);
810 unsigned long listTypeLength(robj *subject);
811 listTypeIterator *listTypeInitIterator(robj *subject, int index, unsigned char direction);
812 void listTypeReleaseIterator(listTypeIterator *li);
813 int listTypeNext(listTypeIterator *li, listTypeEntry *entry);
814 robj *listTypeGet(listTypeEntry *entry);
815 void listTypeInsert(listTypeEntry *entry, robj *value, int where);
816 int listTypeEqual(listTypeEntry *entry, robj *o);
817 void listTypeDelete(listTypeEntry *entry);
818 void listTypeConvert(robj *subject, int enc);
819 void unblockClientWaitingData(redisClient *c);
820 int handleClientsWaitingListPush(redisClient *c, robj *key, robj *ele);
821 void popGenericCommand(redisClient *c, int where);
822
823 /* MULTI/EXEC/WATCH... */
824 void unwatchAllKeys(redisClient *c);
825 void initClientMultiState(redisClient *c);
826 void freeClientMultiState(redisClient *c);
827 void queueMultiCommand(redisClient *c);
828 void touchWatchedKey(redisDb *db, robj *key);
829 void touchWatchedKeysOnFlush(int dbid);
830
831 /* Redis object implementation */
832 void decrRefCount(void *o);
833 void incrRefCount(robj *o);
834 robj *resetRefCount(robj *obj);
835 void freeStringObject(robj *o);
836 void freeListObject(robj *o);
837 void freeSetObject(robj *o);
838 void freeZsetObject(robj *o);
839 void freeHashObject(robj *o);
840 robj *createObject(int type, void *ptr);
841 robj *createStringObject(char *ptr, size_t len);
842 robj *dupStringObject(robj *o);
843 int isObjectRepresentableAsLongLong(robj *o, long long *llongval);
844 robj *tryObjectEncoding(robj *o);
845 robj *getDecodedObject(robj *o);
846 size_t stringObjectLen(robj *o);
847 robj *createStringObjectFromLongLong(long long value);
848 robj *createStringObjectFromLongDouble(long double value);
849 robj *createListObject(void);
850 robj *createZiplistObject(void);
851 robj *createSetObject(void);
852 robj *createIntsetObject(void);
853 robj *createHashObject(void);
854 robj *createZsetObject(void);
855 robj *createZsetZiplistObject(void);
856 int getLongFromObjectOrReply(redisClient *c, robj *o, long *target, const char *msg);
857 int checkType(redisClient *c, robj *o, int type);
858 int getLongLongFromObjectOrReply(redisClient *c, robj *o, long long *target, const char *msg);
859 int getDoubleFromObjectOrReply(redisClient *c, robj *o, double *target, const char *msg);
860 int getLongLongFromObject(robj *o, long long *target);
861 int getLongDoubleFromObject(robj *o, long double *target);
862 int getLongDoubleFromObjectOrReply(redisClient *c, robj *o, long double *target, const char *msg);
863 char *strEncoding(int encoding);
864 int compareStringObjects(robj *a, robj *b);
865 int equalStringObjects(robj *a, robj *b);
866 unsigned long estimateObjectIdleTime(robj *o);
867
868 /* Synchronous I/O with timeout */
869 int syncWrite(int fd, char *ptr, ssize_t size, int timeout);
870 int syncRead(int fd, char *ptr, ssize_t size, int timeout);
871 int syncReadLine(int fd, char *ptr, ssize_t size, int timeout);
872
873 /* Replication */
874 void replicationFeedSlaves(list *slaves, int dictid, robj **argv, int argc);
875 void replicationFeedMonitors(list *monitors, int dictid, robj **argv, int argc);
876 void updateSlavesWaitingBgsave(int bgsaveerr);
877 void replicationCron(void);
878
879 /* Generic persistence functions */
880 void startLoading(FILE *fp);
881 void loadingProgress(off_t pos);
882 void stopLoading(void);
883
884 /* RDB persistence */
885 #include "rdb.h"
886
887 /* AOF persistence */
888 void flushAppendOnlyFile(int force);
889 void feedAppendOnlyFile(struct redisCommand *cmd, int dictid, robj **argv, int argc);
890 void aofRemoveTempFile(pid_t childpid);
891 int rewriteAppendOnlyFileBackground(void);
892 int loadAppendOnlyFile(char *filename);
893 void stopAppendOnly(void);
894 int startAppendOnly(void);
895 void backgroundRewriteDoneHandler(int exitcode, int bysignal);
896
897 /* Sorted sets data type */
898
899 /* Struct to hold a inclusive/exclusive range spec. */
900 typedef struct {
901 double min, max;
902 int minex, maxex; /* are min or max exclusive? */
903 } zrangespec;
904
905 zskiplist *zslCreate(void);
906 void zslFree(zskiplist *zsl);
907 zskiplistNode *zslInsert(zskiplist *zsl, double score, robj *obj);
908 unsigned char *zzlInsert(unsigned char *zl, robj *ele, double score);
909 int zslDelete(zskiplist *zsl, double score, robj *obj);
910 zskiplistNode *zslFirstInRange(zskiplist *zsl, zrangespec range);
911 double zzlGetScore(unsigned char *sptr);
912 void zzlNext(unsigned char *zl, unsigned char **eptr, unsigned char **sptr);
913 void zzlPrev(unsigned char *zl, unsigned char **eptr, unsigned char **sptr);
914 unsigned int zsetLength(robj *zobj);
915 void zsetConvert(robj *zobj, int encoding);
916
917 /* Core functions */
918 void freeMemoryIfNeeded(void);
919 int processCommand(redisClient *c);
920 void setupSignalHandlers(void);
921 struct redisCommand *lookupCommand(sds name);
922 struct redisCommand *lookupCommandByCString(char *s);
923 void call(redisClient *c);
924 int prepareForShutdown();
925 void redisLog(int level, const char *fmt, ...);
926 void redisLogRaw(int level, const char *msg);
927 void usage();
928 void updateDictResizePolicy(void);
929 int htNeedsResize(dict *dict);
930 void oom(const char *msg);
931 void populateCommandTable(void);
932 void resetCommandTableStats(void);
933
934 /* Set data type */
935 robj *setTypeCreate(robj *value);
936 int setTypeAdd(robj *subject, robj *value);
937 int setTypeRemove(robj *subject, robj *value);
938 int setTypeIsMember(robj *subject, robj *value);
939 setTypeIterator *setTypeInitIterator(robj *subject);
940 void setTypeReleaseIterator(setTypeIterator *si);
941 int setTypeNext(setTypeIterator *si, robj **objele, int64_t *llele);
942 robj *setTypeNextObject(setTypeIterator *si);
943 int setTypeRandomElement(robj *setobj, robj **objele, int64_t *llele);
944 unsigned long setTypeSize(robj *subject);
945 void setTypeConvert(robj *subject, int enc);
946
947 /* Hash data type */
948 void convertToRealHash(robj *o);
949 void hashTypeTryConversion(robj *subject, robj **argv, int start, int end);
950 void hashTypeTryObjectEncoding(robj *subject, robj **o1, robj **o2);
951 int hashTypeGet(robj *o, robj *key, robj **objval, unsigned char **v, unsigned int *vlen);
952 robj *hashTypeGetObject(robj *o, robj *key);
953 int hashTypeExists(robj *o, robj *key);
954 int hashTypeSet(robj *o, robj *key, robj *value);
955 int hashTypeDelete(robj *o, robj *key);
956 unsigned long hashTypeLength(robj *o);
957 hashTypeIterator *hashTypeInitIterator(robj *subject);
958 void hashTypeReleaseIterator(hashTypeIterator *hi);
959 int hashTypeNext(hashTypeIterator *hi);
960 int hashTypeCurrent(hashTypeIterator *hi, int what, robj **objval, unsigned char **v, unsigned int *vlen);
961 robj *hashTypeCurrentObject(hashTypeIterator *hi, int what);
962 robj *hashTypeLookupWriteOrCreate(redisClient *c, robj *key);
963
964 /* Pub / Sub */
965 int pubsubUnsubscribeAllChannels(redisClient *c, int notify);
966 int pubsubUnsubscribeAllPatterns(redisClient *c, int notify);
967 void freePubsubPattern(void *p);
968 int listMatchPubsubPattern(void *a, void *b);
969 int pubsubPublishMessage(robj *channel, robj *message);
970
971 /* Configuration */
972 void loadServerConfig(char *filename, char *options);
973 void appendServerSaveParams(time_t seconds, int changes);
974 void resetServerSaveParams();
975
976 /* db.c -- Keyspace access API */
977 int removeExpire(redisDb *db, robj *key);
978 void propagateExpire(redisDb *db, robj *key);
979 int expireIfNeeded(redisDb *db, robj *key);
980 long long getExpire(redisDb *db, robj *key);
981 void setExpire(redisDb *db, robj *key, long long when);
982 robj *lookupKey(redisDb *db, robj *key);
983 robj *lookupKeyRead(redisDb *db, robj *key);
984 robj *lookupKeyWrite(redisDb *db, robj *key);
985 robj *lookupKeyReadOrReply(redisClient *c, robj *key, robj *reply);
986 robj *lookupKeyWriteOrReply(redisClient *c, robj *key, robj *reply);
987 void dbAdd(redisDb *db, robj *key, robj *val);
988 void dbOverwrite(redisDb *db, robj *key, robj *val);
989 void setKey(redisDb *db, robj *key, robj *val);
990 int dbExists(redisDb *db, robj *key);
991 robj *dbRandomKey(redisDb *db);
992 int dbDelete(redisDb *db, robj *key);
993 long long emptyDb();
994 int selectDb(redisClient *c, int id);
995 void signalModifiedKey(redisDb *db, robj *key);
996 void signalFlushedDb(int dbid);
997 unsigned int GetKeysInSlot(unsigned int hashslot, robj **keys, unsigned int count);
998
999 /* API to get key arguments from commands */
1000 #define REDIS_GETKEYS_ALL 0
1001 #define REDIS_GETKEYS_PRELOAD 1
1002 int *getKeysFromCommand(struct redisCommand *cmd, robj **argv, int argc, int *numkeys, int flags);
1003 void getKeysFreeResult(int *result);
1004 int *noPreloadGetKeys(struct redisCommand *cmd,robj **argv, int argc, int *numkeys, int flags);
1005 int *renameGetKeys(struct redisCommand *cmd,robj **argv, int argc, int *numkeys, int flags);
1006 int *zunionInterGetKeys(struct redisCommand *cmd,robj **argv, int argc, int *numkeys, int flags);
1007
1008 /* Cluster */
1009 void clusterInit(void);
1010 unsigned short crc16(const char *buf, int len);
1011 unsigned int keyHashSlot(char *key, int keylen);
1012 clusterNode *createClusterNode(char *nodename, int flags);
1013 int clusterAddNode(clusterNode *node);
1014 void clusterCron(void);
1015 clusterNode *getNodeByQuery(redisClient *c, struct redisCommand *cmd, robj **argv, int argc, int *hashslot, int *ask);
1016 void clusterPropagatePublish(robj *channel, robj *message);
1017
1018 /* Scripting */
1019 void scriptingInit(void);
1020
1021 /* Git SHA1 */
1022 char *redisGitSHA1(void);
1023 char *redisGitDirty(void);
1024
1025 /* Commands prototypes */
1026 void authCommand(redisClient *c);
1027 void pingCommand(redisClient *c);
1028 void echoCommand(redisClient *c);
1029 void setCommand(redisClient *c);
1030 void setnxCommand(redisClient *c);
1031 void setexCommand(redisClient *c);
1032 void psetexCommand(redisClient *c);
1033 void getCommand(redisClient *c);
1034 void delCommand(redisClient *c);
1035 void existsCommand(redisClient *c);
1036 void setbitCommand(redisClient *c);
1037 void getbitCommand(redisClient *c);
1038 void setrangeCommand(redisClient *c);
1039 void getrangeCommand(redisClient *c);
1040 void incrCommand(redisClient *c);
1041 void decrCommand(redisClient *c);
1042 void incrbyCommand(redisClient *c);
1043 void decrbyCommand(redisClient *c);
1044 void incrbyfloatCommand(redisClient *c);
1045 void selectCommand(redisClient *c);
1046 void randomkeyCommand(redisClient *c);
1047 void keysCommand(redisClient *c);
1048 void dbsizeCommand(redisClient *c);
1049 void lastsaveCommand(redisClient *c);
1050 void saveCommand(redisClient *c);
1051 void bgsaveCommand(redisClient *c);
1052 void bgrewriteaofCommand(redisClient *c);
1053 void shutdownCommand(redisClient *c);
1054 void moveCommand(redisClient *c);
1055 void renameCommand(redisClient *c);
1056 void renamenxCommand(redisClient *c);
1057 void lpushCommand(redisClient *c);
1058 void rpushCommand(redisClient *c);
1059 void lpushxCommand(redisClient *c);
1060 void rpushxCommand(redisClient *c);
1061 void linsertCommand(redisClient *c);
1062 void lpopCommand(redisClient *c);
1063 void rpopCommand(redisClient *c);
1064 void llenCommand(redisClient *c);
1065 void lindexCommand(redisClient *c);
1066 void lrangeCommand(redisClient *c);
1067 void ltrimCommand(redisClient *c);
1068 void typeCommand(redisClient *c);
1069 void lsetCommand(redisClient *c);
1070 void saddCommand(redisClient *c);
1071 void sremCommand(redisClient *c);
1072 void smoveCommand(redisClient *c);
1073 void sismemberCommand(redisClient *c);
1074 void scardCommand(redisClient *c);
1075 void spopCommand(redisClient *c);
1076 void srandmemberCommand(redisClient *c);
1077 void sinterCommand(redisClient *c);
1078 void sinterstoreCommand(redisClient *c);
1079 void sunionCommand(redisClient *c);
1080 void sunionstoreCommand(redisClient *c);
1081 void sdiffCommand(redisClient *c);
1082 void sdiffstoreCommand(redisClient *c);
1083 void syncCommand(redisClient *c);
1084 void flushdbCommand(redisClient *c);
1085 void flushallCommand(redisClient *c);
1086 void sortCommand(redisClient *c);
1087 void lremCommand(redisClient *c);
1088 void rpoplpushCommand(redisClient *c);
1089 void infoCommand(redisClient *c);
1090 void mgetCommand(redisClient *c);
1091 void monitorCommand(redisClient *c);
1092 void expireCommand(redisClient *c);
1093 void expireatCommand(redisClient *c);
1094 void pexpireCommand(redisClient *c);
1095 void pexpireatCommand(redisClient *c);
1096 void getsetCommand(redisClient *c);
1097 void ttlCommand(redisClient *c);
1098 void pttlCommand(redisClient *c);
1099 void persistCommand(redisClient *c);
1100 void slaveofCommand(redisClient *c);
1101 void debugCommand(redisClient *c);
1102 void msetCommand(redisClient *c);
1103 void msetnxCommand(redisClient *c);
1104 void zaddCommand(redisClient *c);
1105 void zincrbyCommand(redisClient *c);
1106 void zrangeCommand(redisClient *c);
1107 void zrangebyscoreCommand(redisClient *c);
1108 void zrevrangebyscoreCommand(redisClient *c);
1109 void zcountCommand(redisClient *c);
1110 void zrevrangeCommand(redisClient *c);
1111 void zcardCommand(redisClient *c);
1112 void zremCommand(redisClient *c);
1113 void zscoreCommand(redisClient *c);
1114 void zremrangebyscoreCommand(redisClient *c);
1115 void multiCommand(redisClient *c);
1116 void execCommand(redisClient *c);
1117 void discardCommand(redisClient *c);
1118 void blpopCommand(redisClient *c);
1119 void brpopCommand(redisClient *c);
1120 void brpoplpushCommand(redisClient *c);
1121 void appendCommand(redisClient *c);
1122 void strlenCommand(redisClient *c);
1123 void zrankCommand(redisClient *c);
1124 void zrevrankCommand(redisClient *c);
1125 void hsetCommand(redisClient *c);
1126 void hsetnxCommand(redisClient *c);
1127 void hgetCommand(redisClient *c);
1128 void hmsetCommand(redisClient *c);
1129 void hmgetCommand(redisClient *c);
1130 void hdelCommand(redisClient *c);
1131 void hlenCommand(redisClient *c);
1132 void zremrangebyrankCommand(redisClient *c);
1133 void zunionstoreCommand(redisClient *c);
1134 void zinterstoreCommand(redisClient *c);
1135 void hkeysCommand(redisClient *c);
1136 void hvalsCommand(redisClient *c);
1137 void hgetallCommand(redisClient *c);
1138 void hexistsCommand(redisClient *c);
1139 void configCommand(redisClient *c);
1140 void hincrbyCommand(redisClient *c);
1141 void hincrbyfloatCommand(redisClient *c);
1142 void subscribeCommand(redisClient *c);
1143 void unsubscribeCommand(redisClient *c);
1144 void psubscribeCommand(redisClient *c);
1145 void punsubscribeCommand(redisClient *c);
1146 void publishCommand(redisClient *c);
1147 void watchCommand(redisClient *c);
1148 void unwatchCommand(redisClient *c);
1149 void clusterCommand(redisClient *c);
1150 void restoreCommand(redisClient *c);
1151 void migrateCommand(redisClient *c);
1152 void askingCommand(redisClient *c);
1153 void dumpCommand(redisClient *c);
1154 void objectCommand(redisClient *c);
1155 void clientCommand(redisClient *c);
1156 void evalCommand(redisClient *c);
1157 void evalShaCommand(redisClient *c);
1158 void scriptCommand(redisClient *c);
1159
1160 #if defined(__GNUC__)
1161 void *calloc(size_t count, size_t size) __attribute__ ((deprecated));
1162 void free(void *ptr) __attribute__ ((deprecated));
1163 void *malloc(size_t size) __attribute__ ((deprecated));
1164 void *realloc(void *ptr, size_t size) __attribute__ ((deprecated));
1165 #endif
1166
1167 /* Debugging stuff */
1168 void _redisAssertWithInfo(redisClient *c, robj *o, char *estr, char *file, int line);
1169 void _redisAssert(char *estr, char *file, int line);
1170 void _redisPanic(char *msg, char *file, int line);
1171 void bugReportStart(void);
1172 void redisLogObjectDebugInfo(robj *o);
1173 void sigsegvHandler(int sig, siginfo_t *info, void *secret);
1174 sds genRedisInfoString(char *section);
1175 #endif