-
Notifications
You must be signed in to change notification settings - Fork 15
/
hiredispool.h
73 lines (59 loc) · 1.66 KB
/
hiredispool.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
/* Author: Huanghao
* Date: 2017-2
* Revision: 0.1
* Function: Simple lightweight connection pool for hiredis
* + Connection pooling
* + Auto-reconnect and retry
* + Multiple server endpoints
* Usage:
*/
#ifndef HIREDISPOOL_H
#define HIREDISPOOL_H
#include <stdarg.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Constants */
#define HIREDISPOOL_MAJOR 0
#define HIREDISPOOL_MINOR 1
#define HIREDISPOOL_PATCH 1
#define HIREDISPOOL_SONAME 0.1
/* Types */
typedef struct redis_endpoint {
char host[256];
int port;
} REDIS_ENDPOINT;
typedef struct redis_config {
REDIS_ENDPOINT* endpoints;
int num_endpoints;
int connect_timeout;
int net_readwrite_timeout;
int num_redis_socks;
int connect_failure_retry_delay;
} REDIS_CONFIG;
typedef struct redis_socket {
int id;
int backup;
pthread_mutex_t mutex;
int inuse;
struct redis_socket* next;
enum { sockunconnected, sockconnected } state;
void* conn;
} REDIS_SOCKET;
typedef struct redis_instance {
time_t connect_after;
REDIS_SOCKET* redis_pool;
REDIS_SOCKET* last_used;
REDIS_CONFIG* config;
} REDIS_INSTANCE;
/* Functions */
int redis_pool_create(const REDIS_CONFIG* config, REDIS_INSTANCE** instance);
int redis_pool_destroy(REDIS_INSTANCE* instance);
REDIS_SOCKET* redis_get_socket(REDIS_INSTANCE* instance);
int redis_release_socket(REDIS_INSTANCE* instance, REDIS_SOCKET* redisocket);
void* redis_command(REDIS_SOCKET* redisocket, REDIS_INSTANCE* instance, const char* format, ...);
void* redis_vcommand(REDIS_SOCKET* redisocket, REDIS_INSTANCE* instance, const char* format, va_list ap);
#ifdef __cplusplus
}
#endif
#endif/*HIREDISPOOL_H*/