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