Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix build, declaration must be first in context
  • Loading branch information
pierrejoye committed Mar 12, 2016
commit 018c5afcb9b30bf7c3f728e9e890f6b8a63f690a
18 changes: 12 additions & 6 deletions cluster_library.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ extern zend_class_entry *redis_cluster_exception_ce;

static void cluster_dump_nodes(redisCluster *c) {
redisClusterNode **pp, *p;
const char *slave;

for(zend_hash_internal_pointer_reset(c->nodes);
zend_hash_has_more_elements(c->nodes)==SUCCESS;
Expand All @@ -20,7 +21,7 @@ static void cluster_dump_nodes(redisCluster *c) {
zend_hash_get_current_data(c->nodes, (void**)&pp);
p = *pp;

const char *slave = (p->slave) ? "slave" : "master";
slave = (p->slave) ? "slave" : "master";
php_printf("%d %s %d %d", p->sock->port, slave,p->sock->prefix_len,
p->slot);

Expand Down Expand Up @@ -201,12 +202,13 @@ cluster_read_sock_resp(RedisSock *redis_sock, REDIS_REPLY_TYPE type,
size_t len TSRMLS_DC)
{
clusterReply *r;
/* Error flag in case we go recursive */
int err = 0;

r = ecalloc(1, sizeof(clusterReply));
r->type = type;

// Error flag in case we go recursive
int err = 0;


switch(r->type) {
case TYPE_INT:
Expand Down Expand Up @@ -1742,6 +1744,7 @@ PHP_REDIS_API void cluster_unsub_resp(INTERNAL_FUNCTION_PARAMETERS,
subscribeContext *sctx = (subscribeContext*)ctx;
zval *z_tab, **z_chan, **z_flag;
int pull = 0, argc = sctx->argc;
char *flag;

efree(sctx);
array_init(return_value);
Expand Down Expand Up @@ -1774,7 +1777,7 @@ PHP_REDIS_API void cluster_unsub_resp(INTERNAL_FUNCTION_PARAMETERS,
}

// Redis will give us either :1 or :0 here
char *flag = Z_STRVAL_PP(z_flag);
flag = Z_STRVAL_PP(z_flag);

// Add result
add_assoc_bool(return_value, Z_STRVAL_PP(z_chan), flag[1]=='1');
Expand Down Expand Up @@ -2070,10 +2073,12 @@ PHP_REDIS_API zval *cluster_zval_mbulk_resp(INTERNAL_FUNCTION_PARAMETERS,
PHP_REDIS_API void cluster_multi_mbulk_resp(INTERNAL_FUNCTION_PARAMETERS,
redisCluster *c, void *ctx)
{
clusterFoldItem *fi;

MAKE_STD_ZVAL(c->multi_resp);
array_init(c->multi_resp);

clusterFoldItem *fi = c->multi_head;
fi = c->multi_head;
while(fi) {
/* Make sure our transaction didn't fail here */
if (c->multi_len[fi->slot] > -1) {
Expand Down Expand Up @@ -2108,11 +2113,12 @@ PHP_REDIS_API void cluster_mbulk_mget_resp(INTERNAL_FUNCTION_PARAMETERS,
redisCluster *c, void *ctx)
{
clusterMultiCtx *mctx = (clusterMultiCtx*)ctx;
short fail;

/* Protect against an invalid response type, -1 response length, and failure
* to consume the responses. */
c->cmd_sock->serializer = c->flags->serializer;
short fail = c->reply_type != TYPE_MULTIBULK || c->reply_len == -1 ||
fail = c->reply_type != TYPE_MULTIBULK || c->reply_len == -1 ||
mbulk_resp_loop(c->cmd_sock, mctx->z_multi, c->reply_len, NULL TSRMLS_CC)==FAILURE;

// If we had a failure, pad results with FALSE to indicate failure. Non
Expand Down
6 changes: 4 additions & 2 deletions redis.c
Original file line number Diff line number Diff line change
Expand Up @@ -668,12 +668,14 @@ PHP_METHOD(Redis, __construct)
Public Destructor
*/
PHP_METHOD(Redis,__destruct) {
// Grab our socket
RedisSock *redis_sock;

if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) {
RETURN_FALSE;
}

// Grab our socket
RedisSock *redis_sock;

if (redis_sock_get(getThis(), &redis_sock TSRMLS_CC, 1) < 0) {
RETURN_FALSE;
}
Expand Down
3 changes: 2 additions & 1 deletion redis_array_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -565,8 +565,9 @@ ra_index_keys(zval *z_pairs, zval *z_redis TSRMLS_DC) {

/* Initialize key array */
zval *z_keys, **z_entry_pp;
HashPosition pos;

MAKE_STD_ZVAL(z_keys);
HashPosition pos;
#if PHP_VERSION_ID > 50300
array_init_size(z_keys, zend_hash_num_elements(Z_ARRVAL_P(z_pairs)));
#else
Expand Down
3 changes: 2 additions & 1 deletion redis_cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -1600,11 +1600,12 @@ static void generic_zrange_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw,
zrange_cb fun)
{
redisCluster *c = GET_CONTEXT();
c->readonly = CLUSTER_IS_ATOMIC(c);
cluster_cb cb;
char *cmd; int cmd_len; short slot;
int withscores=0;

c->readonly = CLUSTER_IS_ATOMIC(c);

if(fun(INTERNAL_FUNCTION_PARAM_PASSTHRU, c->flags, kw, &cmd, &cmd_len,
&withscores, &slot, NULL)==FAILURE)
{
Expand Down
42 changes: 23 additions & 19 deletions redis_cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,32 +37,36 @@

/* Simple macro to free our enqueued callbacks after we EXEC */
#define CLUSTER_FREE_QUEUE(c) \
clusterFoldItem *_item = c->multi_head, *_tmp; \
while(_item) { \
_tmp = _item->next; \
efree(_item); \
_item = _tmp; \
} \
c->multi_head = c->multi_curr = NULL; \
{ \
clusterFoldItem *_item = c->multi_head, *_tmp; \
while(_item) { \
_tmp = _item->next; \
efree(_item); \
_item = _tmp; \
} \
c->multi_head = c->multi_curr = NULL; \
}

/* Reset anything flagged as MULTI */
#define CLUSTER_RESET_MULTI(c) \
redisClusterNode **_node; \
for(zend_hash_internal_pointer_reset(c->nodes); \
zend_hash_get_current_data(c->nodes, (void**)&_node); \
zend_hash_move_forward(c->nodes)) \
{ \
(*_node)->sock->watching = 0; \
(*_node)->sock->mode = ATOMIC; \
} \
c->flags->watching = 0; \
c->flags->mode = ATOMIC; \
{ \
redisClusterNode **_node; \
for(zend_hash_internal_pointer_reset(c->nodes); \
zend_hash_get_current_data(c->nodes, (void**)&_node); \
zend_hash_move_forward(c->nodes)) \
{ \
(*_node)->sock->watching = 0; \
(*_node)->sock->mode = ATOMIC; \
} \
c->flags->watching = 0; \
c->flags->mode = ATOMIC; \
}

/* Simple 1-1 command -> response macro */
#define CLUSTER_PROCESS_CMD(cmdname, resp_func, readcmd) \
redisCluster *c = GET_CONTEXT(); \
c->readonly = CLUSTER_IS_ATOMIC(c) && readcmd; \
char *cmd; int cmd_len; short slot; void *ctx=NULL; \
c->readonly = CLUSTER_IS_ATOMIC(c) && readcmd; \
if(redis_##cmdname##_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU,c->flags, &cmd, \
&cmd_len, &slot, &ctx)==FAILURE) { \
RETURN_FALSE; \
Expand All @@ -81,8 +85,8 @@
/* More generic processing, where only the keyword differs */
#define CLUSTER_PROCESS_KW_CMD(kw, cmdfunc, resp_func, readcmd) \
redisCluster *c = GET_CONTEXT(); \
c->readonly = CLUSTER_IS_ATOMIC(c) && readcmd; \
char *cmd; int cmd_len; short slot; void *ctx=NULL; \
c->readonly = CLUSTER_IS_ATOMIC(c) && readcmd; \
if(cmdfunc(INTERNAL_FUNCTION_PARAM_PASSTHRU, c->flags, kw, &cmd, &cmd_len,\
&slot,&ctx)==FAILURE) { \
RETURN_FALSE; \
Expand Down