Build fix for win32 (phpredis 2.1.3)

This commit is contained in:
Charles
2011-06-30 21:17:23 +07:00
parent 73d99c3ec8
commit c9a6ce2cf4
9 changed files with 248 additions and 178 deletions

View File

@@ -52,21 +52,23 @@
#define MULTI_RESPONSE(callback) IF_MULTI_OR_PIPELINE() { \
fold_item *f1 = malloc(sizeof(fold_item)); \
fold_item *f1, *current; \
f1 = malloc(sizeof(fold_item)); \
f1->fun = (void *)callback; \
f1->next = NULL; \
fold_item *current = redis_sock->current;\
current = redis_sock->current;\
if(current) current->next = f1; \
redis_sock->current = f1; \
}
#define PIPELINE_ENQUEUE_COMMAND(cmd, cmd_len) request_item *tmp; \
struct request_item *current_request;\
tmp = malloc(sizeof(request_item));\
tmp->request_str = calloc(cmd_len, 1);\
memcpy(tmp->request_str, cmd, cmd_len);\
tmp->request_size = cmd_len;\
tmp->next = NULL;\
struct request_item *current_request = redis_sock->pipeline_current; \
current_request = redis_sock->pipeline_current; \
if(current_request) {\
current_request->next = tmp;\
} \
@@ -81,11 +83,12 @@
}
#define REDIS_SAVE_CALLBACK(callback, closure_context) IF_MULTI_OR_PIPELINE() { \
fold_item *f1 = malloc(sizeof(fold_item)); \
fold_item *f1, *current; \
f1 = malloc(sizeof(fold_item)); \
f1->fun = (void *)callback; \
f1->ctx = closure_context; \
f1->next = NULL; \
fold_item *current = redis_sock->current;\
current = redis_sock->current;\
if(current) current->next = f1; \
redis_sock->current = f1; \
if(NULL == redis_sock->head) { \

15
config.w32 Normal file
View File

@@ -0,0 +1,15 @@
// vim: ft=javascript:
ARG_ENABLE("redis", "whether to enable redis support", "yes");
ARG_ENABLE("redis-session", "whether to enable sessions", "yes");
if (PHP_REDIS != "no") {
var sources = "redis.c library.c igbinary\\igbinary.c igbinary\\hash_si.c igbinary\\hash_function.c";
if (PHP_REDIS_SESSION != "no") {
AC_DEFINE('PHP_SESSION', 1);
sources += " redis_session.c";
}
AC_DEFINE("PHP_EXPORTS", 1);
EXTENSION("redis", sources);
}

View File

@@ -3,7 +3,10 @@
lookup3.c, by Bob Jenkins, May 2006, Public Domain.
*/
#ifndef _MSC_VER
#include <sys/param.h> /* attempt to define endianness */
#endif
#ifdef linux
# include <endian.h> /* attempt to define endianness */
#endif

View File

@@ -13,12 +13,18 @@
#include "hash.h"
#include "hash_function.h"
#ifdef _MSC_VER
#define INLINE __forceinline /* use __forceinline (VC++ specific) */
#else
#define INLINE inline /* use standard inline */
#endif
/* {{{ nextpow2 */
/** Next power of 2.
* @param n Integer.
* @return next to n power of 2 .
*/
inline static uint32_t nextpow2(uint32_t n) {
INLINE static uint32_t nextpow2(uint32_t n) {
uint32_t m = 1;
while (m < n) {
m = m << 1;
@@ -66,7 +72,7 @@ void hash_si_deinit(struct hash_si *h) {
* @param key_len Key length.
* @return index.
*/
inline static size_t _hash_si_find(struct hash_si *h, const char *key, size_t key_len) {
INLINE static size_t _hash_si_find(struct hash_si *h, const char *key, size_t key_len) {
uint32_t hv;
size_t size;
@@ -155,7 +161,7 @@ int hash_si_remove(struct hash_si *h, const char *key, size_t key_len, uint32_t
/** Rehash/resize hash_si.
* @param h Pointer to hash_si struct.
*/
inline static void hash_si_rehash(struct hash_si *h) {
INLINE static void hash_si_rehash(struct hash_si *h) {
uint32_t hv;
int i;
struct hash_si newh;

View File

@@ -294,13 +294,13 @@ int igbinary_unserialize(const uint8_t *buf, size_t buf_len, zval **z TSRMLS_DC)
/* }}} */
/* {{{ proto string igbinary_unserialize(mixed value) */
PHP_FUNCTION(igbinary_unserialize) {
char *string;
int string_len;
(void) return_value_ptr;
(void) this_ptr;
(void) return_value_used;
char *string;
int string_len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &string, &string_len) == FAILURE) {
RETURN_NULL();
}
@@ -316,13 +316,13 @@ PHP_FUNCTION(igbinary_unserialize) {
/* }}} */
/* {{{ proto mixed igbinary_serialize(string value) */
PHP_FUNCTION(igbinary_serialize) {
zval *z;
struct igbinary_serialize_data igsd;
(void) return_value_ptr;
(void) this_ptr;
(void) return_value_used;
zval *z;
struct igbinary_serialize_data igsd;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &z) == FAILURE) {
RETURN_NULL();
}
@@ -608,13 +608,14 @@ inline static int igbinary_serialize_long(struct igbinary_serialize_data *igsd,
/* }}} */
/* {{{ igbinary_serialize_double */
/** Serializes double. */
inline static int igbinary_serialize_double(struct igbinary_serialize_data *igsd, double d TSRMLS_DC) {
igbinary_serialize8(igsd, igbinary_type_double TSRMLS_CC);
inline static int igbinary_serialize_double(struct igbinary_serialize_data *igsd, double d TSRMLS_DC)
{
union {
double d;
uint64_t u;
} u;
igbinary_serialize8(igsd, igbinary_type_double TSRMLS_CC);
u.d = d;
@@ -1295,6 +1296,11 @@ inline static int igbinary_unserialize_long(struct igbinary_unserialize_data *ig
/* {{{ igbinary_unserialize_double */
/** Unserializes double. */
inline static int igbinary_unserialize_double(struct igbinary_unserialize_data *igsd, enum igbinary_type t, double *ret TSRMLS_DC) {
union {
double d;
uint64_t u;
} u;
(void) t;
if (igsd->buffer_offset + 8 > igsd->buffer_size) {
@@ -1302,11 +1308,6 @@ inline static int igbinary_unserialize_double(struct igbinary_unserialize_data *
return 1;
}
union {
double d;
uint64_t u;
} u;
u.u = igbinary_unserialize64(igsd TSRMLS_CC);
*ret = u.d;

View File

@@ -13,6 +13,10 @@
#define IGBINARY_VERSION "1.0.2"
#ifdef _MSC_VER
#define __func__ __FUNCTION__
#endif
/** Serialize zval.
* Return buffer is allocated by this function with emalloc.
* @param[out] ret Return buffer

View File

@@ -1,8 +1,10 @@
#include "common.h"
#include "php_network.h"
#include <sys/types.h>
#ifndef _MSC_VER
#include <netinet/tcp.h> /* TCP_NODELAY */
#include <sys/socket.h>
#endif
#include <ext/standard/php_smart_str.h>
#include <ext/standard/php_var.h>
@@ -55,6 +57,8 @@ PHPAPI int redis_check_eof(RedisSock *redis_sock TSRMLS_DC)
PHPAPI zval *redis_sock_read_multibulk_reply_zval(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock) {
char inbuf[1024];
int numElems;
zval *z_tab;
if(-1 == redis_check_eof(redis_sock TSRMLS_CC)) {
return NULL;
@@ -72,9 +76,8 @@ PHPAPI zval *redis_sock_read_multibulk_reply_zval(INTERNAL_FUNCTION_PARAMETERS,
if(inbuf[0] != '*') {
return NULL;
}
int numElems = atoi(inbuf+1);
numElems = atoi(inbuf+1);
zval *z_tab;
MAKE_STD_ZVAL(z_tab);
array_init(z_tab);
@@ -100,14 +103,15 @@ PHPAPI char *redis_sock_read_bulk_reply(RedisSock *redis_sock, int bytes TSRMLS_
if (bytes == -1) {
return NULL;
} else {
reply = emalloc(bytes+1);
char c;
int i;
reply = emalloc(bytes+1);
while(offset < bytes) {
got = php_stream_read(redis_sock->stream, reply + offset, bytes-offset);
offset += got;
}
char c;
int i;
for(i = 0; i < 2; i++) {
php_stream_read(redis_sock->stream, &c, 1);
}
@@ -122,7 +126,6 @@ PHPAPI char *redis_sock_read_bulk_reply(RedisSock *redis_sock, int bytes TSRMLS_
*/
PHPAPI char *redis_sock_read(RedisSock *redis_sock, int *buf_len TSRMLS_DC)
{
char inbuf[1024];
char *resp = NULL;
@@ -140,7 +143,6 @@ PHPAPI char *redis_sock_read(RedisSock *redis_sock, int *buf_len TSRMLS_DC)
}
switch(inbuf[0]) {
case '-':
return NULL;
@@ -174,7 +176,6 @@ PHPAPI char *redis_sock_read(RedisSock *redis_sock, int *buf_len TSRMLS_DC)
}
void add_constant_long(zend_class_entry *ce, char *name, int value) {
zval *constval;
constval = pemalloc(sizeof(zval), 1);
INIT_PZVAL(constval);
@@ -324,12 +325,13 @@ PHPAPI void redis_bulk_double_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *
char *response;
int response_len;
double ret;
if ((response = redis_sock_read(redis_sock, &response_len TSRMLS_CC)) == NULL) {
RETURN_FALSE;
}
double ret = atof(response);
ret = atof(response);
efree(response);
IF_MULTI_OR_PIPELINE() {
add_next_index_double(z_tab, ret);
@@ -341,12 +343,12 @@ PHPAPI void redis_bulk_double_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *
PHPAPI void redis_type_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx) {
char *response;
int response_len;
long l;
if ((response = redis_sock_read(redis_sock, &response_len TSRMLS_CC)) == NULL) {
RETURN_FALSE;
}
long l;
if (strncmp(response, "+string", 7) == 0) {
l = REDIS_STRING;
} else if (strncmp(response, "+set", 4) == 0){
@@ -372,22 +374,23 @@ PHPAPI void redis_type_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_s
PHPAPI void redis_info_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx) {
char *response;
int response_len;
char *pos, *cur;
char *key, *value, *p;
int is_numeric;
zval *z_multi_result;
if ((response = redis_sock_read(redis_sock, &response_len TSRMLS_CC)) == NULL) {
RETURN_FALSE;
}
zval *z_multi_result;
MAKE_STD_ZVAL(z_multi_result);
array_init(z_multi_result); /* pre-allocate array for multi's results. */
/* response :: [response_line]
* response_line :: key ':' value CRLF
*/
char *pos, *cur = response;
cur = response;
while(1) {
char *key, *value, *p;
int is_numeric;
/* key */
pos = strchr(cur, ':');
if(pos == NULL) {
@@ -482,16 +485,16 @@ PHPAPI void redis_long_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_s
}
if(response[0] == ':') {
long long ret = atoll(response + 1);
long ret = atol(response + 1);
IF_MULTI_OR_PIPELINE() {
if(ret > (long long)LONG_MAX) { /* overflow */
if(ret > (long)LONG_MAX) { /* overflow */
add_next_index_stringl(z_tab, response+1, response_len-1, 1);
} else {
efree(response);
add_next_index_long(z_tab, (long)ret);
}
} else {
if(ret > (long long)LONG_MAX) { /* overflow */
if(ret > (long)LONG_MAX) { /* overflow */
RETURN_STRINGL(response+1, response_len-1, 1);
} else {
efree(response);
@@ -516,6 +519,8 @@ PHPAPI int redis_sock_read_multibulk_reply_zipped_with_flag(INTERNAL_FUNCTION_PA
*/
char inbuf[1024];
int numElems;
zval *z_multi_result;
if(-1 == redis_check_eof(redis_sock TSRMLS_CC)) {
return -1;
@@ -533,8 +538,7 @@ PHPAPI int redis_sock_read_multibulk_reply_zipped_with_flag(INTERNAL_FUNCTION_PA
if(inbuf[0] != '*') {
return -1;
}
int numElems = atoi(inbuf+1);
zval *z_multi_result;
numElems = atoi(inbuf+1);
MAKE_STD_ZVAL(z_multi_result);
array_init(z_multi_result); /* pre-allocate array for multi's results. */
@@ -693,6 +697,8 @@ PHPAPI int redis_sock_connect(RedisSock *redis_sock TSRMLS_DC)
struct timeval tv, *tv_ptr = NULL;
char *host = NULL, *persistent_id = NULL, *errstr = NULL;
int host_len, err = 0;
php_netstream_data_t *sock;
int tcp_flag = 1;
if (redis_sock->stream != NULL) {
redis_sock_disconnect(redis_sock TSRMLS_CC);
@@ -736,8 +742,7 @@ PHPAPI int redis_sock_connect(RedisSock *redis_sock TSRMLS_DC)
}
/* set TCP_NODELAY */
php_netstream_data_t *sock = (php_netstream_data_t*)redis_sock->stream->abstract;
int tcp_flag = 1;
sock = (php_netstream_data_t*)redis_sock->stream->abstract;
setsockopt(sock->socket, IPPROTO_TCP, TCP_NODELAY, (char *) &tcp_flag, sizeof(int));
php_stream_auto_cleanup(redis_sock->stream);
@@ -814,6 +819,8 @@ PHPAPI int redis_sock_disconnect(RedisSock *redis_sock TSRMLS_DC)
PHPAPI int redis_sock_read_multibulk_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx)
{
char inbuf[1024];
int numElems;
zval *z_multi_result;
if(-1 == redis_check_eof(redis_sock TSRMLS_CC)) {
return -1;
@@ -830,8 +837,7 @@ PHPAPI int redis_sock_read_multibulk_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSo
if(inbuf[0] != '*') {
return -1;
}
int numElems = atoi(inbuf+1);
zval *z_multi_result;
numElems = atoi(inbuf+1);
MAKE_STD_ZVAL(z_multi_result);
array_init(z_multi_result); /* pre-allocate array for multi's results. */
@@ -854,6 +860,8 @@ PHPAPI int redis_sock_read_multibulk_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSo
PHPAPI int redis_sock_read_multibulk_reply_raw(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx)
{
char inbuf[1024];
int numElems;
zval *z_multi_result;
if(-1 == redis_check_eof(redis_sock TSRMLS_CC)) {
return -1;
@@ -870,8 +878,7 @@ PHPAPI int redis_sock_read_multibulk_reply_raw(INTERNAL_FUNCTION_PARAMETERS, Red
if(inbuf[0] != '*') {
return -1;
}
int numElems = atoi(inbuf+1);
zval *z_multi_result;
numElems = atoi(inbuf+1);
MAKE_STD_ZVAL(z_multi_result);
array_init(z_multi_result); /* pre-allocate array for multi's results. */
@@ -920,6 +927,8 @@ PHPAPI int redis_sock_read_multibulk_reply_assoc(INTERNAL_FUNCTION_PARAMETERS, R
{
char inbuf[1024], *response;
int response_len;
int i, numElems;
zval *z_multi_result;
zval **z_keys = ctx;
@@ -938,8 +947,7 @@ PHPAPI int redis_sock_read_multibulk_reply_assoc(INTERNAL_FUNCTION_PARAMETERS, R
if(inbuf[0] != '*') {
return -1;
}
int i, numElems = atoi(inbuf+1);
zval *z_multi_result;
numElems = atoi(inbuf+1);
MAKE_STD_ZVAL(z_multi_result);
array_init(z_multi_result); /* pre-allocate array for multi's results. */
@@ -1112,12 +1120,15 @@ redis_unserialize(RedisSock *redis_sock, const char *val, int val_len, zval **re
PHPAPI int
redis_key_prefix(RedisSock *redis_sock, char **key, int *key_len TSRMLS_DC) {
int ret_len;
char *ret;
if(redis_sock->prefix == NULL || redis_sock->prefix_len == 0) {
return 0;
}
int ret_len = redis_sock->prefix_len + *key_len;
char *ret = ecalloc(1 + ret_len, 1);
ret_len = redis_sock->prefix_len + *key_len;
ret = ecalloc(1 + ret_len, 1);
memcpy(ret, redis_sock->prefix, redis_sock->prefix_len);
memcpy(ret + redis_sock->prefix_len, *key, *key_len);

View File

@@ -190,9 +190,10 @@ PHPAPI void set_pipeline_head(zval *object, request_item *head);
PHPAPI request_item* get_pipeline_current(zval *object);
PHPAPI void set_pipeline_current(zval *object, request_item *current);
#ifndef _MSC_VER
ZEND_BEGIN_MODULE_GLOBALS(redis)
ZEND_END_MODULE_GLOBALS(redis)
#endif
struct redis_queued_item {

278
redis.c
View File

@@ -296,10 +296,11 @@ PHPAPI int redis_sock_get(zval *id, RedisSock **redis_sock TSRMLS_DC)
PHP_MINIT_FUNCTION(redis)
{
zend_class_entry redis_class_entry;
INIT_CLASS_ENTRY(redis_class_entry, "Redis", redis_functions);
zend_class_entry redis_exception_class_entry;
INIT_CLASS_ENTRY(redis_class_entry, "Redis", redis_functions);
redis_ce = zend_register_internal_class(&redis_class_entry TSRMLS_CC);
zend_class_entry redis_exception_class_entry;
INIT_CLASS_ENTRY(redis_exception_class_entry, "RedisException", NULL);
redis_exception_ce = zend_register_internal_class_ex(
&redis_exception_class_entry,
@@ -422,15 +423,15 @@ PHPAPI int redis_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) {
char *persistent_id = NULL;
int persistent_id_len = -1;
double timeout = 0.0;
RedisSock *redis_sock = NULL;
#ifdef ZTS
/* not sure how in threaded mode this works so disabled persistents at first */
persistent = 0;
#endif
double timeout = 0.0;
RedisSock *redis_sock = NULL;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os|lds",
&object, redis_ce, &host, &host_len, &port,
&timeout, &persistent_id, &persistent_id_len) == FAILURE) {
@@ -688,6 +689,7 @@ PHP_METHOD(Redis, renameKey)
RedisSock *redis_sock;
char *cmd, *src, *dst;
int cmd_len, src_len, dst_len;
int src_free, dst_free;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oss",
&object, redis_ce,
@@ -700,8 +702,8 @@ PHP_METHOD(Redis, renameKey)
RETURN_FALSE;
}
int src_free = redis_key_prefix(redis_sock, &src, &src_len TSRMLS_CC);
int dst_free = redis_key_prefix(redis_sock, &dst, &dst_len TSRMLS_CC);
src_free = redis_key_prefix(redis_sock, &src, &src_len TSRMLS_CC);
dst_free = redis_key_prefix(redis_sock, &dst, &dst_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, "RENAME", "ss", src, src_len, dst, dst_len);
if(src_free) efree(src);
if(dst_free) efree(dst);
@@ -724,6 +726,7 @@ PHP_METHOD(Redis, renameNx)
RedisSock *redis_sock;
char *cmd, *src, *dst;
int cmd_len, src_len, dst_len;
int src_free, dst_free;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oss",
&object, redis_ce,
@@ -736,8 +739,8 @@ PHP_METHOD(Redis, renameNx)
RETURN_FALSE;
}
int src_free = redis_key_prefix(redis_sock, &src, &src_len TSRMLS_CC);
int dst_free = redis_key_prefix(redis_sock, &dst, &dst_len TSRMLS_CC);
src_free = redis_key_prefix(redis_sock, &src, &src_len TSRMLS_CC);
dst_free = redis_key_prefix(redis_sock, &dst, &dst_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, "RENAMENX", "ss", src, src_len, dst, dst_len);
if(src_free) efree(src);
if(dst_free) efree(dst);
@@ -759,6 +762,7 @@ PHP_METHOD(Redis, get)
RedisSock *redis_sock;
char *key = NULL, *cmd;
int key_len, cmd_len;
int key_free;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os",
&object, redis_ce,
@@ -770,7 +774,7 @@ PHP_METHOD(Redis, get)
RETURN_FALSE;
}
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, "GET", "s", key, key_len);
if(key_free) efree(key);
@@ -824,6 +828,7 @@ PHPAPI void redis_atomic_increment(INTERNAL_FUNCTION_PARAMETERS, char *keyword,
char *key = NULL, *cmd;
int key_len, cmd_len;
long val = 1;
int key_free;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os|l",
&object, redis_ce,
@@ -834,7 +839,7 @@ PHPAPI void redis_atomic_increment(INTERNAL_FUNCTION_PARAMETERS, char *keyword,
if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
RETURN_FALSE;
}
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
if (val == 1) {
cmd_len = redis_cmd_format_static(&cmd, keyword, "s", key, key_len);
} else {
@@ -976,6 +981,8 @@ PHP_METHOD(Redis, getMultiple)
char *key;
int key_len;
zval *z_tmp = NULL;
char *old_cmd;
int key_free;
if (Z_TYPE_PP(data) == IS_STRING) {
key = Z_STRVAL_PP(data);
@@ -989,11 +996,11 @@ PHP_METHOD(Redis, getMultiple)
key = Z_STRVAL_P(z_tmp);
key_len = Z_STRLEN_P(z_tmp);
}
char *old_cmd = NULL;
old_cmd = NULL;
if(*cmd) {
old_cmd = cmd;
}
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format(&cmd, "%s$%d" _NL "%s" _NL
, cmd, cmd_len
, key_len, key, key_len);
@@ -1034,6 +1041,7 @@ PHP_METHOD(Redis, exists)
RedisSock *redis_sock;
char *key = NULL, *cmd;
int key_len, cmd_len;
int key_free;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os",
&object, redis_ce,
@@ -1044,7 +1052,7 @@ PHP_METHOD(Redis, exists)
RETURN_FALSE;
}
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, "EXISTS", "s", key, key_len);
if(key_free) efree(key);
@@ -1108,7 +1116,7 @@ PHP_METHOD(Redis, getKeys)
zval *object;
RedisSock *redis_sock;
char *pattern = NULL, *cmd;
int pattern_len, cmd_len;
int pattern_len, cmd_len, pattern_free;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os",
&object, redis_ce,
@@ -1120,7 +1128,7 @@ PHP_METHOD(Redis, getKeys)
RETURN_FALSE;
}
int pattern_free = redis_key_prefix(redis_sock, &pattern, &pattern_len TSRMLS_CC);
pattern_free = redis_key_prefix(redis_sock, &pattern, &pattern_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, "KEYS", "s", pattern, pattern_len);
if(pattern_free) efree(pattern);
@@ -1142,7 +1150,7 @@ PHP_METHOD(Redis, type)
zval *object;
RedisSock *redis_sock;
char *key = NULL, *cmd;
int key_len, cmd_len;
int key_len, cmd_len, key_free;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os",
&object, redis_ce,
@@ -1154,7 +1162,7 @@ PHP_METHOD(Redis, type)
RETURN_FALSE;
}
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, "TYPE", "s", key, key_len);
if(key_free) efree(key);
@@ -1171,7 +1179,7 @@ PHP_METHOD(Redis, append)
zval *object;
RedisSock *redis_sock;
char *cmd;
int cmd_len, key_len, val_len;
int cmd_len, key_len, val_len, key_free;
char *key, *val;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oss",
@@ -1184,7 +1192,7 @@ PHP_METHOD(Redis, append)
RETURN_FALSE;
}
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, "APPEND", "ss", key, key_len, val, val_len);
if(key_free) efree(key);
@@ -1200,7 +1208,7 @@ PHP_METHOD(Redis, getRange)
zval *object;
RedisSock *redis_sock;
char *key = NULL, *cmd;
int key_len, cmd_len;
int key_len, cmd_len, key_free;
long start, end;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Osll",
@@ -1213,7 +1221,7 @@ PHP_METHOD(Redis, getRange)
RETURN_FALSE;
}
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, "GETRANGE", "sdd", key, key_len, (int)start, (int)end);
if(key_free) efree(key);
REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len);
@@ -1228,7 +1236,7 @@ PHP_METHOD(Redis, setRange)
zval *object;
RedisSock *redis_sock;
char *key = NULL, *val, *cmd;
int key_len, val_len, cmd_len;
int key_len, val_len, cmd_len, key_free;
long offset;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Osls",
@@ -1241,7 +1249,7 @@ PHP_METHOD(Redis, setRange)
RETURN_FALSE;
}
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, "SETRANGE", "sds", key, key_len, (int)offset, val, val_len);
if(key_free) efree(key);
REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len);
@@ -1256,7 +1264,7 @@ PHP_METHOD(Redis, getBit)
zval *object;
RedisSock *redis_sock;
char *key = NULL, *cmd;
int key_len, cmd_len;
int key_len, cmd_len, key_free;
long offset;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Osl",
@@ -1269,7 +1277,7 @@ PHP_METHOD(Redis, getBit)
RETURN_FALSE;
}
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, "GETBIT", "sd", key, key_len, (int)offset);
if(key_free) efree(key);
REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len);
@@ -1284,7 +1292,7 @@ PHP_METHOD(Redis, setBit)
zval *object;
RedisSock *redis_sock;
char *key = NULL, *cmd;
int key_len, cmd_len;
int key_len, cmd_len, key_free;
long offset;
zend_bool val;
@@ -1298,7 +1306,7 @@ PHP_METHOD(Redis, setBit)
RETURN_FALSE;
}
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, "SETBIT", "sdd", key, key_len, (int)offset, (int)val);
if(key_free) efree(key);
REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len);
@@ -1314,7 +1322,7 @@ PHP_METHOD(Redis, strlen)
zval *object;
RedisSock *redis_sock;
char *cmd;
int cmd_len, key_len;
int cmd_len, key_len, key_free;
char *key;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os",
@@ -1327,7 +1335,7 @@ PHP_METHOD(Redis, strlen)
RETURN_FALSE;
}
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, "STRLEN", "s", key, key_len);
if(key_free) efree(key);
@@ -1447,7 +1455,7 @@ generic_pop_function(INTERNAL_FUNCTION_PARAMETERS, char *keyword, int keyword_le
zval *object;
RedisSock *redis_sock;
char *key = NULL, *cmd;
int key_len, cmd_len;
int key_len, cmd_len, key_free;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os",
&object, redis_ce,
@@ -1459,7 +1467,7 @@ generic_pop_function(INTERNAL_FUNCTION_PARAMETERS, char *keyword, int keyword_le
RETURN_FALSE;
}
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, keyword, "s", key, key_len);
if(key_free) efree(key);
@@ -1535,7 +1543,7 @@ PHP_METHOD(Redis, lSize)
zval *object;
RedisSock *redis_sock;
char *key = NULL, *cmd;
int key_len, cmd_len;
int key_len, cmd_len, key_free;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os",
&object, redis_ce,
@@ -1547,7 +1555,7 @@ PHP_METHOD(Redis, lSize)
RETURN_FALSE;
}
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, "LLEN", "s", key, key_len);
if(key_free) efree(key);
@@ -1606,7 +1614,7 @@ PHP_METHOD(Redis, listTrim)
zval *object;
RedisSock *redis_sock;
char *key = NULL, *cmd;
int key_len, cmd_len;
int key_len, cmd_len, key_free;
long start, end;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Osll",
@@ -1619,7 +1627,7 @@ PHP_METHOD(Redis, listTrim)
RETURN_FALSE;
}
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, "LTRIM", "sdd", key, key_len, (int)start, (int)end);
if(key_free) efree(key);
@@ -1639,7 +1647,7 @@ PHP_METHOD(Redis, lGet)
zval *object;
RedisSock *redis_sock;
char *key = NULL, *cmd;
int key_len, cmd_len;
int key_len, cmd_len, key_free;
long index;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Osl",
@@ -1653,7 +1661,7 @@ PHP_METHOD(Redis, lGet)
}
/* LINDEX key pos */
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, "LINDEX", "sd", key, key_len, (int)index);
if(key_free) efree(key);
@@ -1672,7 +1680,7 @@ PHP_METHOD(Redis, lGetRange)
zval *object;
RedisSock *redis_sock;
char *key = NULL, *cmd;
int key_len, cmd_len;
int key_len, cmd_len, key_free;
long start, end;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Osll",
@@ -1686,7 +1694,7 @@ PHP_METHOD(Redis, lGetRange)
}
/* LRANGE key start end */
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, "LRANGE", "sdd", key, key_len, (int)start, (int)end);
if(key_free) efree(key);
@@ -1741,7 +1749,7 @@ PHP_METHOD(Redis, sSize)
zval *object;
RedisSock *redis_sock;
char *key = NULL, *cmd;
int key_len, cmd_len;
int key_len, cmd_len, key_free;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os",
&object, redis_ce,
@@ -1753,7 +1761,7 @@ PHP_METHOD(Redis, sSize)
RETURN_FALSE;
}
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, "SCARD", "s", key, key_len);
if(key_free) efree(key);
@@ -1898,7 +1906,7 @@ PHP_METHOD(Redis, sMembers)
zval *object;
RedisSock *redis_sock;
char *key = NULL, *cmd;
int key_len, cmd_len;
int key_len, cmd_len, key_free;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os",
&object, redis_ce,
@@ -1910,7 +1918,7 @@ PHP_METHOD(Redis, sMembers)
RETURN_FALSE;
}
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, "SMEMBERS", "s", key, key_len);
if(key_free) efree(key);
@@ -1935,6 +1943,7 @@ PHPAPI int generic_multiple_args_cmd(INTERNAL_FUNCTION_PARAMETERS, char *keyword
int i, j, argc = ZEND_NUM_ARGS(), real_argc = 0;
int single_array = 0;
int timeout;
int pos;
RedisSock *redis_sock;
@@ -2062,9 +2071,9 @@ PHPAPI int generic_multiple_args_cmd(INTERNAL_FUNCTION_PARAMETERS, char *keyword
sprintf(cmd, "*%d" _NL "$%d" _NL "%s" _NL, 1+real_argc, keyword_len, keyword);
int pos = 1 +integer_length(real_argc + 1) + 2
+ 1 + integer_length(keyword_len) + 2
+ keyword_len + 2;
pos = 1 +integer_length(real_argc + 1) + 2
+ 1 + integer_length(keyword_len) + 2
+ keyword_len + 2;
/* copy each key to its destination */
for(i = 0; i < real_argc; ++i) {
@@ -2426,6 +2435,9 @@ PHPAPI void generic_sort_cmd(INTERNAL_FUNCTION_PARAMETERS, char *sort, int use_a
char *cmd_lines[30];
int cmd_sizes[30];
int sort_len;
int i, pos;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os|sslls",
&object, redis_ce,
&key, &key_len, &pattern, &pattern_len,
@@ -2513,7 +2525,7 @@ PHPAPI void generic_sort_cmd(INTERNAL_FUNCTION_PARAMETERS, char *sort, int use_a
}
/* add ASC or DESC */
int sort_len = strlen(sort);
sort_len = strlen(sort);
cmd_sizes[cmd_elements] = redis_cmd_format(&cmd_lines[cmd_elements], "$%d", sort_len);
cmd_elements++;
cmd_lines[cmd_elements] = emalloc(sort_len + 1);
@@ -2555,14 +2567,13 @@ PHPAPI void generic_sort_cmd(INTERNAL_FUNCTION_PARAMETERS, char *sort, int use_a
/* compute the command size */
cmd_len = 0;
int i;
for(i = 0; i < cmd_elements; ++i) {
cmd_len += cmd_sizes[i] + sizeof(_NL) - 1; /* each line followeb by _NL */
}
/* copy all lines into the final command. */
cmd = emalloc(1 + cmd_len);
int pos = 0;
pos = 0;
for(i = 0; i < cmd_elements; ++i) {
memcpy(cmd + pos, cmd_lines[i], cmd_sizes[i]);
pos += cmd_sizes[i];
@@ -2620,7 +2631,7 @@ PHPAPI void generic_expire_cmd(INTERNAL_FUNCTION_PARAMETERS, char *keyword, int
zval *object;
RedisSock *redis_sock;
char *key = NULL, *cmd;
int key_len, cmd_len;
int key_len, cmd_len, key_free;
long t;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Osl",
@@ -2633,7 +2644,7 @@ PHPAPI void generic_expire_cmd(INTERNAL_FUNCTION_PARAMETERS, char *keyword, int
RETURN_FALSE;
}
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, keyword, "sd", key, key_len, t);
if(key_free) efree(key);
@@ -2838,7 +2849,7 @@ PHP_METHOD(Redis, persist) {
RedisSock *redis_sock;
char *cmd, *key;
int cmd_len, key_len;
int cmd_len, key_len, key_free;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os",
&object, redis_ce, &key, &key_len) == FAILURE) {
@@ -2849,7 +2860,7 @@ PHP_METHOD(Redis, persist) {
RETURN_FALSE;
}
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, "PERSIST", "s", key, key_len);
if(key_free) efree(key);
@@ -2869,7 +2880,7 @@ PHP_METHOD(Redis, ttl) {
RedisSock *redis_sock;
char *cmd, *key;
int cmd_len, key_len;
int cmd_len, key_len, key_free;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os",
&object, redis_ce, &key, &key_len) == FAILURE) {
@@ -2880,7 +2891,7 @@ PHP_METHOD(Redis, ttl) {
RETURN_FALSE;
}
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, "TTL", "s", key, key_len);
if(key_free) efree(key);
@@ -2958,7 +2969,7 @@ PHP_METHOD(Redis, move) {
RedisSock *redis_sock;
char *cmd, *key;
int cmd_len, key_len;
int cmd_len, key_len, key_free;
long dbNumber;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Osl",
@@ -2970,7 +2981,7 @@ PHP_METHOD(Redis, move) {
RETURN_FALSE;
}
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, "MOVE", "sd", key, key_len, dbNumber);
if(key_free) efree(key);
@@ -2993,6 +3004,8 @@ generic_mset(INTERNAL_FUNCTION_PARAMETERS, char *kw, void (*fun)(INTERNAL_FUNCTI
int cmd_len;
zval *z_array;
HashTable *keytable;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oa",
&object, redis_ce, &z_array) == FAILURE) {
RETURN_FALSE;
@@ -3008,7 +3021,7 @@ generic_mset(INTERNAL_FUNCTION_PARAMETERS, char *kw, void (*fun)(INTERNAL_FUNCTI
cmd_len = redis_cmd_format(&cmd, kw, 1 + 2 * zend_hash_num_elements(Z_ARRVAL_P(z_array)));
HashTable *keytable = Z_ARRVAL_P(z_array);
keytable = Z_ARRVAL_P(z_array);
for(zend_hash_internal_pointer_reset(keytable);
zend_hash_has_more_elements(keytable) == SUCCESS;
zend_hash_move_forward(keytable)) {
@@ -3019,6 +3032,9 @@ generic_mset(INTERNAL_FUNCTION_PARAMETERS, char *kw, void (*fun)(INTERNAL_FUNCTI
unsigned long idx;
int type;
zval **z_value_pp;
int val_free, key_free;
char *old_cmd;
zval *z_copy;
type = zend_hash_get_current_key_ex(keytable, &key, &key_len, &idx, 0, NULL);
if(zend_hash_get_current_data(keytable, (void**)&z_value_pp) == FAILURE) {
@@ -3029,20 +3045,19 @@ generic_mset(INTERNAL_FUNCTION_PARAMETERS, char *kw, void (*fun)(INTERNAL_FUNCTI
continue;
}
zval *z_copy;
MAKE_STD_ZVAL(z_copy);
*z_copy = **z_value_pp;
zval_copy_ctor(z_copy);
int val_free = redis_serialize(redis_sock, *z_value_pp, &val, &val_len TSRMLS_CC);
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
val_free = redis_serialize(redis_sock, *z_value_pp, &val, &val_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
if(key_len > 0) {
key_len--;
}
char *old_cmd = cmd;
old_cmd = cmd;
cmd_len = redis_cmd_format(&cmd,
"%s"
"$%d" _NL /* key_len */
@@ -3199,7 +3214,7 @@ PHP_METHOD(Redis, zRange)
zval *object;
RedisSock *redis_sock;
char *key = NULL, *cmd;
int key_len, cmd_len;
int key_len, cmd_len, key_free;
long start, end;
long withscores = 0;
@@ -3213,7 +3228,7 @@ PHP_METHOD(Redis, zRange)
RETURN_FALSE;
}
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
if(withscores) {
cmd_len = redis_cmd_format_static(&cmd, "ZRANGE", "sdds", key, key_len, start, end, "WITHSCORES", 10);
} else {
@@ -3281,7 +3296,7 @@ PHP_METHOD(Redis, zDeleteRangeByScore)
zval *object;
RedisSock *redis_sock;
char *key = NULL, *cmd;
int key_len, cmd_len;
int key_len, cmd_len, key_free;
char *start, *end;
int start_len, end_len;
@@ -3295,7 +3310,7 @@ PHP_METHOD(Redis, zDeleteRangeByScore)
RETURN_FALSE;
}
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, "ZREMRANGEBYSCORE", "sss", key, key_len, start, start_len, end, end_len);
if(key_free) efree(key);
@@ -3315,7 +3330,7 @@ PHP_METHOD(Redis, zDeleteRangeByRank)
zval *object;
RedisSock *redis_sock;
char *key = NULL, *cmd;
int key_len, cmd_len;
int key_len, cmd_len, key_free;
long start, end;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Osll",
@@ -3328,7 +3343,7 @@ PHP_METHOD(Redis, zDeleteRangeByRank)
RETURN_FALSE;
}
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, "ZREMRANGEBYRANK", "sdd", key, key_len, (int)start, (int)end);
if(key_free) efree(key);
@@ -3348,7 +3363,7 @@ PHP_METHOD(Redis, zReverseRange)
zval *object;
RedisSock *redis_sock;
char *key = NULL, *cmd;
int key_len, cmd_len;
int key_len, cmd_len, key_free;
long start, end;
long withscores = 0;
@@ -3362,7 +3377,7 @@ PHP_METHOD(Redis, zReverseRange)
RETURN_FALSE;
}
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
if(withscores) {
cmd_len = redis_cmd_format_static(&cmd, "ZREVRANGE", "sdds", key, key_len, start, end, "WITHSCORES", 10);
} else {
@@ -3395,7 +3410,7 @@ redis_generic_zrange_by_score(INTERNAL_FUNCTION_PARAMETERS, char *keyword) {
RedisSock *redis_sock;
char *key = NULL, *cmd;
int key_len, cmd_len;
int key_len, cmd_len, key_free;
zend_bool withscores = 0;
char *start, *end;
int start_len, end_len;
@@ -3441,7 +3456,7 @@ redis_generic_zrange_by_score(INTERNAL_FUNCTION_PARAMETERS, char *keyword) {
}
}
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
if(withscores) {
if(has_limit) {
cmd_len = redis_cmd_format_static(&cmd, keyword, "ssssdds",
@@ -3505,7 +3520,7 @@ PHP_METHOD(Redis, zCount)
RedisSock *redis_sock;
char *key = NULL, *cmd;
int key_len, cmd_len;
int key_len, cmd_len, key_free;
char *start, *end;
int start_len, end_len;
@@ -3521,7 +3536,7 @@ PHP_METHOD(Redis, zCount)
RETURN_FALSE;
}
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, "ZCOUNT", "sss", key, key_len, start, start_len, end, end_len);
if(key_free) efree(key);
@@ -3540,7 +3555,7 @@ PHP_METHOD(Redis, zCard)
zval *object;
RedisSock *redis_sock;
char *key = NULL, *cmd;
int key_len, cmd_len;
int key_len, cmd_len, key_free;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os",
&object, redis_ce,
@@ -3552,7 +3567,7 @@ PHP_METHOD(Redis, zCard)
RETURN_FALSE;
}
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, "ZCARD", "s", key, key_len);
if(key_free) efree(key);
@@ -3700,7 +3715,9 @@ PHPAPI void generic_z_command(INTERNAL_FUNCTION_PARAMETERS, char *command, int c
HashPosition pointer;
char *cmd = "";
char *old_cmd;
int cmd_len, cmd_elements;
int free_key_output;
if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Osa|as",
&object, redis_ce,
@@ -3731,7 +3748,7 @@ PHPAPI void generic_z_command(INTERNAL_FUNCTION_PARAMETERS, char *command, int c
}
int free_key_output = redis_key_prefix(redis_sock, &key_output, &key_output_len TSRMLS_CC);
free_key_output = redis_key_prefix(redis_sock, &key_output, &key_output_len TSRMLS_CC);
cmd_elements = 3;
cmd_len = redis_cmd_format(&cmd,
"$%d" _NL /* command_len */
@@ -3756,13 +3773,17 @@ PHPAPI void generic_z_command(INTERNAL_FUNCTION_PARAMETERS, char *command, int c
if (Z_TYPE_PP(data) == IS_STRING) {
char *old_cmd = NULL;
if(*cmd) {
char *data_str;
int data_len;
int free_data;
if(*cmd) {
old_cmd = cmd;
}
char *data_str = Z_STRVAL_PP(data);
int data_len = Z_STRLEN_PP(data);
data_str = Z_STRVAL_PP(data);
data_len = Z_STRLEN_PP(data);
int free_data = redis_key_prefix(redis_sock, &data_str, &data_len TSRMLS_CC);
free_data = redis_key_prefix(redis_sock, &data_str, &data_len TSRMLS_CC);
cmd_len = redis_cmd_format(&cmd,
"%s" /* cmd */
"$%d" _NL
@@ -3829,7 +3850,7 @@ PHPAPI void generic_z_command(INTERNAL_FUNCTION_PARAMETERS, char *command, int c
efree(old_cmd);
}
char *old_cmd = cmd;
old_cmd = cmd;
cmd_len = redis_cmd_format(&cmd,
"*%d" _NL
"%s"
@@ -3908,7 +3929,7 @@ PHP_METHOD(Redis, hGet)
zval *object;
RedisSock *redis_sock;
char *key = NULL, *cmd, *member;
int key_len, member_len, cmd_len;
int key_len, member_len, cmd_len, key_free;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oss",
&object, redis_ce,
@@ -3919,7 +3940,7 @@ PHP_METHOD(Redis, hGet)
if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
RETURN_FALSE;
}
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, "HGET", "ss", key, key_len, member, member_len);
if(key_free) efree(key);
@@ -3938,7 +3959,7 @@ PHP_METHOD(Redis, hLen)
zval *object;
RedisSock *redis_sock;
char *key = NULL, *cmd;
int key_len, cmd_len;
int key_len, cmd_len, key_free;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os",
&object, redis_ce,
@@ -3950,7 +3971,7 @@ PHP_METHOD(Redis, hLen)
RETURN_FALSE;
}
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, "HLEN", "s", key, key_len);
if(key_free) efree(key);
@@ -3969,7 +3990,7 @@ generic_hash_command_2(INTERNAL_FUNCTION_PARAMETERS, char *keyword, int keyword_
zval *object;
RedisSock *redis_sock;
char *key = NULL, *cmd, *member;
int key_len, cmd_len, member_len;
int key_len, cmd_len, member_len, key_free;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oss",
&object, redis_ce,
@@ -3982,7 +4003,7 @@ generic_hash_command_2(INTERNAL_FUNCTION_PARAMETERS, char *keyword, int keyword_
ZVAL_BOOL(return_value, 0);
return NULL;
}
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, keyword, "ss", key, key_len, member, member_len);
if(key_free) efree(key);
@@ -4027,7 +4048,7 @@ generic_hash_command_1(INTERNAL_FUNCTION_PARAMETERS, char *keyword, int keyword_
zval *object;
RedisSock *redis_sock;
char *key = NULL, *cmd;
int key_len, cmd_len;
int key_len, cmd_len, key_free;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os",
&object, redis_ce,
@@ -4040,7 +4061,7 @@ generic_hash_command_1(INTERNAL_FUNCTION_PARAMETERS, char *keyword, int keyword_
ZVAL_BOOL(return_value, 0);
return NULL;
}
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, keyword, "s", key, key_len);
if(key_free) efree(key);
@@ -4095,10 +4116,11 @@ PHP_METHOD(Redis, hGetAll) {
PHPAPI void array_zip_values_and_scores(RedisSock *redis_sock, zval *z_tab, int use_atof TSRMLS_DC) {
zval *z_ret;
MAKE_STD_ZVAL(z_ret);
HashTable *keytable;
MAKE_STD_ZVAL(z_ret);
array_init(z_ret);
HashTable *keytable = Z_ARRVAL_P(z_tab);
keytable = Z_ARRVAL_P(z_tab);
for(zend_hash_internal_pointer_reset(keytable);
zend_hash_has_more_elements(keytable) == SUCCESS;
@@ -4157,7 +4179,7 @@ PHP_METHOD(Redis, hIncrBy)
zval *object;
RedisSock *redis_sock;
char *key = NULL, *cmd, *member, *val;
int key_len, member_len, cmd_len, val_len;
int key_len, member_len, cmd_len, val_len, key_free;
int i;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Osss",
@@ -4184,7 +4206,7 @@ PHP_METHOD(Redis, hIncrBy)
/* HINCRBY key member amount */
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, "HINCRBY", "sss", key, key_len, member, member_len, val, val_len);
if(key_free) efree(key);
@@ -4201,10 +4223,15 @@ PHP_METHOD(Redis, hMget) {
zval *object;
RedisSock *redis_sock;
char *key = NULL, *cmd;
int key_len, cmd_len;
int key_len, cmd_len, key_free;
zval *z_array;
zval **z_keys;
int nb_fields, i;
char *old_cmd = NULL;
zval **data;
HashTable *arr_hash;
HashPosition pointer;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Osa",
&object, redis_ce,
@@ -4225,7 +4252,7 @@ PHP_METHOD(Redis, hMget) {
for(i = 0; i < nb_fields; ++i) {
z_keys[i] = NULL;
}
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format(&cmd,
"*%d" _NL
@@ -4238,12 +4265,6 @@ PHP_METHOD(Redis, hMget) {
, key_len, key, key_len);
if(key_free) efree(key);
char *old_cmd = NULL;
zval **data;
HashTable *arr_hash;
HashPosition pointer;
arr_hash = Z_ARRVAL_P(z_array);
for (i = 0, zend_hash_internal_pointer_reset_ex(arr_hash, &pointer);
@@ -4287,7 +4308,7 @@ PHP_METHOD(Redis, hMset)
zval *object;
RedisSock *redis_sock;
char *key = NULL, *cmd;
int key_len, cmd_len;
int key_len, cmd_len, key_free;
zval *z_hash;
HashTable *ht_hash;
int i;
@@ -4310,7 +4331,7 @@ PHP_METHOD(Redis, hMset)
RETURN_FALSE;
}
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format(&cmd,
"$5" _NL "HMSET" _NL
"$%d" _NL "%s" _NL
@@ -4328,6 +4349,9 @@ PHP_METHOD(Redis, hMset)
int type;
int hkey_free = 0;
zval **z_value_p;
char *hval;
int hval_len, hval_free;
type = zend_hash_get_current_key_ex(ht_hash, &hkey, &hkey_len, &idx, 0, NULL);
@@ -4343,9 +4367,7 @@ PHP_METHOD(Redis, hMset)
element_count += 2;
/* key is set. */
char *hval;
int hval_len;
int hval_free = redis_serialize(redis_sock, *z_value_p, &hval, &hval_len TSRMLS_CC);
hval_free = redis_serialize(redis_sock, *z_value_p, &hval, &hval_len TSRMLS_CC);
old_cmd = cmd;
cmd_len = redis_cmd_format(&cmd, "%s"
@@ -4507,6 +4529,8 @@ PHPAPI int redis_sock_read_multibulk_multi_reply(INTERNAL_FUNCTION_PARAMETERS,
{
char inbuf[1024];
int numElems;
zval *z_tab;
redis_check_eof(redis_sock TSRMLS_CC);
@@ -4516,14 +4540,14 @@ PHPAPI int redis_sock_read_multibulk_multi_reply(INTERNAL_FUNCTION_PARAMETERS,
}
/* number of responses */
int numElems = atoi(inbuf+1);
numElems = atoi(inbuf+1);
if(numElems < 0) {
return -1;
}
zval_dtor(return_value);
zval *z_tab;
MAKE_STD_ZVAL(z_tab);
array_init(z_tab);
@@ -4541,7 +4565,9 @@ free_reply_callbacks(zval *z_this, RedisSock *redis_sock) {
fold_item *fi;
fold_item *head = redis_sock->head;
for(fi = head; fi; ) {
request_item *ri;
for(fi = head; fi; ) {
fold_item *fi_next = fi->next;
free(fi);
fi = fi_next;
@@ -4549,7 +4575,6 @@ free_reply_callbacks(zval *z_this, RedisSock *redis_sock) {
redis_sock->head = NULL;
redis_sock->current = NULL;
request_item *ri;
for(ri = redis_sock->pipeline_head; ri; ) {
struct request_item *ri_next = ri->next;
free(ri->request_str);
@@ -4695,7 +4720,7 @@ PHP_METHOD(Redis, publish)
zval *object;
RedisSock *redis_sock;
char *cmd, *key, *val;
int cmd_len, key_len, val_len;
int cmd_len, key_len, val_len, key_free;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oss",
&object, redis_ce,
@@ -4707,7 +4732,7 @@ PHP_METHOD(Redis, publish)
RETURN_FALSE;
}
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, "PUBLISH", "ss", key, key_len, val, val_len);
if(key_free) efree(key);
@@ -4732,6 +4757,13 @@ PHP_METHOD(Redis, subscribe)
char *cmd = "", *old_cmd = NULL, *callback_ft_name;
int cmd_len, array_count, callback_ft_name_len;
zval *z_tab, **tmp;
char *type_response;
int callback_type;
zval *z_o, *z_fun,*z_ret, *z_args[3];
char *method_name;
zend_class_entry *ce;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oaz|z",
&object, redis_ce, &array, &z_callback) == FAILURE) {
@@ -4775,8 +4807,6 @@ PHP_METHOD(Redis, subscribe)
efree(cmd);
/* read the status of the execution of the command `subscribe` */
zval *z_tab, **tmp;
char *type_response;
z_tab = redis_sock_read_multibulk_reply_zval(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock);
@@ -4792,11 +4822,6 @@ PHP_METHOD(Redis, subscribe)
RETURN_FALSE;
}
efree(z_tab);
int callback_type;
zval *z_o, *z_fun,*z_ret, *z_args[3];
char *method_name;
zend_class_entry *ce;
/* verify the callback */
if(Z_TYPE_P(z_callback) == IS_ARRAY) {
@@ -4826,8 +4851,8 @@ PHP_METHOD(Redis, subscribe)
/* Multibulk Response, format : {message type, originating channel, message payload} */
while(1) {
/* call the callback with this z_tab in argument */
z_tab = redis_sock_read_multibulk_reply_zval(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock);
zval **type, **channel, **data;
z_tab = redis_sock_read_multibulk_reply_zval(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock);
if(Z_TYPE_P(z_tab) != IS_ARRAY) {
//ERROR
@@ -4895,6 +4920,9 @@ PHP_METHOD(Redis, unsubscribe)
char *cmd = "", *old_cmd = NULL;
int cmd_len, array_count;
int i;
zval *z_tab, **z_channel;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oa",
&object, redis_ce, &array) == FAILURE) {
RETURN_FALSE;
@@ -4937,9 +4965,7 @@ PHP_METHOD(Redis, unsubscribe)
}
efree(cmd);
int i = 1;
zval *z_tab, **z_channel;
i = 1;
array_init(return_value);
while( i <= array_count) {