]>
git.saurik.com Git - redis.git/blob - src/rdb.h
7 /* TBD: include only necessary headers. */
10 /* The current RDB version. When the format changes in a way that is no longer
11 * backward compatible this number gets incremented. */
12 #define REDIS_RDB_VERSION 6
14 /* Defines related to the dump file format. To store 32 bits lengths for short
15 * keys requires a lot of space, so we check the most significant 2 bits of
16 * the first byte to interpreter the length:
18 * 00|000000 => if the two MSB are 00 the len is the 6 bits of this byte
19 * 01|000000 00000000 => 01, the len is 14 byes, 6 bits + 8 bits of next byte
20 * 10|000000 [32 bit integer] => if it's 01, a full 32 bit len will follow
21 * 11|000000 this means: specially encoded object will follow. The six bits
22 * number specify the kind of object that follows.
23 * See the REDIS_RDB_ENC_* defines.
25 * Lenghts up to 63 are stored using a single byte, most DB keys, and may
26 * values, will fit inside. */
27 #define REDIS_RDB_6BITLEN 0
28 #define REDIS_RDB_14BITLEN 1
29 #define REDIS_RDB_32BITLEN 2
30 #define REDIS_RDB_ENCVAL 3
31 #define REDIS_RDB_LENERR UINT_MAX
33 /* When a length of a string object stored on disk has the first two bits
34 * set, the remaining two bits specify a special encoding for the object
35 * accordingly to the following defines: */
36 #define REDIS_RDB_ENC_INT8 0 /* 8 bit signed integer */
37 #define REDIS_RDB_ENC_INT16 1 /* 16 bit signed integer */
38 #define REDIS_RDB_ENC_INT32 2 /* 32 bit signed integer */
39 #define REDIS_RDB_ENC_LZF 3 /* string compressed with FASTLZ */
41 /* Dup object types to RDB object types. Only reason is readability (are we
42 * dealing with RDB types or with in-memory object types?). */
43 #define REDIS_RDB_TYPE_STRING 0
44 #define REDIS_RDB_TYPE_LIST 1
45 #define REDIS_RDB_TYPE_SET 2
46 #define REDIS_RDB_TYPE_ZSET 3
47 #define REDIS_RDB_TYPE_HASH 4
49 /* Object types for encoded objects. */
50 #define REDIS_RDB_TYPE_HASH_ZIPMAP 9
51 #define REDIS_RDB_TYPE_LIST_ZIPLIST 10
52 #define REDIS_RDB_TYPE_SET_INTSET 11
53 #define REDIS_RDB_TYPE_ZSET_ZIPLIST 12
54 #define REDIS_RDB_TYPE_HASH_ZIPLIST 13
56 /* Test if a type is an object type. */
57 #define rdbIsObjectType(t) ((t >= 0 && t <= 4) || (t >= 9 && t <= 13))
59 /* Special RDB opcodes (saved/loaded with rdbSaveType/rdbLoadType). */
60 #define REDIS_RDB_OPCODE_EXPIRETIME_MS 252
61 #define REDIS_RDB_OPCODE_EXPIRETIME 253
62 #define REDIS_RDB_OPCODE_SELECTDB 254
63 #define REDIS_RDB_OPCODE_EOF 255
65 int rdbSaveType(rio
*rdb
, unsigned char type
);
66 int rdbLoadType(rio
*rdb
);
67 int rdbSaveTime(rio
*rdb
, time_t t
);
68 time_t rdbLoadTime(rio
*rdb
);
69 int rdbSaveLen(rio
*rdb
, uint32_t len
);
70 uint32_t rdbLoadLen(rio
*rdb
, int *isencoded
);
71 int rdbSaveObjectType(rio
*rdb
, robj
*o
);
72 int rdbLoadObjectType(rio
*rdb
);
73 int rdbLoad(char *filename
);
74 int rdbSaveBackground(char *filename
);
75 void rdbRemoveTempFile(pid_t childpid
);
76 int rdbSave(char *filename
);
77 int rdbSaveObject(rio
*rdb
, robj
*o
);
78 off_t
rdbSavedObjectLen(robj
*o
);
79 off_t
rdbSavedObjectPages(robj
*o
);
80 robj
*rdbLoadObject(int type
, rio
*rdb
);
81 void backgroundSaveDoneHandler(int exitcode
, int bysignal
);
82 int rdbSaveKeyValuePair(rio
*rdb
, robj
*key
, robj
*val
, long long expiretime
, long long now
);
83 robj
*rdbLoadStringObject(rio
*rdb
);