forked from pikiwidb/rediscache
-
Notifications
You must be signed in to change notification settings - Fork 1
/
db.h
73 lines (61 loc) · 2.35 KB
/
db.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef __DB_H__
#define __DB_H__
#include "object.h"
#include "dict.h"
#include "evict.h"
#ifdef _cplusplus
extern "C" {
#endif
#define LOOKUP_NONE 0
#define LOOKUP_NOTOUCH (1<<0) /* Don't update LRU. */
#define LOOKUP_NONOTIFY (1<<1) /* Don't trigger keyspace event on key misses. */
#define LOOKUP_NOSTATS (1<<2) /* Don't update keyspace hits/misses counters. */
#define LOOKUP_WRITE (1<<3) /* Delete expired keys even in replicas. */
#define LOOKUP_NOEXPIRE (1<<4) /* Avoid deleting lazy expired keys. */
#define LOOKUP_NOEFFECTS (LOOKUP_NONOTIFY | LOOKUP_NOSTATS | LOOKUP_NOTOUCH | LOOKUP_NOEXPIRE) /* Avoid any effects from fetching the key */
// RedisDb
typedef struct redisDb {
dict *dict; /* The keyspace for this DB */
dict *expires; /* Timeout of keys with a timeout set */
struct evictionPoolEntry *eviction_pool; /* Eviction pool of keys */
} redisDb;
typedef enum {
LIST_CONV_AUTO,
LIST_CONV_GROWING,
LIST_CONV_SHRINKING,
} list_conv_type;
#define SETKEY_KEEPTTL 1
#define SETKEY_NO_SIGNAL 2
#define SETKEY_ALREADY_EXIST 4
#define SETKEY_DOESNT_EXIST 8
#define SETKEY_ADD_OR_UPDATE 16 /* Key most likely doesn't exists */
/* Key flags for how key is removed */
#define DB_FLAG_KEY_NONE 0
#define DB_FLAG_KEY_DELETED (1ULL<<0)
#define DB_FLAG_KEY_EXPIRED (1ULL<<1)
#define DB_FLAG_KEY_EVICTED (1ULL<<2)
#define DB_FLAG_KEY_OVERWRITE (1ULL<<3)
redisDb* createRedisDb(void);
void closeRedisDb(redisDb *db);
robj *lookupKey(redisDb *db, robj *key, int flags);
robj *lookupKeyRead(redisDb *db, robj *key);
robj *lookupKeyWrite(redisDb *db, robj *key);
void dbAdd(redisDb *db, robj *key, robj *val);
void dbReplaceValue(redisDb *db, robj *key, robj *val);
void setKey(redisDb *db, robj *key, robj *val, int flags);
int dbExists(redisDb *db, robj *key);
robj *dbRandomKey(redisDb *db);
int dbDelete(redisDb *db, robj *key);
long long emptyDb(redisDb *db, void(callback)(dict*));
int removeExpire(redisDb *db, robj *key);
void setExpire(redisDb *db, robj *key, long long when);
long long getExpire(redisDb *db, robj *key);
int expireIfNeeded(redisDb *db, robj *key, int flags);
int freeMemoryIfNeeded(redisDb *db);
int activeExpireCycle(redisDb *db);
robj *dbUnshareStringValue(redisDb *db, robj *key, robj *o);
typedef void (*beforeConvertCB)(void *data);
#ifdef _cplusplus
}
#endif
#endif