redis-client 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile +1 -2
- data/Gemfile.lock +1 -2
- data/README.md +5 -9
- data/Rakefile +41 -22
- data/lib/redis_client/version.rb +1 -1
- data/lib/redis_client.rb +1 -6
- data/redis-client.gemspec +2 -4
- metadata +6 -56
- data/.rubocop.yml +0 -191
- data/ext/redis_client/hiredis/export.clang +0 -2
- data/ext/redis_client/hiredis/export.gcc +0 -7
- data/ext/redis_client/hiredis/extconf.rb +0 -69
- data/ext/redis_client/hiredis/hiredis_connection.c +0 -708
- data/ext/redis_client/hiredis/vendor/.gitignore +0 -9
- data/ext/redis_client/hiredis/vendor/.travis.yml +0 -131
- data/ext/redis_client/hiredis/vendor/CHANGELOG.md +0 -364
- data/ext/redis_client/hiredis/vendor/CMakeLists.txt +0 -165
- data/ext/redis_client/hiredis/vendor/COPYING +0 -29
- data/ext/redis_client/hiredis/vendor/Makefile +0 -308
- data/ext/redis_client/hiredis/vendor/README.md +0 -664
- data/ext/redis_client/hiredis/vendor/adapters/ae.h +0 -130
- data/ext/redis_client/hiredis/vendor/adapters/glib.h +0 -156
- data/ext/redis_client/hiredis/vendor/adapters/ivykis.h +0 -84
- data/ext/redis_client/hiredis/vendor/adapters/libev.h +0 -179
- data/ext/redis_client/hiredis/vendor/adapters/libevent.h +0 -175
- data/ext/redis_client/hiredis/vendor/adapters/libuv.h +0 -117
- data/ext/redis_client/hiredis/vendor/adapters/macosx.h +0 -115
- data/ext/redis_client/hiredis/vendor/adapters/qt.h +0 -135
- data/ext/redis_client/hiredis/vendor/alloc.c +0 -86
- data/ext/redis_client/hiredis/vendor/alloc.h +0 -91
- data/ext/redis_client/hiredis/vendor/appveyor.yml +0 -24
- data/ext/redis_client/hiredis/vendor/async.c +0 -887
- data/ext/redis_client/hiredis/vendor/async.h +0 -147
- data/ext/redis_client/hiredis/vendor/async_private.h +0 -75
- data/ext/redis_client/hiredis/vendor/dict.c +0 -352
- data/ext/redis_client/hiredis/vendor/dict.h +0 -126
- data/ext/redis_client/hiredis/vendor/fmacros.h +0 -12
- data/ext/redis_client/hiredis/vendor/hiredis-config.cmake.in +0 -13
- data/ext/redis_client/hiredis/vendor/hiredis.c +0 -1174
- data/ext/redis_client/hiredis/vendor/hiredis.h +0 -336
- data/ext/redis_client/hiredis/vendor/hiredis.pc.in +0 -12
- data/ext/redis_client/hiredis/vendor/hiredis_ssl-config.cmake.in +0 -13
- data/ext/redis_client/hiredis/vendor/hiredis_ssl.h +0 -157
- data/ext/redis_client/hiredis/vendor/hiredis_ssl.pc.in +0 -12
- data/ext/redis_client/hiredis/vendor/net.c +0 -612
- data/ext/redis_client/hiredis/vendor/net.h +0 -56
- data/ext/redis_client/hiredis/vendor/read.c +0 -739
- data/ext/redis_client/hiredis/vendor/read.h +0 -129
- data/ext/redis_client/hiredis/vendor/sds.c +0 -1289
- data/ext/redis_client/hiredis/vendor/sds.h +0 -278
- data/ext/redis_client/hiredis/vendor/sdsalloc.h +0 -44
- data/ext/redis_client/hiredis/vendor/sockcompat.c +0 -248
- data/ext/redis_client/hiredis/vendor/sockcompat.h +0 -92
- data/ext/redis_client/hiredis/vendor/ssl.c +0 -544
- data/ext/redis_client/hiredis/vendor/test.c +0 -1401
- data/ext/redis_client/hiredis/vendor/test.sh +0 -78
- data/ext/redis_client/hiredis/vendor/win32.h +0 -56
- data/lib/redis_client/hiredis_connection.rb +0 -93
@@ -1,175 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* Copyright (c) 2010-2011, Pieter Noordhuis <pcnoordhuis at gmail dot com>
|
3
|
-
*
|
4
|
-
* All rights reserved.
|
5
|
-
*
|
6
|
-
* Redistribution and use in source and binary forms, with or without
|
7
|
-
* modification, are permitted provided that the following conditions are met:
|
8
|
-
*
|
9
|
-
* * Redistributions of source code must retain the above copyright notice,
|
10
|
-
* this list of conditions and the following disclaimer.
|
11
|
-
* * Redistributions in binary form must reproduce the above copyright
|
12
|
-
* notice, this list of conditions and the following disclaimer in the
|
13
|
-
* documentation and/or other materials provided with the distribution.
|
14
|
-
* * Neither the name of Redis nor the names of its contributors may be used
|
15
|
-
* to endorse or promote products derived from this software without
|
16
|
-
* specific prior written permission.
|
17
|
-
*
|
18
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
19
|
-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
20
|
-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
21
|
-
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
22
|
-
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
23
|
-
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
24
|
-
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
25
|
-
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
26
|
-
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
27
|
-
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28
|
-
* POSSIBILITY OF SUCH DAMAGE.
|
29
|
-
*/
|
30
|
-
|
31
|
-
#ifndef __HIREDIS_LIBEVENT_H__
|
32
|
-
#define __HIREDIS_LIBEVENT_H__
|
33
|
-
#include <event2/event.h>
|
34
|
-
#include "../hiredis.h"
|
35
|
-
#include "../async.h"
|
36
|
-
|
37
|
-
#define REDIS_LIBEVENT_DELETED 0x01
|
38
|
-
#define REDIS_LIBEVENT_ENTERED 0x02
|
39
|
-
|
40
|
-
typedef struct redisLibeventEvents {
|
41
|
-
redisAsyncContext *context;
|
42
|
-
struct event *ev;
|
43
|
-
struct event_base *base;
|
44
|
-
struct timeval tv;
|
45
|
-
short flags;
|
46
|
-
short state;
|
47
|
-
} redisLibeventEvents;
|
48
|
-
|
49
|
-
static void redisLibeventDestroy(redisLibeventEvents *e) {
|
50
|
-
hi_free(e);
|
51
|
-
}
|
52
|
-
|
53
|
-
static void redisLibeventHandler(int fd, short event, void *arg) {
|
54
|
-
((void)fd);
|
55
|
-
redisLibeventEvents *e = (redisLibeventEvents*)arg;
|
56
|
-
e->state |= REDIS_LIBEVENT_ENTERED;
|
57
|
-
|
58
|
-
#define CHECK_DELETED() if (e->state & REDIS_LIBEVENT_DELETED) {\
|
59
|
-
redisLibeventDestroy(e);\
|
60
|
-
return; \
|
61
|
-
}
|
62
|
-
|
63
|
-
if ((event & EV_TIMEOUT) && (e->state & REDIS_LIBEVENT_DELETED) == 0) {
|
64
|
-
redisAsyncHandleTimeout(e->context);
|
65
|
-
CHECK_DELETED();
|
66
|
-
}
|
67
|
-
|
68
|
-
if ((event & EV_READ) && e->context && (e->state & REDIS_LIBEVENT_DELETED) == 0) {
|
69
|
-
redisAsyncHandleRead(e->context);
|
70
|
-
CHECK_DELETED();
|
71
|
-
}
|
72
|
-
|
73
|
-
if ((event & EV_WRITE) && e->context && (e->state & REDIS_LIBEVENT_DELETED) == 0) {
|
74
|
-
redisAsyncHandleWrite(e->context);
|
75
|
-
CHECK_DELETED();
|
76
|
-
}
|
77
|
-
|
78
|
-
e->state &= ~REDIS_LIBEVENT_ENTERED;
|
79
|
-
#undef CHECK_DELETED
|
80
|
-
}
|
81
|
-
|
82
|
-
static void redisLibeventUpdate(void *privdata, short flag, int isRemove) {
|
83
|
-
redisLibeventEvents *e = (redisLibeventEvents *)privdata;
|
84
|
-
const struct timeval *tv = e->tv.tv_sec || e->tv.tv_usec ? &e->tv : NULL;
|
85
|
-
|
86
|
-
if (isRemove) {
|
87
|
-
if ((e->flags & flag) == 0) {
|
88
|
-
return;
|
89
|
-
} else {
|
90
|
-
e->flags &= ~flag;
|
91
|
-
}
|
92
|
-
} else {
|
93
|
-
if (e->flags & flag) {
|
94
|
-
return;
|
95
|
-
} else {
|
96
|
-
e->flags |= flag;
|
97
|
-
}
|
98
|
-
}
|
99
|
-
|
100
|
-
event_del(e->ev);
|
101
|
-
event_assign(e->ev, e->base, e->context->c.fd, e->flags | EV_PERSIST,
|
102
|
-
redisLibeventHandler, privdata);
|
103
|
-
event_add(e->ev, tv);
|
104
|
-
}
|
105
|
-
|
106
|
-
static void redisLibeventAddRead(void *privdata) {
|
107
|
-
redisLibeventUpdate(privdata, EV_READ, 0);
|
108
|
-
}
|
109
|
-
|
110
|
-
static void redisLibeventDelRead(void *privdata) {
|
111
|
-
redisLibeventUpdate(privdata, EV_READ, 1);
|
112
|
-
}
|
113
|
-
|
114
|
-
static void redisLibeventAddWrite(void *privdata) {
|
115
|
-
redisLibeventUpdate(privdata, EV_WRITE, 0);
|
116
|
-
}
|
117
|
-
|
118
|
-
static void redisLibeventDelWrite(void *privdata) {
|
119
|
-
redisLibeventUpdate(privdata, EV_WRITE, 1);
|
120
|
-
}
|
121
|
-
|
122
|
-
static void redisLibeventCleanup(void *privdata) {
|
123
|
-
redisLibeventEvents *e = (redisLibeventEvents*)privdata;
|
124
|
-
if (!e) {
|
125
|
-
return;
|
126
|
-
}
|
127
|
-
event_del(e->ev);
|
128
|
-
event_free(e->ev);
|
129
|
-
e->ev = NULL;
|
130
|
-
|
131
|
-
if (e->state & REDIS_LIBEVENT_ENTERED) {
|
132
|
-
e->state |= REDIS_LIBEVENT_DELETED;
|
133
|
-
} else {
|
134
|
-
redisLibeventDestroy(e);
|
135
|
-
}
|
136
|
-
}
|
137
|
-
|
138
|
-
static void redisLibeventSetTimeout(void *privdata, struct timeval tv) {
|
139
|
-
redisLibeventEvents *e = (redisLibeventEvents *)privdata;
|
140
|
-
short flags = e->flags;
|
141
|
-
e->flags = 0;
|
142
|
-
e->tv = tv;
|
143
|
-
redisLibeventUpdate(e, flags, 0);
|
144
|
-
}
|
145
|
-
|
146
|
-
static int redisLibeventAttach(redisAsyncContext *ac, struct event_base *base) {
|
147
|
-
redisContext *c = &(ac->c);
|
148
|
-
redisLibeventEvents *e;
|
149
|
-
|
150
|
-
/* Nothing should be attached when something is already attached */
|
151
|
-
if (ac->ev.data != NULL)
|
152
|
-
return REDIS_ERR;
|
153
|
-
|
154
|
-
/* Create container for context and r/w events */
|
155
|
-
e = (redisLibeventEvents*)hi_calloc(1, sizeof(*e));
|
156
|
-
if (e == NULL)
|
157
|
-
return REDIS_ERR;
|
158
|
-
|
159
|
-
e->context = ac;
|
160
|
-
|
161
|
-
/* Register functions to start/stop listening for events */
|
162
|
-
ac->ev.addRead = redisLibeventAddRead;
|
163
|
-
ac->ev.delRead = redisLibeventDelRead;
|
164
|
-
ac->ev.addWrite = redisLibeventAddWrite;
|
165
|
-
ac->ev.delWrite = redisLibeventDelWrite;
|
166
|
-
ac->ev.cleanup = redisLibeventCleanup;
|
167
|
-
ac->ev.scheduleTimer = redisLibeventSetTimeout;
|
168
|
-
ac->ev.data = e;
|
169
|
-
|
170
|
-
/* Initialize and install read/write events */
|
171
|
-
e->ev = event_new(base, c->fd, EV_READ | EV_WRITE, redisLibeventHandler, e);
|
172
|
-
e->base = base;
|
173
|
-
return REDIS_OK;
|
174
|
-
}
|
175
|
-
#endif
|
@@ -1,117 +0,0 @@
|
|
1
|
-
#ifndef __HIREDIS_LIBUV_H__
|
2
|
-
#define __HIREDIS_LIBUV_H__
|
3
|
-
#include <stdlib.h>
|
4
|
-
#include <uv.h>
|
5
|
-
#include "../hiredis.h"
|
6
|
-
#include "../async.h"
|
7
|
-
#include <string.h>
|
8
|
-
|
9
|
-
typedef struct redisLibuvEvents {
|
10
|
-
redisAsyncContext* context;
|
11
|
-
uv_poll_t handle;
|
12
|
-
int events;
|
13
|
-
} redisLibuvEvents;
|
14
|
-
|
15
|
-
|
16
|
-
static void redisLibuvPoll(uv_poll_t* handle, int status, int events) {
|
17
|
-
redisLibuvEvents* p = (redisLibuvEvents*)handle->data;
|
18
|
-
int ev = (status ? p->events : events);
|
19
|
-
|
20
|
-
if (p->context != NULL && (ev & UV_READABLE)) {
|
21
|
-
redisAsyncHandleRead(p->context);
|
22
|
-
}
|
23
|
-
if (p->context != NULL && (ev & UV_WRITABLE)) {
|
24
|
-
redisAsyncHandleWrite(p->context);
|
25
|
-
}
|
26
|
-
}
|
27
|
-
|
28
|
-
|
29
|
-
static void redisLibuvAddRead(void *privdata) {
|
30
|
-
redisLibuvEvents* p = (redisLibuvEvents*)privdata;
|
31
|
-
|
32
|
-
p->events |= UV_READABLE;
|
33
|
-
|
34
|
-
uv_poll_start(&p->handle, p->events, redisLibuvPoll);
|
35
|
-
}
|
36
|
-
|
37
|
-
|
38
|
-
static void redisLibuvDelRead(void *privdata) {
|
39
|
-
redisLibuvEvents* p = (redisLibuvEvents*)privdata;
|
40
|
-
|
41
|
-
p->events &= ~UV_READABLE;
|
42
|
-
|
43
|
-
if (p->events) {
|
44
|
-
uv_poll_start(&p->handle, p->events, redisLibuvPoll);
|
45
|
-
} else {
|
46
|
-
uv_poll_stop(&p->handle);
|
47
|
-
}
|
48
|
-
}
|
49
|
-
|
50
|
-
|
51
|
-
static void redisLibuvAddWrite(void *privdata) {
|
52
|
-
redisLibuvEvents* p = (redisLibuvEvents*)privdata;
|
53
|
-
|
54
|
-
p->events |= UV_WRITABLE;
|
55
|
-
|
56
|
-
uv_poll_start(&p->handle, p->events, redisLibuvPoll);
|
57
|
-
}
|
58
|
-
|
59
|
-
|
60
|
-
static void redisLibuvDelWrite(void *privdata) {
|
61
|
-
redisLibuvEvents* p = (redisLibuvEvents*)privdata;
|
62
|
-
|
63
|
-
p->events &= ~UV_WRITABLE;
|
64
|
-
|
65
|
-
if (p->events) {
|
66
|
-
uv_poll_start(&p->handle, p->events, redisLibuvPoll);
|
67
|
-
} else {
|
68
|
-
uv_poll_stop(&p->handle);
|
69
|
-
}
|
70
|
-
}
|
71
|
-
|
72
|
-
|
73
|
-
static void on_close(uv_handle_t* handle) {
|
74
|
-
redisLibuvEvents* p = (redisLibuvEvents*)handle->data;
|
75
|
-
|
76
|
-
hi_free(p);
|
77
|
-
}
|
78
|
-
|
79
|
-
|
80
|
-
static void redisLibuvCleanup(void *privdata) {
|
81
|
-
redisLibuvEvents* p = (redisLibuvEvents*)privdata;
|
82
|
-
|
83
|
-
p->context = NULL; // indicate that context might no longer exist
|
84
|
-
uv_close((uv_handle_t*)&p->handle, on_close);
|
85
|
-
}
|
86
|
-
|
87
|
-
|
88
|
-
static int redisLibuvAttach(redisAsyncContext* ac, uv_loop_t* loop) {
|
89
|
-
redisContext *c = &(ac->c);
|
90
|
-
|
91
|
-
if (ac->ev.data != NULL) {
|
92
|
-
return REDIS_ERR;
|
93
|
-
}
|
94
|
-
|
95
|
-
ac->ev.addRead = redisLibuvAddRead;
|
96
|
-
ac->ev.delRead = redisLibuvDelRead;
|
97
|
-
ac->ev.addWrite = redisLibuvAddWrite;
|
98
|
-
ac->ev.delWrite = redisLibuvDelWrite;
|
99
|
-
ac->ev.cleanup = redisLibuvCleanup;
|
100
|
-
|
101
|
-
redisLibuvEvents* p = (redisLibuvEvents*)hi_malloc(sizeof(*p));
|
102
|
-
if (p == NULL)
|
103
|
-
return REDIS_ERR;
|
104
|
-
|
105
|
-
memset(p, 0, sizeof(*p));
|
106
|
-
|
107
|
-
if (uv_poll_init_socket(loop, &p->handle, c->fd) != 0) {
|
108
|
-
return REDIS_ERR;
|
109
|
-
}
|
110
|
-
|
111
|
-
ac->ev.data = p;
|
112
|
-
p->handle.data = p;
|
113
|
-
p->context = ac;
|
114
|
-
|
115
|
-
return REDIS_OK;
|
116
|
-
}
|
117
|
-
#endif
|
@@ -1,115 +0,0 @@
|
|
1
|
-
//
|
2
|
-
// Created by Дмитрий Бахвалов on 13.07.15.
|
3
|
-
// Copyright (c) 2015 Dmitry Bakhvalov. All rights reserved.
|
4
|
-
//
|
5
|
-
|
6
|
-
#ifndef __HIREDIS_MACOSX_H__
|
7
|
-
#define __HIREDIS_MACOSX_H__
|
8
|
-
|
9
|
-
#include <CoreFoundation/CoreFoundation.h>
|
10
|
-
|
11
|
-
#include "../hiredis.h"
|
12
|
-
#include "../async.h"
|
13
|
-
|
14
|
-
typedef struct {
|
15
|
-
redisAsyncContext *context;
|
16
|
-
CFSocketRef socketRef;
|
17
|
-
CFRunLoopSourceRef sourceRef;
|
18
|
-
} RedisRunLoop;
|
19
|
-
|
20
|
-
static int freeRedisRunLoop(RedisRunLoop* redisRunLoop) {
|
21
|
-
if( redisRunLoop != NULL ) {
|
22
|
-
if( redisRunLoop->sourceRef != NULL ) {
|
23
|
-
CFRunLoopSourceInvalidate(redisRunLoop->sourceRef);
|
24
|
-
CFRelease(redisRunLoop->sourceRef);
|
25
|
-
}
|
26
|
-
if( redisRunLoop->socketRef != NULL ) {
|
27
|
-
CFSocketInvalidate(redisRunLoop->socketRef);
|
28
|
-
CFRelease(redisRunLoop->socketRef);
|
29
|
-
}
|
30
|
-
hi_free(redisRunLoop);
|
31
|
-
}
|
32
|
-
return REDIS_ERR;
|
33
|
-
}
|
34
|
-
|
35
|
-
static void redisMacOSAddRead(void *privdata) {
|
36
|
-
RedisRunLoop *redisRunLoop = (RedisRunLoop*)privdata;
|
37
|
-
CFSocketEnableCallBacks(redisRunLoop->socketRef, kCFSocketReadCallBack);
|
38
|
-
}
|
39
|
-
|
40
|
-
static void redisMacOSDelRead(void *privdata) {
|
41
|
-
RedisRunLoop *redisRunLoop = (RedisRunLoop*)privdata;
|
42
|
-
CFSocketDisableCallBacks(redisRunLoop->socketRef, kCFSocketReadCallBack);
|
43
|
-
}
|
44
|
-
|
45
|
-
static void redisMacOSAddWrite(void *privdata) {
|
46
|
-
RedisRunLoop *redisRunLoop = (RedisRunLoop*)privdata;
|
47
|
-
CFSocketEnableCallBacks(redisRunLoop->socketRef, kCFSocketWriteCallBack);
|
48
|
-
}
|
49
|
-
|
50
|
-
static void redisMacOSDelWrite(void *privdata) {
|
51
|
-
RedisRunLoop *redisRunLoop = (RedisRunLoop*)privdata;
|
52
|
-
CFSocketDisableCallBacks(redisRunLoop->socketRef, kCFSocketWriteCallBack);
|
53
|
-
}
|
54
|
-
|
55
|
-
static void redisMacOSCleanup(void *privdata) {
|
56
|
-
RedisRunLoop *redisRunLoop = (RedisRunLoop*)privdata;
|
57
|
-
freeRedisRunLoop(redisRunLoop);
|
58
|
-
}
|
59
|
-
|
60
|
-
static void redisMacOSAsyncCallback(CFSocketRef __unused s, CFSocketCallBackType callbackType, CFDataRef __unused address, const void __unused *data, void *info) {
|
61
|
-
redisAsyncContext* context = (redisAsyncContext*) info;
|
62
|
-
|
63
|
-
switch (callbackType) {
|
64
|
-
case kCFSocketReadCallBack:
|
65
|
-
redisAsyncHandleRead(context);
|
66
|
-
break;
|
67
|
-
|
68
|
-
case kCFSocketWriteCallBack:
|
69
|
-
redisAsyncHandleWrite(context);
|
70
|
-
break;
|
71
|
-
|
72
|
-
default:
|
73
|
-
break;
|
74
|
-
}
|
75
|
-
}
|
76
|
-
|
77
|
-
static int redisMacOSAttach(redisAsyncContext *redisAsyncCtx, CFRunLoopRef runLoop) {
|
78
|
-
redisContext *redisCtx = &(redisAsyncCtx->c);
|
79
|
-
|
80
|
-
/* Nothing should be attached when something is already attached */
|
81
|
-
if( redisAsyncCtx->ev.data != NULL ) return REDIS_ERR;
|
82
|
-
|
83
|
-
RedisRunLoop* redisRunLoop = (RedisRunLoop*) hi_calloc(1, sizeof(RedisRunLoop));
|
84
|
-
if (redisRunLoop == NULL)
|
85
|
-
return REDIS_ERR;
|
86
|
-
|
87
|
-
/* Setup redis stuff */
|
88
|
-
redisRunLoop->context = redisAsyncCtx;
|
89
|
-
|
90
|
-
redisAsyncCtx->ev.addRead = redisMacOSAddRead;
|
91
|
-
redisAsyncCtx->ev.delRead = redisMacOSDelRead;
|
92
|
-
redisAsyncCtx->ev.addWrite = redisMacOSAddWrite;
|
93
|
-
redisAsyncCtx->ev.delWrite = redisMacOSDelWrite;
|
94
|
-
redisAsyncCtx->ev.cleanup = redisMacOSCleanup;
|
95
|
-
redisAsyncCtx->ev.data = redisRunLoop;
|
96
|
-
|
97
|
-
/* Initialize and install read/write events */
|
98
|
-
CFSocketContext socketCtx = { 0, redisAsyncCtx, NULL, NULL, NULL };
|
99
|
-
|
100
|
-
redisRunLoop->socketRef = CFSocketCreateWithNative(NULL, redisCtx->fd,
|
101
|
-
kCFSocketReadCallBack | kCFSocketWriteCallBack,
|
102
|
-
redisMacOSAsyncCallback,
|
103
|
-
&socketCtx);
|
104
|
-
if( !redisRunLoop->socketRef ) return freeRedisRunLoop(redisRunLoop);
|
105
|
-
|
106
|
-
redisRunLoop->sourceRef = CFSocketCreateRunLoopSource(NULL, redisRunLoop->socketRef, 0);
|
107
|
-
if( !redisRunLoop->sourceRef ) return freeRedisRunLoop(redisRunLoop);
|
108
|
-
|
109
|
-
CFRunLoopAddSource(runLoop, redisRunLoop->sourceRef, kCFRunLoopDefaultMode);
|
110
|
-
|
111
|
-
return REDIS_OK;
|
112
|
-
}
|
113
|
-
|
114
|
-
#endif
|
115
|
-
|
@@ -1,135 +0,0 @@
|
|
1
|
-
/*-
|
2
|
-
* Copyright (C) 2014 Pietro Cerutti <gahr@gahr.ch>
|
3
|
-
*
|
4
|
-
* Redistribution and use in source and binary forms, with or without
|
5
|
-
* modification, are permitted provided that the following conditions
|
6
|
-
* are met:
|
7
|
-
* 1. Redistributions of source code must retain the above copyright
|
8
|
-
* notice, this list of conditions and the following disclaimer.
|
9
|
-
* 2. Redistributions in binary form must reproduce the above copyright
|
10
|
-
* notice, this list of conditions and the following disclaimer in the
|
11
|
-
* documentation and/or other materials provided with the distribution.
|
12
|
-
*
|
13
|
-
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
14
|
-
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
15
|
-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
16
|
-
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
17
|
-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
18
|
-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
19
|
-
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
20
|
-
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
21
|
-
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
22
|
-
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
23
|
-
* SUCH DAMAGE.
|
24
|
-
*/
|
25
|
-
|
26
|
-
#ifndef __HIREDIS_QT_H__
|
27
|
-
#define __HIREDIS_QT_H__
|
28
|
-
#include <QSocketNotifier>
|
29
|
-
#include "../async.h"
|
30
|
-
|
31
|
-
static void RedisQtAddRead(void *);
|
32
|
-
static void RedisQtDelRead(void *);
|
33
|
-
static void RedisQtAddWrite(void *);
|
34
|
-
static void RedisQtDelWrite(void *);
|
35
|
-
static void RedisQtCleanup(void *);
|
36
|
-
|
37
|
-
class RedisQtAdapter : public QObject {
|
38
|
-
|
39
|
-
Q_OBJECT
|
40
|
-
|
41
|
-
friend
|
42
|
-
void RedisQtAddRead(void * adapter) {
|
43
|
-
RedisQtAdapter * a = static_cast<RedisQtAdapter *>(adapter);
|
44
|
-
a->addRead();
|
45
|
-
}
|
46
|
-
|
47
|
-
friend
|
48
|
-
void RedisQtDelRead(void * adapter) {
|
49
|
-
RedisQtAdapter * a = static_cast<RedisQtAdapter *>(adapter);
|
50
|
-
a->delRead();
|
51
|
-
}
|
52
|
-
|
53
|
-
friend
|
54
|
-
void RedisQtAddWrite(void * adapter) {
|
55
|
-
RedisQtAdapter * a = static_cast<RedisQtAdapter *>(adapter);
|
56
|
-
a->addWrite();
|
57
|
-
}
|
58
|
-
|
59
|
-
friend
|
60
|
-
void RedisQtDelWrite(void * adapter) {
|
61
|
-
RedisQtAdapter * a = static_cast<RedisQtAdapter *>(adapter);
|
62
|
-
a->delWrite();
|
63
|
-
}
|
64
|
-
|
65
|
-
friend
|
66
|
-
void RedisQtCleanup(void * adapter) {
|
67
|
-
RedisQtAdapter * a = static_cast<RedisQtAdapter *>(adapter);
|
68
|
-
a->cleanup();
|
69
|
-
}
|
70
|
-
|
71
|
-
public:
|
72
|
-
RedisQtAdapter(QObject * parent = 0)
|
73
|
-
: QObject(parent), m_ctx(0), m_read(0), m_write(0) { }
|
74
|
-
|
75
|
-
~RedisQtAdapter() {
|
76
|
-
if (m_ctx != 0) {
|
77
|
-
m_ctx->ev.data = NULL;
|
78
|
-
}
|
79
|
-
}
|
80
|
-
|
81
|
-
int setContext(redisAsyncContext * ac) {
|
82
|
-
if (ac->ev.data != NULL) {
|
83
|
-
return REDIS_ERR;
|
84
|
-
}
|
85
|
-
m_ctx = ac;
|
86
|
-
m_ctx->ev.data = this;
|
87
|
-
m_ctx->ev.addRead = RedisQtAddRead;
|
88
|
-
m_ctx->ev.delRead = RedisQtDelRead;
|
89
|
-
m_ctx->ev.addWrite = RedisQtAddWrite;
|
90
|
-
m_ctx->ev.delWrite = RedisQtDelWrite;
|
91
|
-
m_ctx->ev.cleanup = RedisQtCleanup;
|
92
|
-
return REDIS_OK;
|
93
|
-
}
|
94
|
-
|
95
|
-
private:
|
96
|
-
void addRead() {
|
97
|
-
if (m_read) return;
|
98
|
-
m_read = new QSocketNotifier(m_ctx->c.fd, QSocketNotifier::Read, 0);
|
99
|
-
connect(m_read, SIGNAL(activated(int)), this, SLOT(read()));
|
100
|
-
}
|
101
|
-
|
102
|
-
void delRead() {
|
103
|
-
if (!m_read) return;
|
104
|
-
delete m_read;
|
105
|
-
m_read = 0;
|
106
|
-
}
|
107
|
-
|
108
|
-
void addWrite() {
|
109
|
-
if (m_write) return;
|
110
|
-
m_write = new QSocketNotifier(m_ctx->c.fd, QSocketNotifier::Write, 0);
|
111
|
-
connect(m_write, SIGNAL(activated(int)), this, SLOT(write()));
|
112
|
-
}
|
113
|
-
|
114
|
-
void delWrite() {
|
115
|
-
if (!m_write) return;
|
116
|
-
delete m_write;
|
117
|
-
m_write = 0;
|
118
|
-
}
|
119
|
-
|
120
|
-
void cleanup() {
|
121
|
-
delRead();
|
122
|
-
delWrite();
|
123
|
-
}
|
124
|
-
|
125
|
-
private slots:
|
126
|
-
void read() { redisAsyncHandleRead(m_ctx); }
|
127
|
-
void write() { redisAsyncHandleWrite(m_ctx); }
|
128
|
-
|
129
|
-
private:
|
130
|
-
redisAsyncContext * m_ctx;
|
131
|
-
QSocketNotifier * m_read;
|
132
|
-
QSocketNotifier * m_write;
|
133
|
-
};
|
134
|
-
|
135
|
-
#endif /* !__HIREDIS_QT_H__ */
|
@@ -1,86 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* Copyright (c) 2020, Michael Grunder <michael dot grunder at gmail dot com>
|
3
|
-
*
|
4
|
-
* All rights reserved.
|
5
|
-
*
|
6
|
-
* Redistribution and use in source and binary forms, with or without
|
7
|
-
* modification, are permitted provided that the following conditions are met:
|
8
|
-
*
|
9
|
-
* * Redistributions of source code must retain the above copyright notice,
|
10
|
-
* this list of conditions and the following disclaimer.
|
11
|
-
* * Redistributions in binary form must reproduce the above copyright
|
12
|
-
* notice, this list of conditions and the following disclaimer in the
|
13
|
-
* documentation and/or other materials provided with the distribution.
|
14
|
-
* * Neither the name of Redis nor the names of its contributors may be used
|
15
|
-
* to endorse or promote products derived from this software without
|
16
|
-
* specific prior written permission.
|
17
|
-
*
|
18
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
19
|
-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
20
|
-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
21
|
-
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
22
|
-
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
23
|
-
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
24
|
-
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
25
|
-
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
26
|
-
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
27
|
-
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28
|
-
* POSSIBILITY OF SUCH DAMAGE.
|
29
|
-
*/
|
30
|
-
|
31
|
-
#include "fmacros.h"
|
32
|
-
#include "alloc.h"
|
33
|
-
#include <string.h>
|
34
|
-
#include <stdlib.h>
|
35
|
-
|
36
|
-
hiredisAllocFuncs hiredisAllocFns = {
|
37
|
-
.mallocFn = malloc,
|
38
|
-
.callocFn = calloc,
|
39
|
-
.reallocFn = realloc,
|
40
|
-
.strdupFn = strdup,
|
41
|
-
.freeFn = free,
|
42
|
-
};
|
43
|
-
|
44
|
-
/* Override hiredis' allocators with ones supplied by the user */
|
45
|
-
hiredisAllocFuncs hiredisSetAllocators(hiredisAllocFuncs *override) {
|
46
|
-
hiredisAllocFuncs orig = hiredisAllocFns;
|
47
|
-
|
48
|
-
hiredisAllocFns = *override;
|
49
|
-
|
50
|
-
return orig;
|
51
|
-
}
|
52
|
-
|
53
|
-
/* Reset allocators to use libc defaults */
|
54
|
-
void hiredisResetAllocators(void) {
|
55
|
-
hiredisAllocFns = (hiredisAllocFuncs) {
|
56
|
-
.mallocFn = malloc,
|
57
|
-
.callocFn = calloc,
|
58
|
-
.reallocFn = realloc,
|
59
|
-
.strdupFn = strdup,
|
60
|
-
.freeFn = free,
|
61
|
-
};
|
62
|
-
}
|
63
|
-
|
64
|
-
#ifdef _WIN32
|
65
|
-
|
66
|
-
void *hi_malloc(size_t size) {
|
67
|
-
return hiredisAllocFns.mallocFn(size);
|
68
|
-
}
|
69
|
-
|
70
|
-
void *hi_calloc(size_t nmemb, size_t size) {
|
71
|
-
return hiredisAllocFns.callocFn(nmemb, size);
|
72
|
-
}
|
73
|
-
|
74
|
-
void *hi_realloc(void *ptr, size_t size) {
|
75
|
-
return hiredisAllocFns.reallocFn(ptr, size);
|
76
|
-
}
|
77
|
-
|
78
|
-
char *hi_strdup(const char *str) {
|
79
|
-
return hiredisAllocFns.strdupFn(str);
|
80
|
-
}
|
81
|
-
|
82
|
-
void hi_free(void *ptr) {
|
83
|
-
hiredisAllocFns.freeFn(ptr);
|
84
|
-
}
|
85
|
-
|
86
|
-
#endif
|