Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f6a7366

Browse files
committed
Merge branch 'master' into pecl
2 parents 4e99a4d + c0dbf8c commit f6a7366

File tree

6 files changed

+259
-162
lines changed

6 files changed

+259
-162
lines changed

README.markdown

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,6 +1389,7 @@ None.
13891389
<pre>
13901390
$redis->bgSave();
13911391
</pre>
1392+
13921393
## lastSave
13931394

13941395
##### *Description*
@@ -1628,6 +1629,30 @@ None.
16281629
$redis->info();
16291630
</pre>
16301631

1632+
## resetStat
1633+
##### *Description*
1634+
Resets the statistics reported by Redis using the INFO command (`info()` function).
1635+
1636+
These are the counters that are reset:
1637+
1638+
* Keyspace hits
1639+
* Keyspace misses
1640+
* Number of commands processed
1641+
* Number of connections received
1642+
* Number of expired keys
1643+
1644+
1645+
##### *Parameters*
1646+
None.
1647+
1648+
##### *Return value*
1649+
*BOOL*: `TRUE` in case of success, `FALSE` in case of failure.
1650+
1651+
##### *Example*
1652+
<pre>
1653+
$redis->resetStat();
1654+
</pre>
1655+
16311656
## ttl
16321657
##### *Description*
16331658
Returns the time to live left for a given key, in seconds. If the key doesn't exist, `FALSE` is returned.

common.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,23 @@
5252

5353

5454
#define MULTI_RESPONSE(callback) IF_MULTI_OR_PIPELINE() { \
55-
fold_item *f1 = malloc(sizeof(fold_item)); \
55+
fold_item *f1, *current; \
56+
f1 = malloc(sizeof(fold_item)); \
5657
f1->fun = (void *)callback; \
5758
f1->next = NULL; \
58-
fold_item *current = redis_sock->current;\
59+
current = redis_sock->current;\
5960
if(current) current->next = f1; \
6061
redis_sock->current = f1; \
6162
}
6263

6364
#define PIPELINE_ENQUEUE_COMMAND(cmd, cmd_len) request_item *tmp; \
65+
struct request_item *current_request;\
6466
tmp = malloc(sizeof(request_item));\
6567
tmp->request_str = calloc(cmd_len, 1);\
6668
memcpy(tmp->request_str, cmd, cmd_len);\
6769
tmp->request_size = cmd_len;\
6870
tmp->next = NULL;\
69-
struct request_item *current_request = redis_sock->pipeline_current; \
71+
current_request = redis_sock->pipeline_current; \
7072
if(current_request) {\
7173
current_request->next = tmp;\
7274
} \
@@ -81,11 +83,12 @@
8183
}
8284

8385
#define REDIS_SAVE_CALLBACK(callback, closure_context) IF_MULTI_OR_PIPELINE() { \
84-
fold_item *f1 = malloc(sizeof(fold_item)); \
86+
fold_item *f1, *current; \
87+
f1 = malloc(sizeof(fold_item)); \
8588
f1->fun = (void *)callback; \
8689
f1->ctx = closure_context; \
8790
f1->next = NULL; \
88-
fold_item *current = redis_sock->current;\
91+
current = redis_sock->current;\
8992
if(current) current->next = f1; \
9093
redis_sock->current = f1; \
9194
if(NULL == redis_sock->head) { \

config.w32

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// vim: ft=javascript:
2+
3+
ARG_ENABLE("redis", "whether to enable redis support", "yes");
4+
ARG_ENABLE("redis-session", "whether to enable sessions", "yes");
5+
6+
if (PHP_REDIS != "no") {
7+
var sources = "redis.c library.c igbinary\\igbinary.c igbinary\\hash_si.c igbinary\\hash_function.c";
8+
if (PHP_REDIS_SESSION != "no") {
9+
AC_DEFINE('PHP_SESSION', 1);
10+
sources += " redis_session.c";
11+
}
12+
13+
AC_DEFINE("PHP_EXPORTS", 1);
14+
EXTENSION("redis", sources);
15+
}

library.c

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
#include "common.h"
66
#include "php_network.h"
77
#include <sys/types.h>
8+
#ifndef _MSC_VER
89
#include <netinet/tcp.h> /* TCP_NODELAY */
910
#include <sys/socket.h>
11+
#endif
1012
#include <ext/standard/php_smart_str.h>
1113
#include <ext/standard/php_var.h>
1214

@@ -61,6 +63,8 @@ PHPAPI int redis_check_eof(RedisSock *redis_sock TSRMLS_DC)
6163

6264
PHPAPI zval *redis_sock_read_multibulk_reply_zval(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock) {
6365
char inbuf[1024];
66+
int numElems;
67+
zval *z_tab;
6468

6569
if(-1 == redis_check_eof(redis_sock TSRMLS_CC)) {
6670
return NULL;
@@ -78,9 +82,8 @@ PHPAPI zval *redis_sock_read_multibulk_reply_zval(INTERNAL_FUNCTION_PARAMETERS,
7882
if(inbuf[0] != '*') {
7983
return NULL;
8084
}
81-
int numElems = atoi(inbuf+1);
85+
numElems = atoi(inbuf+1);
8286

83-
zval *z_tab;
8487
MAKE_STD_ZVAL(z_tab);
8588
array_init(z_tab);
8689

@@ -106,14 +109,15 @@ PHPAPI char *redis_sock_read_bulk_reply(RedisSock *redis_sock, int bytes TSRMLS_
106109
if (bytes == -1) {
107110
return NULL;
108111
} else {
109-
reply = emalloc(bytes+1);
112+
char c;
113+
int i;
114+
115+
reply = emalloc(bytes+1);
110116

111117
while(offset < bytes) {
112118
got = php_stream_read(redis_sock->stream, reply + offset, bytes-offset);
113119
offset += got;
114120
}
115-
char c;
116-
int i;
117121
for(i = 0; i < 2; i++) {
118122
php_stream_read(redis_sock->stream, &c, 1);
119123
}
@@ -128,7 +132,6 @@ PHPAPI char *redis_sock_read_bulk_reply(RedisSock *redis_sock, int bytes TSRMLS_
128132
*/
129133
PHPAPI char *redis_sock_read(RedisSock *redis_sock, int *buf_len TSRMLS_DC)
130134
{
131-
132135
char inbuf[1024];
133136
char *resp = NULL;
134137

@@ -146,7 +149,6 @@ PHPAPI char *redis_sock_read(RedisSock *redis_sock, int *buf_len TSRMLS_DC)
146149
}
147150

148151
switch(inbuf[0]) {
149-
150152
case '-':
151153
return NULL;
152154

@@ -156,6 +158,7 @@ PHPAPI char *redis_sock_read(RedisSock *redis_sock, int *buf_len TSRMLS_DC)
156158
return resp;
157159

158160
case '+':
161+
case '*':
159162
case ':':
160163
// Single Line Reply
161164
/* :123\r\n */
@@ -180,7 +183,6 @@ PHPAPI char *redis_sock_read(RedisSock *redis_sock, int *buf_len TSRMLS_DC)
180183
}
181184

182185
void add_constant_long(zend_class_entry *ce, char *name, int value) {
183-
184186
zval *constval;
185187
constval = pemalloc(sizeof(zval), 1);
186188
INIT_PZVAL(constval);
@@ -330,12 +332,13 @@ PHPAPI void redis_bulk_double_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *
330332

331333
char *response;
332334
int response_len;
335+
double ret;
333336

334337
if ((response = redis_sock_read(redis_sock, &response_len TSRMLS_CC)) == NULL) {
335338
RETURN_FALSE;
336339
}
337340

338-
double ret = atof(response);
341+
ret = atof(response);
339342
efree(response);
340343
IF_MULTI_OR_PIPELINE() {
341344
add_next_index_double(z_tab, ret);
@@ -347,12 +350,12 @@ PHPAPI void redis_bulk_double_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *
347350
PHPAPI void redis_type_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx) {
348351
char *response;
349352
int response_len;
353+
long l;
350354

351355
if ((response = redis_sock_read(redis_sock, &response_len TSRMLS_CC)) == NULL) {
352356
RETURN_FALSE;
353357
}
354358

355-
long l;
356359
if (strncmp(response, "+string", 7) == 0) {
357360
l = REDIS_STRING;
358361
} else if (strncmp(response, "+set", 4) == 0){
@@ -378,22 +381,23 @@ PHPAPI void redis_type_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_s
378381
PHPAPI void redis_info_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx) {
379382
char *response;
380383
int response_len;
384+
char *pos, *cur;
385+
char *key, *value, *p;
386+
int is_numeric;
387+
zval *z_multi_result;
381388

382389
if ((response = redis_sock_read(redis_sock, &response_len TSRMLS_CC)) == NULL) {
383390
RETURN_FALSE;
384391
}
385392

386-
zval *z_multi_result;
387393
MAKE_STD_ZVAL(z_multi_result);
388394
array_init(z_multi_result); /* pre-allocate array for multi's results. */
389395
/* response :: [response_line]
390396
* response_line :: key ':' value CRLF
391397
*/
392398

393-
char *pos, *cur = response;
399+
cur = response;
394400
while(1) {
395-
char *key, *value, *p;
396-
int is_numeric;
397401
/* key */
398402
pos = strchr(cur, ':');
399403
if(pos == NULL) {
@@ -488,16 +492,16 @@ PHPAPI void redis_long_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_s
488492
}
489493

490494
if(response[0] == ':') {
491-
long long ret = atoll(response + 1);
495+
long ret = atol(response + 1);
492496
IF_MULTI_OR_PIPELINE() {
493-
if(ret > (long long)LONG_MAX) { /* overflow */
497+
if(ret > (long)LONG_MAX) { /* overflow */
494498
add_next_index_stringl(z_tab, response+1, response_len-1, 1);
495499
} else {
496500
efree(response);
497501
add_next_index_long(z_tab, (long)ret);
498502
}
499503
} else {
500-
if(ret > (long long)LONG_MAX) { /* overflow */
504+
if(ret > (long)LONG_MAX) { /* overflow */
501505
RETURN_STRINGL(response+1, response_len-1, 1);
502506
} else {
503507
efree(response);
@@ -522,6 +526,8 @@ PHPAPI int redis_sock_read_multibulk_reply_zipped_with_flag(INTERNAL_FUNCTION_PA
522526
*/
523527

524528
char inbuf[1024];
529+
int numElems;
530+
zval *z_multi_result;
525531

526532
if(-1 == redis_check_eof(redis_sock TSRMLS_CC)) {
527533
return -1;
@@ -539,8 +545,7 @@ PHPAPI int redis_sock_read_multibulk_reply_zipped_with_flag(INTERNAL_FUNCTION_PA
539545
if(inbuf[0] != '*') {
540546
return -1;
541547
}
542-
int numElems = atoi(inbuf+1);
543-
zval *z_multi_result;
548+
numElems = atoi(inbuf+1);
544549
MAKE_STD_ZVAL(z_multi_result);
545550
array_init(z_multi_result); /* pre-allocate array for multi's results. */
546551

@@ -699,6 +704,8 @@ PHPAPI int redis_sock_connect(RedisSock *redis_sock TSRMLS_DC)
699704
struct timeval tv, *tv_ptr = NULL;
700705
char *host = NULL, *persistent_id = NULL, *errstr = NULL;
701706
int host_len, err = 0;
707+
php_netstream_data_t *sock;
708+
int tcp_flag = 1;
702709

703710
if (redis_sock->stream != NULL) {
704711
redis_sock_disconnect(redis_sock TSRMLS_CC);
@@ -742,8 +749,7 @@ PHPAPI int redis_sock_connect(RedisSock *redis_sock TSRMLS_DC)
742749
}
743750

744751
/* set TCP_NODELAY */
745-
php_netstream_data_t *sock = (php_netstream_data_t*)redis_sock->stream->abstract;
746-
int tcp_flag = 1;
752+
sock = (php_netstream_data_t*)redis_sock->stream->abstract;
747753
setsockopt(sock->socket, IPPROTO_TCP, TCP_NODELAY, (char *) &tcp_flag, sizeof(int));
748754

749755
php_stream_auto_cleanup(redis_sock->stream);
@@ -820,6 +826,8 @@ PHPAPI int redis_sock_disconnect(RedisSock *redis_sock TSRMLS_DC)
820826
PHPAPI int redis_sock_read_multibulk_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx)
821827
{
822828
char inbuf[1024];
829+
int numElems;
830+
zval *z_multi_result;
823831

824832
if(-1 == redis_check_eof(redis_sock TSRMLS_CC)) {
825833
return -1;
@@ -836,8 +844,7 @@ PHPAPI int redis_sock_read_multibulk_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSo
836844
if(inbuf[0] != '*') {
837845
return -1;
838846
}
839-
int numElems = atoi(inbuf+1);
840-
zval *z_multi_result;
847+
numElems = atoi(inbuf+1);
841848
MAKE_STD_ZVAL(z_multi_result);
842849
array_init(z_multi_result); /* pre-allocate array for multi's results. */
843850

@@ -860,6 +867,8 @@ PHPAPI int redis_sock_read_multibulk_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSo
860867
PHPAPI int redis_sock_read_multibulk_reply_raw(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx)
861868
{
862869
char inbuf[1024];
870+
int numElems;
871+
zval *z_multi_result;
863872

864873
if(-1 == redis_check_eof(redis_sock TSRMLS_CC)) {
865874
return -1;
@@ -876,8 +885,7 @@ PHPAPI int redis_sock_read_multibulk_reply_raw(INTERNAL_FUNCTION_PARAMETERS, Red
876885
if(inbuf[0] != '*') {
877886
return -1;
878887
}
879-
int numElems = atoi(inbuf+1);
880-
zval *z_multi_result;
888+
numElems = atoi(inbuf+1);
881889
MAKE_STD_ZVAL(z_multi_result);
882890
array_init(z_multi_result); /* pre-allocate array for multi's results. */
883891

@@ -926,6 +934,8 @@ PHPAPI int redis_sock_read_multibulk_reply_assoc(INTERNAL_FUNCTION_PARAMETERS, R
926934
{
927935
char inbuf[1024], *response;
928936
int response_len;
937+
int i, numElems;
938+
zval *z_multi_result;
929939

930940
zval **z_keys = ctx;
931941

@@ -944,8 +954,7 @@ PHPAPI int redis_sock_read_multibulk_reply_assoc(INTERNAL_FUNCTION_PARAMETERS, R
944954
if(inbuf[0] != '*') {
945955
return -1;
946956
}
947-
int i, numElems = atoi(inbuf+1);
948-
zval *z_multi_result;
957+
numElems = atoi(inbuf+1);
949958
MAKE_STD_ZVAL(z_multi_result);
950959
array_init(z_multi_result); /* pre-allocate array for multi's results. */
951960

@@ -1122,12 +1131,15 @@ redis_unserialize(RedisSock *redis_sock, const char *val, int val_len, zval **re
11221131

11231132
PHPAPI int
11241133
redis_key_prefix(RedisSock *redis_sock, char **key, int *key_len TSRMLS_DC) {
1134+
int ret_len;
1135+
char *ret;
1136+
11251137
if(redis_sock->prefix == NULL || redis_sock->prefix_len == 0) {
11261138
return 0;
11271139
}
11281140

1129-
int ret_len = redis_sock->prefix_len + *key_len;
1130-
char *ret = ecalloc(1 + ret_len, 1);
1141+
ret_len = redis_sock->prefix_len + *key_len;
1142+
ret = ecalloc(1 + ret_len, 1);
11311143
memcpy(ret, redis_sock->prefix, redis_sock->prefix_len);
11321144
memcpy(ret + redis_sock->prefix_len, *key, *key_len);
11331145

php_redis.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ PHP_METHOD(Redis, auth);
9696
PHP_METHOD(Redis, ttl);
9797
PHP_METHOD(Redis, persist);
9898
PHP_METHOD(Redis, info);
99+
PHP_METHOD(Redis, resetStat);
99100
PHP_METHOD(Redis, select);
100101
PHP_METHOD(Redis, move);
101102
PHP_METHOD(Redis, zAdd);
@@ -190,9 +191,10 @@ PHPAPI void set_pipeline_head(zval *object, request_item *head);
190191
PHPAPI request_item* get_pipeline_current(zval *object);
191192
PHPAPI void set_pipeline_current(zval *object, request_item *current);
192193

194+
#ifndef _MSC_VER
193195
ZEND_BEGIN_MODULE_GLOBALS(redis)
194196
ZEND_END_MODULE_GLOBALS(redis)
195-
197+
#endif
196198

197199
struct redis_queued_item {
198200

0 commit comments

Comments
 (0)