Skip to content

Commit fb05979

Browse files
Merge remote
1 parent ab8fa7d commit fb05979

8 files changed

+70
-97
lines changed

config.w32

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ARG_ENABLE("redis-session", "whether to enable sessions", "yes");
55
ARG_ENABLE("redis-igbinary", "whether to enable igbinary serializer support", "no");
66

77
if (PHP_REDIS != "no") {
8-
var sources = "redis.c library.c redis_array.c redis_array_impl.c";
8+
var sources = "redis.c library.c redis_array.c redis_array_impl.c redis_cluster.c cluster_library.c";
99
if (PHP_REDIS_SESSION != "no") {
1010
ADD_SOURCES(configure_module_dirname, "redis_session.c", "redis");
1111
ADD_EXTENSION_DEP("redis", "session");

library.c

+38-44
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,6 @@
2020
#include <ext/standard/php_math.h>
2121
#include <ext/standard/php_rand.h>
2222

23-
#ifdef PHP_WIN32
24-
# if PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION <= 4
25-
/* This proto is available from 5.5 on only */
26-
PHPAPI int usleep(unsigned int useconds);
27-
# endif
28-
#endif
29-
3023
#define UNSERIALIZE_NONE 0
3124
#define UNSERIALIZE_KEYS 1
3225
#define UNSERIALIZE_VALS 2
@@ -130,12 +123,12 @@ static void redis_error_throw(char *err, size_t err_len TSRMLS_DC) {
130123
}
131124
}
132125

133-
PHP_REDIS_API void redis_stream_close(RedisSock *redis_sock TSRMLS_DC) {
134-
if (!redis_sock->persistent) {
135-
php_stream_close(redis_sock->stream);
136-
} else {
137-
php_stream_pclose(redis_sock->stream);
138-
}
126+
PHPAPI void redis_stream_close(RedisSock *redis_sock TSRMLS_DC) {
127+
if (!redis_sock->persistent) {
128+
php_stream_close(redis_sock->stream);
129+
} else {
130+
php_stream_pclose(redis_sock->stream);
131+
}
139132
}
140133

141134
PHP_REDIS_API int redis_check_eof(RedisSock *redis_sock, int no_throw TSRMLS_DC)
@@ -509,7 +502,8 @@ PHP_REDIS_API char *redis_sock_read(RedisSock *redis_sock, int *buf_len TSRMLS_D
509502
redis_sock->status = REDIS_SOCK_STATUS_FAILED;
510503
redis_sock->mode = ATOMIC;
511504
redis_sock->watching = 0;
512-
zend_throw_exception(redis_exception_ce, "read error on connection", 0 TSRMLS_CC);
505+
zend_throw_exception(redis_exception_ce, "read error on connection",
506+
0 TSRMLS_CC);
513507
return NULL;
514508
}
515509

@@ -1086,8 +1080,7 @@ PHPAPI zval* redis_parse_client_list_response(char *response) {
10861080
} else {
10871081
add_assoc_string(z_sub_result, key, value, 0);
10881082
}
1089-
1090-
/* If we hit a '\n', then we can add this user to our list */
1083+
// If we hit a '\n', then we can add this user to our list
10911084
if(*p == '\n') {
10921085
/* Add our user */
10931086
add_next_index_zval(z_result, z_sub_result);
@@ -1099,7 +1092,7 @@ PHPAPI zval* redis_parse_client_list_response(char *response) {
10991092
}
11001093
}
11011094

1102-
/* Free our key */
1095+
// Free our key
11031096
efree(key);
11041097
} else {
11051098
// Something is wrong
@@ -1384,9 +1377,10 @@ PHPAPI int redis_mbulk_reply_zipped_vals(INTERNAL_FUNCTION_PARAMETERS, RedisSock
13841377
z_tab, UNSERIALIZE_VALS, SCORE_DECODE_NONE);
13851378
}
13861379

1387-
PHPAPI void redis_1_response(INTERNAL_FUNCTION_PARAMETERS,
1388-
RedisSock *redis_sock, zval *z_tab, void *ctx)
1380+
PHP_REDIS_API void redis_1_response(INTERNAL_FUNCTION_PARAMETERS,
1381+
RedisSock *redis_sock, zval *z_tab, void *ctx)
13891382
{
1383+
13901384
char *response;
13911385
int response_len;
13921386
char ret;
@@ -1765,23 +1759,23 @@ PHPAPI int redis_sock_set_err(RedisSock *redis_sock, const char *msg,
17651759
redis_sock->err = erealloc(redis_sock->err, msg_len +1);
17661760
}
17671761

1768-
/* Copy in our new error message, set new length, and null terminate */
1769-
memcpy(redis_sock->err, msg, msg_len);
1770-
redis_sock->err[msg_len] = '\0';
1771-
redis_sock->err_len = msg_len;
1772-
} else {
1773-
/* Free our last error */
1774-
if(redis_sock->err != NULL) {
1775-
efree(redis_sock->err);
1776-
}
1762+
// Copy in our new error message, set new length, and null terminate
1763+
memcpy(redis_sock->err, msg, msg_len);
1764+
redis_sock->err[msg_len] = '\0';
1765+
redis_sock->err_len = msg_len;
1766+
} else {
1767+
// Free our last error
1768+
if(redis_sock->err != NULL) {
1769+
efree(redis_sock->err);
1770+
}
17771771

1778-
/* Set to null, with zero length */
1779-
redis_sock->err = NULL;
1780-
redis_sock->err_len = 0;
1781-
}
1772+
// Set to null, with zero length
1773+
redis_sock->err = NULL;
1774+
redis_sock->err_len = 0;
1775+
}
17821776

1783-
/* Success */
1784-
return 0;
1777+
// Success
1778+
return 0;
17851779
}
17861780

17871781
/**
@@ -1813,12 +1807,10 @@ PHPAPI int redis_sock_read_multibulk_reply(INTERNAL_FUNCTION_PARAMETERS,
18131807
IF_MULTI_OR_PIPELINE() {
18141808
add_next_index_bool(z_tab, 0);
18151809
} else {
1816-
/* Capture our error if redis has given us one */
18171810
if (inbuf[0] == '-') {
18181811
err_len = strlen(inbuf+1) - 2;
18191812
redis_sock_set_err(redis_sock, inbuf+1, err_len);
18201813
}
1821-
18221814
RETVAL_FALSE;
18231815
}
18241816
return -1;
@@ -2147,14 +2139,16 @@ redis_unserialize(RedisSock* redis_sock, const char *val, int val_len,
21472139

21482140
case REDIS_SERIALIZER_IGBINARY:
21492141
#ifdef HAVE_REDIS_IGBINARY
2150-
if(!*return_value) {
2151-
MAKE_STD_ZVAL(*return_value);
2152-
rv_free = 1;
2153-
}
2154-
if(igbinary_unserialize((const uint8_t *)val, (size_t)val_len, return_value TSRMLS_CC) == 0) {
2155-
return 1;
2156-
}
2157-
if(rv_free==1) efree(*return_value);
2142+
if(!*return_value) {
2143+
MAKE_STD_ZVAL(*return_value);
2144+
rv_free = 1;
2145+
}
2146+
if(igbinary_unserialize((const uint8_t *)val, (size_t)val_len,
2147+
return_value TSRMLS_CC) == 0)
2148+
{
2149+
return 1;
2150+
}
2151+
if (rv_free==1) efree(*return_value);
21582152
#endif
21592153
return 0;
21602154
break;

library.h

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ PHP_REDIS_API int
6363
redis_serialize(RedisSock *redis_sock, zval *z, char **val, int *val_len TSRMLS_DC);
6464
PHP_REDIS_API int
6565
redis_key_prefix(RedisSock *redis_sock, char **key, int *key_len);
66+
6667
PHP_REDIS_API int
6768
redis_unserialize(RedisSock *redis_sock, const char *val, int val_len, zval **return_value TSRMLS_DC);
6869

redis.c

+5-6
Original file line numberDiff line numberDiff line change
@@ -3485,17 +3485,16 @@ PHP_METHOD(Redis, clearLastError) {
34853485
{
34863486
RETURN_FALSE;
34873487
}
3488-
3489-
/* Grab socket */
3490-
if (redis_sock_get(object, &redis_sock TSRMLS_CC, 0) < 0) {
3488+
// Grab socket
3489+
if(redis_sock_get(object, &redis_sock TSRMLS_CC, 0) < 0) {
34913490
RETURN_FALSE;
34923491
}
34933492

3494-
/* Clear error message if we have one */
3495-
if (redis_sock->err) {
3493+
// Clear error message
3494+
if(redis_sock->err) {
34963495
efree(redis_sock->err);
3497-
redis_sock->err = NULL;
34983496
}
3497+
redis_sock->err = NULL;
34993498

35003499
RETURN_TRUE;
35013500
}

redis_array_impl.c

+1-6
Original file line numberDiff line numberDiff line change
@@ -565,8 +565,8 @@ ra_index_keys(zval *z_pairs, zval *z_redis TSRMLS_DC) {
565565

566566
/* Initialize key array */
567567
zval *z_keys, **z_entry_pp;
568-
HashPosition pos;
569568
MAKE_STD_ZVAL(z_keys);
569+
HashPosition pos;
570570
#if PHP_VERSION_ID > 50300
571571
array_init_size(z_keys, zend_hash_num_elements(Z_ARRVAL_P(z_pairs)));
572572
#else
@@ -960,11 +960,6 @@ ra_move_zset(const char *key, int key_len, zval *z_from, zval *z_to, long ttl TS
960960

961961
zval_dtor(&z_ret);
962962

963-
/* Free the array itself */
964-
efree(z_zadd_args);
965-
966-
zval_dtor(&z_ret);
967-
968963
/* Free the array itself */
969964
efree(z_zadd_args);
970965

redis_cluster.c

+24-24
Original file line numberDiff line numberDiff line change
@@ -2200,8 +2200,27 @@ PHP_METHOD(RedisCluster, exec) {
22002200
CLUSTER_RESET_MULTI(c);
22012201
}
22022202

2203+
/* {{{ proto bool RedisCluster::discard() */
2204+
PHP_METHOD(RedisCluster, discard) {
2205+
redisCluster *c = GET_CONTEXT();
2206+
2207+
if(CLUSTER_IS_ATOMIC(c)) {
2208+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cluster is not in MULTI mode");
2209+
RETURN_FALSE;
2210+
}
2211+
2212+
if(cluster_abort_exec(c TSRMLS_CC)<0) {
2213+
CLUSTER_RESET_MULTI(c);
2214+
}
2215+
2216+
CLUSTER_FREE_QUEUE(c);
2217+
2218+
RETURN_TRUE;
2219+
}
2220+
22032221
/* Get a slot either by key (string) or host/port array */
2204-
static short cluster_cmd_get_slot(redisCluster *c, zval *z_arg TSRMLS_DC)
2222+
static short
2223+
cluster_cmd_get_slot(redisCluster *c, zval *z_arg TSRMLS_DC)
22052224
{
22062225
int key_len, key_free;
22072226
zval **z_host, **z_port, *z_tmp = NULL;
@@ -2211,7 +2230,7 @@ static short cluster_cmd_get_slot(redisCluster *c, zval *z_arg TSRMLS_DC)
22112230
/* If it's a string, treat it as a key. Otherwise, look for a two
22122231
* element array */
22132232
if(Z_TYPE_P(z_arg)==IS_STRING || Z_TYPE_P(z_arg)==IS_LONG ||
2214-
Z_TYPE_P(z_arg)==IS_DOUBLE)
2233+
Z_TYPE_P(z_arg)==IS_DOUBLE)
22152234
{
22162235
/* Allow for any scalar here */
22172236
if (Z_TYPE_P(z_arg) != IS_STRING) {
@@ -2235,7 +2254,7 @@ static short cluster_cmd_get_slot(redisCluster *c, zval *z_arg TSRMLS_DC)
22352254
zval_dtor(z_tmp);
22362255
efree(z_tmp);
22372256
}
2238-
} else if (Z_TYPE_P(z_arg) == IS_ARRAY &&
2257+
} else if (Z_TYPE_P(z_arg) == IS_ARRAY &&
22392258
zend_hash_index_find(Z_ARRVAL_P(z_arg),0,(void**)&z_host)!=FAILURE &&
22402259
zend_hash_index_find(Z_ARRVAL_P(z_arg),1,(void**)&z_port)!=FAILURE &&
22412260
Z_TYPE_PP(z_host)==IS_STRING && Z_TYPE_PP(z_port)==IS_LONG)
@@ -2245,7 +2264,7 @@ static short cluster_cmd_get_slot(redisCluster *c, zval *z_arg TSRMLS_DC)
22452264
(unsigned short)Z_LVAL_PP(z_port));
22462265

22472266
/* Inform the caller if they've passed bad data */
2248-
if(slot < 0) {
2267+
if(slot < 0) {
22492268
php_error_docref(0 TSRMLS_CC, E_WARNING, "Unknown node %s:%ld",
22502269
Z_STRVAL_PP(z_host), Z_LVAL_PP(z_port));
22512270
}
@@ -2258,24 +2277,6 @@ static short cluster_cmd_get_slot(redisCluster *c, zval *z_arg TSRMLS_DC)
22582277
return slot;
22592278
}
22602279

2261-
/* {{{ proto bool RedisCluster::discard() */
2262-
PHP_METHOD(RedisCluster, discard) {
2263-
redisCluster *c = GET_CONTEXT();
2264-
2265-
if(CLUSTER_IS_ATOMIC(c)) {
2266-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cluster is not in MULTI mode");
2267-
RETURN_FALSE;
2268-
}
2269-
2270-
if(cluster_abort_exec(c TSRMLS_CC)<0) {
2271-
CLUSTER_RESET_MULTI(c);
2272-
}
2273-
2274-
CLUSTER_FREE_QUEUE(c);
2275-
2276-
RETURN_TRUE;
2277-
}
2278-
22792280
/* Generic handler for things we want directed at a given node, like SAVE,
22802281
* BGSAVE, FLUSHDB, FLUSHALL, etc */
22812282
static void
@@ -2856,7 +2857,7 @@ PHP_METHOD(RedisCluster, echo) {
28562857
rtype = CLUSTER_IS_ATOMIC(c) ? TYPE_BULK : TYPE_LINE;
28572858
if(cluster_send_slot(c,slot,cmd,cmd_len,rtype TSRMLS_CC)<0) {
28582859
zend_throw_exception(redis_cluster_exception_ce,
2859-
"Unable to send command at the specificed node", 0 TSRMLS_CC);
2860+
"Unable to send commnad at the specificed node", 0 TSRMLS_CC);
28602861
efree(cmd);
28612862
RETURN_FALSE;
28622863
}
@@ -2934,6 +2935,5 @@ PHP_METHOD(RedisCluster, rawcommand) {
29342935
PHP_METHOD(RedisCluster, command) {
29352936
CLUSTER_PROCESS_CMD(command, cluster_variant_resp, 0);
29362937
}
2937-
/* }}} */
29382938

29392939
/* vim: set tabstop=4 softtabstops=4 noexpandtab shiftwidth=4: */

redis_commands.h

-3
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,6 @@ int redis_sdiffstore_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
218218
int redis_command_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
219219
char **cmd, int *cmd_len, short *slot, void **ctx);
220220

221-
int redis_rawcommand_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
222-
char **cmd, int *cmd_len, short *slot, void **ctx);
223-
224221
int redis_fmt_scan_cmd(char **cmd, REDIS_SCAN_TYPE type, char *key, int key_len,
225222
long it, char *pat, int pat_len, long count);
226223

tests/RedisArrayTest.php

-13
Original file line numberDiff line numberDiff line change
@@ -544,17 +544,4 @@ function run_tests($className, $str_filter) {
544544

545545
define('REDIS_ARRAY_DATA_SIZE', 1000);
546546

547-
global $useIndex;
548-
foreach(array(true, false) as $useIndex) {
549-
$str_limit = isset($argv[1]) ? $argv[1] : NULL;
550-
551-
echo "\n".($useIndex?"WITH":"WITHOUT"). " per-node index:\n";
552-
553-
//run_tests('Redis_Array_Test', $str_limit);
554-
run_tests('Redis_Rehashing_Test', $str_limit);
555-
//run_tests('Redis_Auto_Rehashing_Test', $str_limit);
556-
//run_tests('Redis_Multi_Exec_Test', $str_limit);
557-
//run_tests('Redis_Distributor_Test', $str_limit);
558-
}
559-
560547
?>

0 commit comments

Comments
 (0)