-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy pathlib_mysqludf_redis.h
231 lines (175 loc) · 3.79 KB
/
lib_mysqludf_redis.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#include <pthread.h>
#if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(WIN32)
#define DLLEXP __declspec(dllexport)
#else
#define DLLEXP
#endif
#ifdef STANDARD
#include <string.h>
#include <stdlib.h>
#include <time.h>
#ifdef __WIN__
typedef unsigned __int64 ulonglong;
typedef __int64 longlong;
#else
typedef unsigned long long ulonglong;
typedef long long longlong;
#endif /*__WIN__*/
#else
#include <my_global.h>
#include <my_sys.h>
#endif
#include <mysql.h>
#include <m_ctype.h>
#include <m_string.h>
#include <stdlib.h>
#include <ctype.h>
#include <stdarg.h>
#include <unistd.h>
/**
* hiredis head file
*/
#include <hiredis/hiredis.h>
/**
* mysql head file
*/
#include <mysql/plugin.h>
//apache portable runtime
#include <apr-1/apu.h>
#include <apr-1/apr.h>
#include <apr-1/apr_queue.h>
#include <apr-1/apr_thread_pool.h>
#include <apr-1/apr_time.h>
#include <apr-1/apr_general.h>
//fix me!
#ifdef __cplusplus
extern "C" {
#endif
#define LIBVERSION "lib_mysqludf_redis version 0.2.0"
#define MAX_LEN 8192 // max allowed length of input string, including 0 terminator
#define MAX_STR 16 // max allowed number of substrings in input string
#ifdef __WIN__
#define SETENV(name,value) SetEnvironmentVariable(name,value);
#else
#define SETENV(name,value) setenv(name,value,1);
#endif
struct redis_command{
size_t arg_count; /* Number of arguments */
char **argv; /* Pointer to argument */
size_t *argvlen; /* lengths of arguments */
};
enum conn_type {
CONN_TCP,
CONN_UNIX_SOCK
};
struct config {
enum conn_type type;
struct {
char host[256];
int port;
} tcp;
struct {
const char *path;
} unix_sock;
char password[256];
int auth;
char log_file[256];
int debug;
};
/* Redis connection mutex */
static pthread_mutex_t sredisContext_mutex = PTHREAD_MUTEX_INITIALIZER;
/* Redis Connection context */
static redisContext *sredisContext = NULL;
static FILE * pFile = NULL;
#define QUEUE_SIZE 100000
static apr_queue_t *queue = NULL;
static apr_pool_t *mem_pool = NULL;
static apr_thread_pool_t *thrp = NULL;
/**
set server info command.
*/
DLLEXP
my_bool redis_servers_set_v2_init(
UDF_INIT *initid
, UDF_ARGS *args
, char *message
);
DLLEXP
void redis_servers_set_v2_deinit(
UDF_INIT *initid
);
DLLEXP
my_ulonglong redis_servers_set_v2(
UDF_INIT *initid
, UDF_ARGS *args
, char *is_null
, char *error
);
/**
* redis_command
*
* execute multiple redis command (ex: select 1\n set x 1\n)
*/
DLLEXP
my_bool redis_command_v2_init(
UDF_INIT *initid
, UDF_ARGS *args
, char *message
);
DLLEXP
void redis_command_v2_deinit(
UDF_INIT *initid
);
DLLEXP
my_ulonglong redis_command_v2(
UDF_INIT *initid
, UDF_ARGS *args
, char *is_null
, char *error
);
/**
free resources.
*/
DLLEXP
my_bool free_resources_init(
UDF_INIT *initid
, UDF_ARGS *args
, char *message
);
DLLEXP
void free_resources_deinit(
UDF_INIT *initid
);
DLLEXP
my_ulonglong free_resources(
UDF_INIT *initid
, UDF_ARGS *args
, char *is_null
, char *error
);
/* Helpers */
redisContext *_myredisConnect(struct config config);
void _myredisDconnect(redisContext *c);
redisContext *_redis_context_init();
redisContext *_redis_context_reinit();
void _redis_context_deinit();
long long _do_redis_command(const char** args, const size_t * argvlen, size_t arg_count);
void check_error(apr_status_t rv);
void deinitialize_apr(void);
void initialize_apr(void);
void free_command(struct redis_command *cmd);
void * APR_THREAD_FUNC consumer(apr_thread_t *thd, void *data);
int start_consumer_worker(void);
#define debug_print(...) \
do { \
if (cfg.debug && pFile) \
fprintf(pFile, __VA_ARGS__); \
} while (0)
#define info_print(...) \
do { \
if (pFile) \
fprintf(pFile, __VA_ARGS__); \
} while (0)
#ifdef __cplusplus
}
#endif