Skip to content

Commit

Permalink
Destroy all tabs :-)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-grunder committed Sep 28, 2017
1 parent 6a53cb9 commit 345fc7f
Show file tree
Hide file tree
Showing 6 changed files with 1,111 additions and 1,110 deletions.
129 changes: 65 additions & 64 deletions library.c
Original file line number Diff line number Diff line change
Expand Up @@ -1517,16 +1517,17 @@ PHP_REDIS_API int redis_sock_disconnect(RedisSock *redis_sock TSRMLS_DC)

redis_sock->dbNumber = 0;
if (redis_sock->stream != NULL) {
redis_sock->status = REDIS_SOCK_STATUS_DISCONNECTED;
redis_sock->watching = 0;
redis_sock->status = REDIS_SOCK_STATUS_DISCONNECTED;
redis_sock->watching = 0;

/* Stil valid? */
if (!redis_sock->persistent) {
php_stream_close(redis_sock->stream);
}
redis_sock->stream = NULL;
/* Stil valid? */
if (!redis_sock->persistent) {
php_stream_close(redis_sock->stream);
}

return 1;
redis_sock->stream = NULL;

return 1;
}

return 0;
Expand Down Expand Up @@ -1967,12 +1968,12 @@ redis_sock_gets(RedisSock *redis_sock, char *buf, int buf_size,
return -1;
}

/* We don't need \r\n */
*line_size-=2;
buf[*line_size]='\0';
/* We don't need \r\n */
*line_size-=2;
buf[*line_size]='\0';

/* Success! */
return 0;
/* Success! */
return 0;
}

PHP_REDIS_API int
Expand Down Expand Up @@ -2001,17 +2002,17 @@ redis_read_reply_type(RedisSock *redis_sock, REDIS_REPLY_TYPE *reply_type,
// Buffer to hold size information
char inbuf[255];

/* Read up to our newline */
if(php_stream_gets(redis_sock->stream, inbuf, sizeof(inbuf)) == NULL) {
return -1;
}
/* Read up to our newline */
if (php_stream_gets(redis_sock->stream, inbuf, sizeof(inbuf)) == NULL) {
return -1;
}

/* Set our size response */
*reply_info = atol(inbuf);
}
/* Set our size response */
*reply_info = atol(inbuf);
}

/* Success! */
return 0;
/* Success! */
return 0;
}

/*
Expand All @@ -2025,26 +2026,26 @@ redis_read_variant_line(RedisSock *redis_sock, REDIS_REPLY_TYPE reply_type,
char inbuf[4096];
size_t line_size;

/* Attempt to read our single line reply */
if(redis_sock_gets(redis_sock, inbuf, sizeof(inbuf), &line_size TSRMLS_CC) < 0) {
return -1;
}
/* Attempt to read our single line reply */
if(redis_sock_gets(redis_sock, inbuf, sizeof(inbuf), &line_size TSRMLS_CC) < 0) {
return -1;
}

// If this is an error response, check if it is a SYNC error, and throw in
// that case
if(reply_type == TYPE_ERR) {
/* Set our last error */
redis_sock_set_err(redis_sock, inbuf, line_size);
/* Set our last error */
redis_sock_set_err(redis_sock, inbuf, line_size);

/* Handle throwable errors */
redis_error_throw(redis_sock TSRMLS_CC);

/* Set our response to FALSE */
ZVAL_FALSE(z_ret);
} else {
/* Set our response to TRUE */
ZVAL_TRUE(z_ret);
}
/* Set our response to FALSE */
ZVAL_FALSE(z_ret);
} else {
/* Set our response to TRUE */
ZVAL_TRUE(z_ret);
}

return 0;
}
Expand All @@ -2056,11 +2057,11 @@ redis_read_variant_bulk(RedisSock *redis_sock, int size, zval *z_ret
// Attempt to read the bulk reply
char *bulk_resp = redis_sock_read_bulk_reply(redis_sock, size TSRMLS_CC);

/* Set our reply to FALSE on failure, and the string on success */
if(bulk_resp == NULL) {
ZVAL_FALSE(z_ret);
return -1;
}
/* Set our reply to FALSE on failure, and the string on success */
if(bulk_resp == NULL) {
ZVAL_FALSE(z_ret);
return -1;
}
ZVAL_STRINGL(z_ret, bulk_resp, size);
efree(bulk_resp);
return 0;
Expand Down Expand Up @@ -2126,9 +2127,9 @@ redis_read_multibulk_recursive(RedisSock *redis_sock, int elements, zval *z_ret
break;
}

/* Decrement our element counter */
elements--;
}
/* Decrement our element counter */
elements--;
}

return 0;
}
Expand All @@ -2152,21 +2153,21 @@ redis_read_variant_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
#if (PHP_MAJOR_VERSION < 7)
MAKE_STD_ZVAL(z_ret);
#endif
/* Switch based on our top level reply type */
switch(reply_type) {
case TYPE_ERR:
case TYPE_LINE:
redis_read_variant_line(redis_sock, reply_type, z_ret TSRMLS_CC);
break;
case TYPE_INT:
ZVAL_LONG(z_ret, reply_info);
break;
case TYPE_BULK:
redis_read_variant_bulk(redis_sock, reply_info, z_ret TSRMLS_CC);
break;
case TYPE_MULTIBULK:
/* Initialize an array for our multi-bulk response */
array_init(z_ret);
/* Switch based on our top level reply type */
switch(reply_type) {
case TYPE_ERR:
case TYPE_LINE:
redis_read_variant_line(redis_sock, reply_type, z_ret TSRMLS_CC);
break;
case TYPE_INT:
ZVAL_LONG(z_ret, reply_info);
break;
case TYPE_BULK:
redis_read_variant_bulk(redis_sock, reply_info, z_ret TSRMLS_CC);
break;
case TYPE_MULTIBULK:
/* Initialize an array for our multi-bulk response */
array_init(z_ret);

// If we've got more than zero elements, parse our multi bulk
// response recursively
Expand All @@ -2185,15 +2186,15 @@ redis_read_variant_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
return FAILURE;
}

IF_NOT_ATOMIC() {
add_next_index_zval(z_tab, z_ret);
} else {
/* Set our return value */
IF_NOT_ATOMIC() {
add_next_index_zval(z_tab, z_ret);
} else {
/* Set our return value */
RETVAL_ZVAL(z_ret, 0, 1);
}
}

/* Success */
return 0;
/* Success */
return 0;
}

/* vim: set tabstop=4 softtabstop=4 expandtab shiftwidth=4: */
58 changes: 29 additions & 29 deletions redis.c
Original file line number Diff line number Diff line change
Expand Up @@ -2895,7 +2895,7 @@ PHP_METHOD(Redis, evalsha) {

PHP_REDIS_API int
redis_build_script_exists_cmd(char **ret, zval *argv, int argc) {
smart_string cmd = {0};
smart_string cmd = {0};
zend_string *zstr;
int i;

Expand All @@ -2909,9 +2909,9 @@ redis_build_script_exists_cmd(char **ret, zval *argv, int argc) {
zend_string_release(zstr);
}

/* Success */
/* Success */
*ret = cmd.c;
return cmd.len;
return cmd.len;
}

/* {{{ proto status Redis::script('flush')
Expand All @@ -2925,24 +2925,24 @@ PHP_METHOD(Redis, script) {
int cmd_len, argc;
char *cmd;

/* Attempt to grab our socket */
/* Attempt to grab our socket */
if ((redis_sock = redis_sock_get(getThis() TSRMLS_CC, 0)) == NULL) {
RETURN_FALSE;
}
RETURN_FALSE;
}

/* Grab the number of arguments */
argc = ZEND_NUM_ARGS();
/* Grab the number of arguments */
argc = ZEND_NUM_ARGS();

/* Allocate an array big enough to store our arguments */
z_args = emalloc(argc * sizeof(zval));
/* Allocate an array big enough to store our arguments */
z_args = emalloc(argc * sizeof(zval));

/* Make sure we can grab our arguments, we have a string directive */
if (zend_get_parameters_array(ht, argc, z_args) == FAILURE ||
(argc < 1 || Z_TYPE(z_args[0]) != IS_STRING))
{
efree(z_args);
RETURN_FALSE;
}
/* Make sure we can grab our arguments, we have a string directive */
if (zend_get_parameters_array(ht, argc, z_args) == FAILURE ||
(argc < 1 || Z_TYPE(z_args[0]) != IS_STRING))
{
efree(z_args);
RETURN_FALSE;
}

// Branch based on the directive
if(!strcasecmp(Z_STRVAL(z_args[0]), "flush") ||
Expand All @@ -2964,17 +2964,17 @@ PHP_METHOD(Redis, script) {
// Format our SCRIPT LOAD command
cmd_len = REDIS_SPPRINTF(&cmd, "SCRIPT", "ss", "LOAD", 4, Z_STRVAL(z_args[1]),
Z_STRLEN(z_args[1]));
} else if(!strcasecmp(Z_STRVAL(z_args[0]), "exists")) {
/* Construct our SCRIPT EXISTS command */
cmd_len = redis_build_script_exists_cmd(&cmd, &(z_args[1]), argc-1);
} else {
/* Unknown directive */
efree(z_args);
RETURN_FALSE;
}

/* Free our alocated arguments */
efree(z_args);
} else if(!strcasecmp(Z_STRVAL(z_args[0]), "exists")) {
/* Construct our SCRIPT EXISTS command */
cmd_len = redis_build_script_exists_cmd(&cmd, &(z_args[1]), argc-1);
} else {
/* Unknown directive */
efree(z_args);
RETURN_FALSE;
}

/* Free our alocated arguments */
efree(z_args);

// Kick off our request
REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len);
Expand Down Expand Up @@ -3066,7 +3066,7 @@ PHP_METHOD(Redis, getLastError) {
RETURN_FALSE;
}

/* Return our last error or NULL if we don't have one */
/* Return our last error or NULL if we don't have one */
if (redis_sock->err) {
RETURN_STRINGL(ZSTR_VAL(redis_sock->err), ZSTR_LEN(redis_sock->err));
}
Expand Down
Loading

0 comments on commit 345fc7f

Please sign in to comment.