-
Notifications
You must be signed in to change notification settings - Fork 136
/
shmcache.h
186 lines (164 loc) · 4.23 KB
/
shmcache.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
//shmcache.h
#ifndef _SHMCACHE_H
#define _SHMCACHE_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <pthread.h>
#include <sys/shm.h>
#include "common_define.h"
#include "shmcache_types.h"
#include "shm_hashtable.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
context init
parameters:
context: the context pointer
config: the config parameters
create_segment: if create segment when segment not exist
check_segment: if check segment
return error no, 0 for success, != 0 for fail
*/
int shmcache_init(struct shmcache_context *context,
struct shmcache_config *config, const bool create_segment,
const bool check_segment);
/**
context init from config file
parameters:
context: the context pointer
config_filename: the config filename
create_segment: if create segment when segment not exist
check_segment: if check segment
return error no, 0 for success, != 0 for fail
*/
int shmcache_init_from_file_ex(struct shmcache_context *context,
const char *config_filename, const bool create_segment,
const bool check_segment);
/**
context init from config file
parameters:
context: the context pointer
config_filename: the config filename
return error no, 0 for success, != 0 for fail
*/
static inline int shmcache_init_from_file(struct shmcache_context *context,
const char *config_filename)
{
return shmcache_init_from_file_ex(context, config_filename, true, true);
}
/**
load config from file
parameters:
config: the config pointer
config_filename: the config filename
return error no, 0 for success, != 0 for fail
*/
int shmcache_load_config(struct shmcache_config *config,
const char *config_filename);
/**
context destroy
parameters:
context: the context pointer
*/
void shmcache_destroy(struct shmcache_context *context);
/**
set value
parameters:
context: the context pointer
key: the key
value: the value, include expire filed
return error no, 0 for success, != 0 for fail
*/
int shmcache_set_ex(struct shmcache_context *context,
const struct shmcache_key_info *key,
const struct shmcache_value_info *value);
/**
set value
parameters:
context: the context pointer
key: the key
data: the value string ptr
data_len: the value length
ttl: the time to live in seconds
return error no, 0 for success, != 0 for fail
*/
int shmcache_set(struct shmcache_context *context,
const struct shmcache_key_info *key,
const char *data, const int data_len, const int ttl);
/**
increase integer value
parameters:
context: the context pointer
key: the key
incr: the incremental number
ttl: the time to live in seconds
value: return the new value
return error no, 0 for success, != 0 for fail
*/
int shmcache_incr(struct shmcache_context *context,
const struct shmcache_key_info *key,
const int64_t increment,
const int ttl, int64_t *new_value);
/**
get value
parameters:
context: the context pointer
key: the key
value: store the returned value
return error no, 0 for success, != 0 for fail
*/
int shmcache_get(struct shmcache_context *context,
const struct shmcache_key_info *key,
struct shmcache_value_info *value);
/**
delte the key
parameters:
context: the context pointer
key: the key
return error no, 0 for success, != 0 for fail
*/
int shmcache_delete(struct shmcache_context *context,
const struct shmcache_key_info *key);
/**
remove all share memory
parameters:
context: the context pointer
return error no, 0 for success, != 0 for fail
*/
int shmcache_remove_all(struct shmcache_context *context);
/**
get stats
parameters:
context: the context pointer
stats: return the stats
return none
*/
void shmcache_stats(struct shmcache_context *context, struct shmcache_stats *stats);
/**
clear stats
parameters:
context: the context pointer
return none
*/
void shmcache_clear_stats(struct shmcache_context *context);
/**
get serializer label
parameters:
serializer: the serializer
return serializer label
*/
const char *shmcache_get_serializer_label(const int serializer);
/**
clear hashtable
parameters:
context: the context pointer
return error no, 0 for success, != 0 for fail
*/
int shmcache_clear(struct shmcache_context *context);
#ifdef __cplusplus
}
#endif
#endif