Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Socket Retrieval #18

Open
wants to merge 8 commits into from

3 participants

@iliaal

I've modified the code to store the socket information inside the object struct. This allows code to avoid 2 hash lookups on every function (1 lookup of object property and another to lookup the socket in the resource list). This makes this specific operation 15-20% faster.

There are also a few compiler warning fixes.

@briceburg

Curious here - any reason why this was not merged?

@iliaal
@abrosimov abrosimov referenced this pull request
Closed

Segmentation fault. #143

@lstrojny

Anything wrong with this patch?

@iliaal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 18, 2011
  1. @iliaal

    Minor tweaks

    iliaal authored
Commits on May 20, 2011
  1. @iliaal
  2. @iliaal

    Move socket storage into object internal, rather than a public proper…

    iliaal authored
    …ty, this make socket resolution 15-20% faster.
    
    Fixed some compiler warnings
Commits on May 21, 2011
  1. @iliaal

    Simplify code

    iliaal authored
  2. @iliaal
Commits on May 23, 2011
  1. Removed un-necessary INIT functions

    Ilia authored
  2. Move declaration methods around so that they don't need to sit inside…

    Ilia authored
    … the header file
This page is out of date. Refresh to see the latest.
Showing with 734 additions and 1,023 deletions.
  1. +1 −0  config.m4
  2. +2 −10 library.c
  3. +0 −132 php_redis.h
  4. +731 −881 redis.c
View
1  config.m4
@@ -47,4 +47,5 @@ if test "$PHP_REDIS" != "no"; then
dnl PHP_SUBST(REDIS_SHARED_LIBADD)
PHP_NEW_EXTENSION(redis, redis.c library.c redis_session.c igbinary/igbinary.c igbinary/hash_si.c igbinary/hash_function.c, $ext_shared)
+ PHP_ADD_BUILD_DIR($ext_builddir/igbinary, 1)
fi
View
12 library.c
@@ -453,17 +453,9 @@ PHPAPI void redis_boolean_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redi
efree(response);
IF_MULTI_OR_PIPELINE() {
- if (ret == '+') {
- add_next_index_bool(z_tab, 1);
- } else {
- add_next_index_bool(z_tab, 0);
- }
+ add_next_index_bool(z_tab, (ret == '+'));
} else {
- if (ret == '+') {
- RETURN_TRUE;
- } else {
- RETURN_FALSE;
- }
+ RETURN_BOOL((ret == '+'));
}
}
View
132 php_redis.h
@@ -23,135 +23,6 @@
#ifndef PHP_REDIS_H
#define PHP_REDIS_H
-PHP_METHOD(Redis, __construct);
-PHP_METHOD(Redis, connect);
-PHP_METHOD(Redis, pconnect);
-PHP_METHOD(Redis, close);
-PHP_METHOD(Redis, ping);
-PHP_METHOD(Redis, get);
-PHP_METHOD(Redis, set);
-PHP_METHOD(Redis, setex);
-PHP_METHOD(Redis, setnx);
-PHP_METHOD(Redis, getSet);
-PHP_METHOD(Redis, randomKey);
-PHP_METHOD(Redis, renameKey);
-PHP_METHOD(Redis, renameNx);
-PHP_METHOD(Redis, getMultiple);
-PHP_METHOD(Redis, exists);
-PHP_METHOD(Redis, delete);
-PHP_METHOD(Redis, incr);
-PHP_METHOD(Redis, incrBy);
-PHP_METHOD(Redis, decr);
-PHP_METHOD(Redis, decrBy);
-PHP_METHOD(Redis, type);
-PHP_METHOD(Redis, append);
-PHP_METHOD(Redis, getRange);
-PHP_METHOD(Redis, setRange);
-PHP_METHOD(Redis, getBit);
-PHP_METHOD(Redis, setBit);
-PHP_METHOD(Redis, strlen);
-PHP_METHOD(Redis, getKeys);
-PHP_METHOD(Redis, sort);
-PHP_METHOD(Redis, sortAsc);
-PHP_METHOD(Redis, sortAscAlpha);
-PHP_METHOD(Redis, sortDesc);
-PHP_METHOD(Redis, sortDescAlpha);
-PHP_METHOD(Redis, lPush);
-PHP_METHOD(Redis, lPushx);
-PHP_METHOD(Redis, rPush);
-PHP_METHOD(Redis, rPushx);
-PHP_METHOD(Redis, lPop);
-PHP_METHOD(Redis, rPop);
-PHP_METHOD(Redis, blPop);
-PHP_METHOD(Redis, brPop);
-PHP_METHOD(Redis, lSize);
-PHP_METHOD(Redis, lRemove);
-PHP_METHOD(Redis, listTrim);
-PHP_METHOD(Redis, lGet);
-PHP_METHOD(Redis, lGetRange);
-PHP_METHOD(Redis, lSet);
-PHP_METHOD(Redis, lInsert);
-PHP_METHOD(Redis, sAdd);
-PHP_METHOD(Redis, sSize);
-PHP_METHOD(Redis, sRemove);
-PHP_METHOD(Redis, sMove);
-PHP_METHOD(Redis, sPop);
-PHP_METHOD(Redis, sRandMember);
-PHP_METHOD(Redis, sContains);
-PHP_METHOD(Redis, sMembers);
-PHP_METHOD(Redis, sInter);
-PHP_METHOD(Redis, sInterStore);
-PHP_METHOD(Redis, sUnion);
-PHP_METHOD(Redis, sUnionStore);
-PHP_METHOD(Redis, sDiff);
-PHP_METHOD(Redis, sDiffStore);
-PHP_METHOD(Redis, setTimeout);
-PHP_METHOD(Redis, save);
-PHP_METHOD(Redis, bgSave);
-PHP_METHOD(Redis, lastSave);
-PHP_METHOD(Redis, flushDB);
-PHP_METHOD(Redis, flushAll);
-PHP_METHOD(Redis, dbSize);
-PHP_METHOD(Redis, auth);
-PHP_METHOD(Redis, ttl);
-PHP_METHOD(Redis, persist);
-PHP_METHOD(Redis, info);
-PHP_METHOD(Redis, select);
-PHP_METHOD(Redis, move);
-PHP_METHOD(Redis, zAdd);
-PHP_METHOD(Redis, zDelete);
-PHP_METHOD(Redis, zRange);
-PHP_METHOD(Redis, zReverseRange);
-PHP_METHOD(Redis, zRangeByScore);
-PHP_METHOD(Redis, zRevRangeByScore);
-PHP_METHOD(Redis, zCount);
-PHP_METHOD(Redis, zDeleteRangeByScore);
-PHP_METHOD(Redis, zDeleteRangeByRank);
-PHP_METHOD(Redis, zCard);
-PHP_METHOD(Redis, zScore);
-PHP_METHOD(Redis, zRank);
-PHP_METHOD(Redis, zRevRank);
-PHP_METHOD(Redis, zIncrBy);
-PHP_METHOD(Redis, zInter);
-PHP_METHOD(Redis, zUnion);
-PHP_METHOD(Redis, expireAt);
-PHP_METHOD(Redis, bgrewriteaof);
-PHP_METHOD(Redis, slaveof);
-PHP_METHOD(Redis, object);
-
-PHP_METHOD(Redis, mset);
-PHP_METHOD(Redis, msetnx);
-PHP_METHOD(Redis, rpoplpush);
-PHP_METHOD(Redis, brpoplpush);
-
-PHP_METHOD(Redis, hGet);
-PHP_METHOD(Redis, hSet);
-PHP_METHOD(Redis, hSetNx);
-PHP_METHOD(Redis, hDel);
-PHP_METHOD(Redis, hLen);
-PHP_METHOD(Redis, hKeys);
-PHP_METHOD(Redis, hVals);
-PHP_METHOD(Redis, hGetAll);
-PHP_METHOD(Redis, hExists);
-PHP_METHOD(Redis, hIncrBy);
-PHP_METHOD(Redis, hMset);
-PHP_METHOD(Redis, hMget);
-
-PHP_METHOD(Redis, multi);
-PHP_METHOD(Redis, discard);
-PHP_METHOD(Redis, exec);
-PHP_METHOD(Redis, watch);
-PHP_METHOD(Redis, unwatch);
-
-PHP_METHOD(Redis, pipeline);
-
-PHP_METHOD(Redis, publish);
-PHP_METHOD(Redis, subscribe);
-PHP_METHOD(Redis, unsubscribe);
-
-PHP_METHOD(Redis, getOption);
-PHP_METHOD(Redis, setOption);
-
#ifdef PHP_WIN32
#define PHP_REDIS_API __declspec(dllexport)
#else
@@ -163,9 +34,6 @@ PHP_METHOD(Redis, setOption);
#endif
PHP_MINIT_FUNCTION(redis);
-PHP_MSHUTDOWN_FUNCTION(redis);
-PHP_RINIT_FUNCTION(redis);
-PHP_RSHUTDOWN_FUNCTION(redis);
PHP_MINFO_FUNCTION(redis);
PHPAPI int redis_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent);
View
1,612 redis.c
@@ -39,495 +39,84 @@ static int le_redis_sock;
extern ps_module ps_mod_redis;
+typedef struct _redis_object {
+ zend_object std;
+ RedisSock *sock;
+ long sock_id;
+} redis_object;
+
zend_class_entry *redis_ce;
zend_class_entry *redis_exception_ce;
zend_class_entry *spl_ce_RuntimeException = NULL;
+#define REDIS_FROM_OBJECT(redis_sock, object) \
+ { \
+ redis_object *obj = (redis_object*) zend_object_store_get_object(object TSRMLS_CC); \
+ redis_sock = obj->sock; \
+ if (!redis_sock) { \
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Connection was not yet established"); \
+ RETURN_FALSE; \
+ } \
+ }
-ZEND_DECLARE_MODULE_GLOBALS(redis)
-
-static zend_function_entry redis_functions[] = {
- PHP_ME(Redis, __construct, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, connect, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, pconnect, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, close, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, ping, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, get, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, set, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, setex, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, setnx, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, getSet, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, randomKey, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, renameKey, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, renameNx, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, getMultiple, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, exists, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, delete, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, incr, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, incrBy, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, decr, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, decrBy, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, type, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, append, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, getRange, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, setRange, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, getBit, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, setBit, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, strlen, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, getKeys, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, sort, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, sortAsc, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, sortAscAlpha, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, sortDesc, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, sortDescAlpha, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, lPush, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, rPush, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, lPushx, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, rPushx, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, lPop, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, rPop, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, blPop, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, brPop, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, lSize, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, lRemove, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, listTrim, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, lGet, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, lGetRange, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, lSet, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, lInsert, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, sAdd, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, sSize, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, sRemove, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, sMove, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, sPop, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, sRandMember, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, sContains, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, sMembers, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, sInter, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, sInterStore, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, sUnion, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, sUnionStore, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, sDiff, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, sDiffStore, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, setTimeout, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, save, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, bgSave, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, lastSave, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, flushDB, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, flushAll, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, dbSize, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, auth, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, ttl, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, persist, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, info, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, select, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, move, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, bgrewriteaof, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, slaveof, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, object, NULL, ZEND_ACC_PUBLIC)
-
- /* 1.1 */
- PHP_ME(Redis, mset, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, msetnx, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, rpoplpush, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, brpoplpush, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, zAdd, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, zDelete, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, zRange, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, zReverseRange, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, zRangeByScore, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, zRevRangeByScore, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, zCount, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, zDeleteRangeByScore, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, zDeleteRangeByRank, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, zCard, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, zScore, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, zRank, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, zRevRank, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, zInter, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, zUnion, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, zIncrBy, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, expireAt, NULL, ZEND_ACC_PUBLIC)
-
- /* 1.2 */
- PHP_ME(Redis, hGet, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, hSet, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, hSetNx, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, hDel, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, hLen, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, hKeys, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, hVals, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, hGetAll, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, hExists, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, hIncrBy, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, hMset, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, hMget, NULL, ZEND_ACC_PUBLIC)
-
- PHP_ME(Redis, multi, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, discard, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, exec, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, pipeline, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, watch, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, unwatch, NULL, ZEND_ACC_PUBLIC)
-
- PHP_ME(Redis, publish, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, subscribe, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, unsubscribe, NULL, ZEND_ACC_PUBLIC)
-
- /* options */
- PHP_ME(Redis, getOption, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, setOption, NULL, ZEND_ACC_PUBLIC)
-
- /* aliases */
- PHP_MALIAS(Redis, open, connect, NULL, ZEND_ACC_PUBLIC)
- PHP_MALIAS(Redis, popen, pconnect, NULL, ZEND_ACC_PUBLIC)
- PHP_MALIAS(Redis, lLen, lSize, NULL, ZEND_ACC_PUBLIC)
- PHP_MALIAS(Redis, sGetMembers, sMembers, NULL, ZEND_ACC_PUBLIC)
- PHP_MALIAS(Redis, mget, getMultiple, NULL, ZEND_ACC_PUBLIC)
- PHP_MALIAS(Redis, expire, setTimeout, NULL, ZEND_ACC_PUBLIC)
- PHP_MALIAS(Redis, zunionstore, zUnion, NULL, ZEND_ACC_PUBLIC)
- PHP_MALIAS(Redis, zinterstore, zInter, NULL, ZEND_ACC_PUBLIC)
- PHP_MALIAS(Redis, zRemove, zDelete, NULL, ZEND_ACC_PUBLIC)
- PHP_MALIAS(Redis, zRem, zDelete, NULL, ZEND_ACC_PUBLIC)
- PHP_MALIAS(Redis, zRemoveRangeByScore, zDeleteRangeByScore, NULL, ZEND_ACC_PUBLIC)
- PHP_MALIAS(Redis, zRemRangeByScore, zDeleteRangeByScore, NULL, ZEND_ACC_PUBLIC)
- PHP_MALIAS(Redis, zRemRangeByRank, zDeleteRangeByRank, NULL, ZEND_ACC_PUBLIC)
- PHP_MALIAS(Redis, zSize, zCard, NULL, ZEND_ACC_PUBLIC)
- PHP_MALIAS(Redis, substr, getRange, NULL, ZEND_ACC_PUBLIC)
- PHP_MALIAS(Redis, rename, renameKey, NULL, ZEND_ACC_PUBLIC)
- PHP_MALIAS(Redis, del, delete, NULL, ZEND_ACC_PUBLIC)
- PHP_MALIAS(Redis, keys, getKeys, NULL, ZEND_ACC_PUBLIC)
- PHP_MALIAS(Redis, lrem, lRemove, NULL, ZEND_ACC_PUBLIC)
- PHP_MALIAS(Redis, ltrim, listTrim, NULL, ZEND_ACC_PUBLIC)
- PHP_MALIAS(Redis, lindex, lGet, NULL, ZEND_ACC_PUBLIC)
- PHP_MALIAS(Redis, lrange, lGetRange, NULL, ZEND_ACC_PUBLIC)
- PHP_MALIAS(Redis, scard, sSize, NULL, ZEND_ACC_PUBLIC)
- PHP_MALIAS(Redis, srem, sRemove, NULL, ZEND_ACC_PUBLIC)
- PHP_MALIAS(Redis, sismember, sContains, NULL, ZEND_ACC_PUBLIC)
- PHP_MALIAS(Redis, zrevrange, zReverseRange, NULL, ZEND_ACC_PUBLIC)
- {NULL, NULL, NULL}
-};
+/* {{{ proto boolean Redis::close()
+ */
+PHP_METHOD(Redis, close)
+{
+ zval *object;
+ RedisSock *redis_sock = NULL;
-zend_module_entry redis_module_entry = {
-#if ZEND_MODULE_API_NO >= 20010901
- STANDARD_MODULE_HEADER,
-#endif
- "redis",
- NULL,
- PHP_MINIT(redis),
- PHP_MSHUTDOWN(redis),
- PHP_RINIT(redis),
- PHP_RSHUTDOWN(redis),
- PHP_MINFO(redis),
-#if ZEND_MODULE_API_NO >= 20010901
- PHP_REDIS_VERSION,
-#endif
- STANDARD_MODULE_PROPERTIES
-};
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
+ &object, redis_ce) == FAILURE) {
+ RETURN_FALSE;
+ }
-#ifdef COMPILE_DL_REDIS
-ZEND_GET_MODULE(redis)
-#endif
+ REDIS_FROM_OBJECT(redis_sock, object);
-PHPAPI zend_class_entry *redis_get_exception_base(int root TSRMLS_DC)
-{
-#if HAVE_SPL
- if (!root) {
- if (!spl_ce_RuntimeException) {
- zend_class_entry **pce;
+ if (redis_sock_disconnect(redis_sock TSRMLS_CC)) {
+ RETURN_TRUE;
+ }
- if (zend_hash_find(CG(class_table), "runtimeexception",
- sizeof("RuntimeException"), (void **) &pce) == SUCCESS) {
- spl_ce_RuntimeException = *pce;
- return *pce;
- }
- } else {
- return spl_ce_RuntimeException;
- }
- }
-#endif
-#if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 2)
- return zend_exception_get_default();
-#else
- return zend_exception_get_default(TSRMLS_C);
-#endif
+ RETURN_FALSE;
}
+/* }}} */
-/**
- * redis_destructor_redis_sock
- */
-static void redis_destructor_redis_sock(zend_rsrc_list_entry * rsrc TSRMLS_DC)
-{
- RedisSock *redis_sock = (RedisSock *) rsrc->ptr;
- redis_sock_disconnect(redis_sock TSRMLS_CC);
- redis_free_socket(redis_sock);
-}
-/**
- * redis_sock_get
+/* {{{ proto boolean Redis::set(string key, mixed value)
*/
-PHPAPI int redis_sock_get(zval *id, RedisSock **redis_sock TSRMLS_DC)
+PHP_METHOD(Redis, set)
{
+ zval *object;
+ RedisSock *redis_sock;
+ char *key = NULL, *val = NULL, *cmd;
+ int key_len, val_len, cmd_len;
+ long expire = -1;
+ int val_free = 0, key_free = 0;
+ zval *z_value;
- zval **socket;
- int resource_type;
-
- if (Z_TYPE_P(id) != IS_OBJECT || zend_hash_find(Z_OBJPROP_P(id), "socket",
- sizeof("socket"), (void **) &socket) == FAILURE) {
- return -1;
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Osz|l",
+ &object, redis_ce, &key, &key_len,
+ &z_value, &expire) == FAILURE) {
+ RETURN_FALSE;
}
- *redis_sock = (RedisSock *) zend_list_find(Z_LVAL_PP(socket), &resource_type);
+ REDIS_FROM_OBJECT(redis_sock, object);
- if (!*redis_sock || resource_type != le_redis_sock) {
- return -1;
+ val_free = redis_serialize(redis_sock, z_value, &val, &val_len TSRMLS_CC);
+ key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
+ if(expire > 0) {
+ cmd_len = redis_cmd_format_static(&cmd, "SETEX", "sds", key, key_len, expire, val, val_len);
+ } else {
+ cmd_len = redis_cmd_format_static(&cmd, "SET", "ss", key, key_len, val, val_len);
}
+ if(val_free) efree(val);
+ if(key_free) efree(key);
- return Z_LVAL_PP(socket);
-}
-
-/**
- * PHP_MINIT_FUNCTION
- */
-PHP_MINIT_FUNCTION(redis)
-{
- zend_class_entry redis_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,
- redis_get_exception_base(0 TSRMLS_CC),
- NULL TSRMLS_CC
- );
-
- le_redis_sock = zend_register_list_destructors_ex(
- redis_destructor_redis_sock,
- NULL,
- redis_sock_name, module_number
- );
-
- add_constant_long(redis_ce, "REDIS_NOT_FOUND", REDIS_NOT_FOUND);
- add_constant_long(redis_ce, "REDIS_STRING", REDIS_STRING);
- add_constant_long(redis_ce, "REDIS_SET", REDIS_SET);
- add_constant_long(redis_ce, "REDIS_LIST", REDIS_LIST);
- add_constant_long(redis_ce, "REDIS_ZSET", REDIS_ZSET);
- add_constant_long(redis_ce, "REDIS_HASH", REDIS_HASH);
-
- add_constant_long(redis_ce, "ATOMIC", ATOMIC);
- add_constant_long(redis_ce, "MULTI", MULTI);
- add_constant_long(redis_ce, "PIPELINE", PIPELINE);
-
- /* options */
- add_constant_long(redis_ce, "OPT_SERIALIZER", REDIS_OPT_SERIALIZER);
- add_constant_long(redis_ce, "OPT_PREFIX", REDIS_OPT_PREFIX);
-
- /* serializer */
- add_constant_long(redis_ce, "SERIALIZER_NONE", REDIS_SERIALIZER_NONE);
- add_constant_long(redis_ce, "SERIALIZER_PHP", REDIS_SERIALIZER_PHP);
- add_constant_long(redis_ce, "SERIALIZER_IGBINARY", REDIS_SERIALIZER_IGBINARY);
-
- zend_declare_class_constant_stringl(redis_ce, "AFTER", 5, "after", 5 TSRMLS_CC);
- zend_declare_class_constant_stringl(redis_ce, "BEFORE", 6, "before", 6 TSRMLS_CC);
-
- /* declare session handler */
- php_session_register_module(&ps_mod_redis);
-
- return SUCCESS;
-}
-
-/**
- * PHP_MSHUTDOWN_FUNCTION
- */
-PHP_MSHUTDOWN_FUNCTION(redis)
-{
- return SUCCESS;
-}
-
-/**
- * PHP_RINIT_FUNCTION
- */
-PHP_RINIT_FUNCTION(redis)
-{
- return SUCCESS;
-}
-
-/**
- * PHP_RSHUTDOWN_FUNCTION
- */
-PHP_RSHUTDOWN_FUNCTION(redis)
-{
- return SUCCESS;
-}
-
-/**
- * PHP_MINFO_FUNCTION
- */
-PHP_MINFO_FUNCTION(redis)
-{
- php_info_print_table_start();
- php_info_print_table_header(2, "Redis Support", "enabled");
- php_info_print_table_row(2, "Redis Version", PHP_REDIS_VERSION);
- php_info_print_table_end();
-}
-
-/* {{{ proto Redis Redis::__construct()
- Public constructor */
-PHP_METHOD(Redis, __construct)
-{
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) {
- RETURN_FALSE;
- }
-}
-/* }}} */
-
-/* {{{ proto boolean Redis::connect(string host, int port [, double timeout])
- */
-PHP_METHOD(Redis, connect)
-{
- if (redis_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0) == FAILURE) {
- RETURN_FALSE;
- } else {
- RETURN_TRUE;
- }
-}
-/* }}} */
-
-/* {{{ proto boolean Redis::pconnect(string host, int port [, double timeout])
- */
-PHP_METHOD(Redis, pconnect)
-{
- if (redis_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1) == FAILURE) {
- RETURN_FALSE;
- } else {
- RETURN_TRUE;
- }
-}
-/* }}} */
-
-PHPAPI int redis_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) {
- zval *object;
- zval **socket;
- int host_len, id;
- char *host = NULL;
- long port = -1;
-
-#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|ld",
- &object, redis_ce, &host, &host_len, &port,
- &timeout) == FAILURE) {
- return FAILURE;
- }
-
- if (timeout < 0L || timeout > INT_MAX) {
- zend_throw_exception(redis_exception_ce, "Invalid timeout", 0 TSRMLS_CC);
- return FAILURE;
- }
-
- if(port == -1 && host_len && host[0] != '/') { /* not unix socket, set to default value */
- port = 6379;
- }
-
- /* if there is a redis sock already we have to remove it from the list */
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) > 0) {
- if (zend_hash_find(Z_OBJPROP_P(object), "socket",
- sizeof("socket"), (void **) &socket) == FAILURE) {
- /* maybe there is a socket but the id isn't known.. what to do? */
- } else {
- zend_list_delete(Z_LVAL_PP(socket)); /* the refcount should be decreased and the detructor called */
- }
- }
-
- redis_sock = redis_sock_create(host, host_len, port, timeout, persistent);
-
- if (redis_sock_server_open(redis_sock, 1 TSRMLS_CC) < 0) {
- redis_free_socket(redis_sock);
- zend_throw_exception_ex(
- redis_exception_ce,
- 0 TSRMLS_CC,
- "Can't connect to %s:%d",
- host,
- port
- );
- return FAILURE;
- }
-
- id = zend_list_insert(redis_sock, le_redis_sock);
- add_property_resource(object, "socket", id);
-
- return SUCCESS;
-}
-
-/* {{{ proto boolean Redis::close()
- */
-PHP_METHOD(Redis, close)
-{
- zval *object;
- RedisSock *redis_sock = NULL;
-
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
- &object, redis_ce) == FAILURE) {
- RETURN_FALSE;
- }
-
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
-
- if (redis_sock_disconnect(redis_sock TSRMLS_CC)) {
- RETURN_TRUE;
- }
-
- RETURN_FALSE;
-}
-/* }}} */
-
-/* {{{ proto boolean Redis::set(string key, mixed value)
- */
-PHP_METHOD(Redis, set)
-{
- zval *object;
- RedisSock *redis_sock;
- char *key = NULL, *val = NULL, *cmd;
- int key_len, val_len, cmd_len;
- long expire = -1;
- int val_free = 0, key_free = 0;
- zval *z_value;
-
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Osz|l",
- &object, redis_ce, &key, &key_len,
- &z_value, &expire) == FAILURE) {
- RETURN_FALSE;
- }
-
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
-
- val_free = redis_serialize(redis_sock, z_value, &val, &val_len TSRMLS_CC);
- key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
- if(expire > 0) {
- cmd_len = redis_cmd_format_static(&cmd, "SETEX", "sds", key, key_len, expire, val, val_len);
- } else {
- cmd_len = redis_cmd_format_static(&cmd, "SET", "ss", key, key_len, val, val_len);
- }
- if(val_free) efree(val);
- if(key_free) efree(key);
-
- REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len);
- IF_ATOMIC() {
- redis_boolean_response(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, NULL, NULL);
- }
- REDIS_PROCESS_RESPONSE(redis_boolean_response);
+ REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len);
+ IF_ATOMIC() {
+ redis_boolean_response(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, NULL, NULL);
+ }
+ REDIS_PROCESS_RESPONSE(redis_boolean_response);
}
/* {{{ proto boolean Redis::setex(string key, long expire, string value)
@@ -548,9 +137,7 @@ PHP_METHOD(Redis, setex)
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
val_free = redis_serialize(redis_sock, z_value, &val, &val_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
@@ -583,9 +170,7 @@ PHP_METHOD(Redis, setnx)
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
val_free = redis_serialize(redis_sock, z_value, &val, &val_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
@@ -621,9 +206,7 @@ PHP_METHOD(Redis, getSet)
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
val_free = redis_serialize(redis_sock, z_value, &val, &val_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
@@ -655,9 +238,7 @@ PHP_METHOD(Redis, randomKey)
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
cmd_len = redis_cmd_format(&cmd, "*1" _NL "$9" _NL "RANDOMKEY" _NL);
/* TODO: remove prefix from key */
@@ -687,9 +268,7 @@ PHP_METHOD(Redis, renameKey)
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
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);
@@ -723,9 +302,7 @@ PHP_METHOD(Redis, renameNx)
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
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);
@@ -757,9 +334,7 @@ PHP_METHOD(Redis, get)
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, "GET", "s", key, key_len);
@@ -789,9 +364,7 @@ PHP_METHOD(Redis, ping)
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
if (!redis_sock->stream) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "The object is not connected");
@@ -822,9 +395,8 @@ PHPAPI void redis_atomic_increment(INTERNAL_FUNCTION_PARAMETERS, char *keyword,
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
+
int 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);
@@ -948,9 +520,7 @@ PHP_METHOD(Redis, getMultiple)
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
arr_hash = Z_ARRVAL_P(array);
array_count = zend_hash_num_elements(arr_hash);
@@ -1031,9 +601,8 @@ PHP_METHOD(Redis, exists)
&key, &key_len) == FAILURE) {
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+
+ REDIS_FROM_OBJECT(redis_sock, object)
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, "EXISTS", "s", key, key_len);
@@ -1107,9 +676,7 @@ PHP_METHOD(Redis, getKeys)
RETURN_NULL();
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
int pattern_free = redis_key_prefix(redis_sock, &pattern, &pattern_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, "KEYS", "s", pattern, pattern_len);
@@ -1141,9 +708,7 @@ PHP_METHOD(Redis, type)
RETURN_NULL();
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, "TYPE", "s", key, key_len);
@@ -1171,9 +736,7 @@ PHP_METHOD(Redis, append)
RETURN_NULL();
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
int 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);
@@ -1200,9 +763,7 @@ PHP_METHOD(Redis, getRange)
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
int 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);
@@ -1228,9 +789,7 @@ PHP_METHOD(Redis, setRange)
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
int 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);
@@ -1256,9 +815,7 @@ PHP_METHOD(Redis, getBit)
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
int 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);
@@ -1285,9 +842,7 @@ PHP_METHOD(Redis, setBit)
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
int 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);
@@ -1314,9 +869,7 @@ PHP_METHOD(Redis, strlen)
RETURN_NULL();
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, "STRLEN", "s", key, key_len);
@@ -1344,9 +897,7 @@ generic_push_function(INTERNAL_FUNCTION_PARAMETERS, char *keyword, int keyword_l
RETURN_NULL();
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
val_free = redis_serialize(redis_sock, z_value, &val, &val_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
@@ -1397,10 +948,8 @@ PHP_METHOD(Redis, lInsert)
RETURN_NULL();
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
-
+ REDIS_FROM_OBJECT(redis_sock, object)
+
if(strncasecmp(position, "after", 5) == 0 || strncasecmp(position, "before", 6) == 0) {
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
@@ -1446,9 +995,7 @@ generic_pop_function(INTERNAL_FUNCTION_PARAMETERS, char *keyword, int keyword_le
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, keyword, "s", key, key_len);
@@ -1534,9 +1081,7 @@ PHP_METHOD(Redis, lSize)
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, "LLEN", "s", key, key_len);
@@ -1570,10 +1115,7 @@ PHP_METHOD(Redis, lRemove)
RETURN_NULL();
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
-
+ REDIS_FROM_OBJECT(redis_sock, object)
/* LREM key count value */
val_free = redis_serialize(redis_sock, z_value, &val, &val_len TSRMLS_CC);
@@ -1606,9 +1148,7 @@ PHP_METHOD(Redis, listTrim)
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
int 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);
@@ -1639,9 +1179,7 @@ PHP_METHOD(Redis, lGet)
RETURN_NULL();
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
/* LINDEX key pos */
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
@@ -1672,9 +1210,7 @@ PHP_METHOD(Redis, lGetRange)
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
/* LRANGE key start end */
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
@@ -1707,9 +1243,7 @@ PHP_METHOD(Redis, sAdd)
RETURN_NULL();
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
val_free = redis_serialize(redis_sock, z_value, &val, &val_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
@@ -1740,9 +1274,7 @@ PHP_METHOD(Redis, sSize)
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, "SCARD", "s", key, key_len);
@@ -1773,9 +1305,7 @@ PHP_METHOD(Redis, sRemove)
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
val_free = redis_serialize(redis_sock, z_value, &val, &val_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
@@ -1809,9 +1339,7 @@ PHP_METHOD(Redis, sMove)
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
val_free = redis_serialize(redis_sock, z_value, &val, &val_len TSRMLS_CC);
src_free = redis_key_prefix(redis_sock, &src, &src_len TSRMLS_CC);
@@ -1864,9 +1392,7 @@ PHP_METHOD(Redis, sContains)
return;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
val_free = redis_serialize(redis_sock, z_value, &val, &val_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
@@ -1897,9 +1423,7 @@ PHP_METHOD(Redis, sMembers)
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, "SMEMBERS", "s", key, key_len);
@@ -1920,25 +1444,25 @@ PHP_METHOD(Redis, sMembers)
PHPAPI int generic_multiple_args_cmd(INTERNAL_FUNCTION_PARAMETERS, char *keyword, int keyword_len,
int min_argc, RedisSock **out_sock, int has_timeout)
{
- zval *object, **z_args, *z_array;
- char **keys, *cmd;
- int cmd_len, *keys_len;
- int i, j, argc = ZEND_NUM_ARGS(), real_argc = 0;
- int single_array = 0;
+ zval *object, **z_args, *z_array;
+ char **keys, *cmd;
+ int cmd_len, *keys_len;
+ int i, j, argc = ZEND_NUM_ARGS(), real_argc = 0;
+ int single_array = 0;
int timeout;
- RedisSock *redis_sock;
-
- if(argc < min_argc) {
- WRONG_PARAM_COUNT;
- RETURN_FALSE;
- }
+ RedisSock *redis_sock;
- /* get redis socket */
- if (redis_sock_get(getThis(), out_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
- redis_sock = *out_sock;
+ if (argc < min_argc) {
+ WRONG_PARAM_COUNT_WITH_RETVAL(-1);
+ } else { /* get redis socket */
+ redis_object *obj = (redis_object*) zend_object_store_get_object(getThis() TSRMLS_CC);
+ *out_sock = redis_sock = obj->sock;
+ if (!redis_sock) {
+ ZVAL_BOOL(return_value, 0);
+ return -1;
+ }
+ }
z_args = emalloc(argc * sizeof(zval*));
if(zend_get_parameters_array(ht, argc, z_args) == FAILURE) {
@@ -2216,9 +1740,7 @@ PHP_METHOD(Redis, sort) {
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
cmd_len = redis_cmd_format(&cmd, "$4" _NL "SORT" _NL "$%d" _NL "%s" _NL
, key_len, key, key_len);
@@ -2424,9 +1946,8 @@ PHPAPI void generic_sort_cmd(INTERNAL_FUNCTION_PARAMETERS, char *sort, int use_a
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
+
if(key_len == 0) {
RETURN_FALSE;
}
@@ -2620,9 +2141,7 @@ PHPAPI void generic_expire_cmd(INTERNAL_FUNCTION_PARAMETERS, char *keyword, int
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
int 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);
@@ -2669,9 +2188,7 @@ PHP_METHOD(Redis, lSet) {
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
val_free = redis_serialize(redis_sock, z_value, &val, &val_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
@@ -2697,9 +2214,7 @@ PHPAPI void generic_empty_cmd(INTERNAL_FUNCTION_PARAMETERS, char *cmd, int cmd_l
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len);
IF_ATOMIC() {
@@ -2740,9 +2255,7 @@ PHPAPI void generic_empty_long_cmd(INTERNAL_FUNCTION_PARAMETERS, char *cmd, int
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len);
IF_ATOMIC() {
@@ -2807,9 +2320,7 @@ PHP_METHOD(Redis, auth) {
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
cmd_len = redis_cmd_format_static(&cmd, "AUTH", "s", password, password_len);
@@ -2836,9 +2347,7 @@ PHP_METHOD(Redis, persist) {
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, "PERSIST", "s", key, key_len);
@@ -2867,9 +2376,7 @@ PHP_METHOD(Redis, ttl) {
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, "TTL", "s", key, key_len);
@@ -2898,9 +2405,7 @@ PHP_METHOD(Redis, info) {
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len);
IF_ATOMIC() {
@@ -2927,9 +2432,7 @@ PHP_METHOD(Redis, select) {
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
cmd_len = redis_cmd_format_static(&cmd, "SELECT", "d", dbNumber);
@@ -2957,9 +2460,7 @@ PHP_METHOD(Redis, move) {
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
int 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);
@@ -2989,9 +2490,7 @@ generic_mset(INTERNAL_FUNCTION_PARAMETERS, char *kw, void (*fun)(INTERNAL_FUNCTI
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
if(zend_hash_num_elements(Z_ARRVAL_P(z_array)) == 0) {
RETURN_FALSE;
@@ -3062,7 +2561,6 @@ generic_mset(INTERNAL_FUNCTION_PARAMETERS, char *kw, void (*fun)(INTERNAL_FUNCTI
/* {{{ proto bool Redis::mset(array (key => value, ...))
*/
PHP_METHOD(Redis, mset) {
- RedisSock *redis_sock;
generic_mset(INTERNAL_FUNCTION_PARAM_PASSTHRU, "*%d" _NL "$4" _NL "MSET" _NL, redis_boolean_response);
}
/* }}} */
@@ -3106,7 +2604,7 @@ PHP_METHOD(Redis, rpoplpush)
zval *object;
RedisSock *redis_sock;
char *srckey = NULL, *dstkey = NULL;
- int srckey_len, dstkey_len, cmd_len;
+ int srckey_len, dstkey_len;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oss",
&object, redis_ce, &srckey, &srckey_len,
@@ -3114,9 +2612,7 @@ PHP_METHOD(Redis, rpoplpush)
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
common_rpoplpush(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, srckey, srckey_len, dstkey, dstkey_len, -1);
}
@@ -3138,9 +2634,7 @@ PHP_METHOD(Redis, brpoplpush)
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
common_rpoplpush(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, srckey, srckey_len, dstkey, dstkey_len, timeout);
}
@@ -3165,9 +2659,7 @@ PHP_METHOD(Redis, zAdd) {
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
val_free = redis_serialize(redis_sock, z_value, &val, &val_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
@@ -3200,9 +2692,7 @@ PHP_METHOD(Redis, zRange)
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
if(withscores) {
@@ -3246,9 +2736,7 @@ PHP_METHOD(Redis, zDelete)
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
val_free = redis_serialize(redis_sock, z_value, &val, &val_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
@@ -3282,9 +2770,7 @@ PHP_METHOD(Redis, zDeleteRangeByScore)
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
int 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);
@@ -3315,9 +2801,7 @@ PHP_METHOD(Redis, zDeleteRangeByRank)
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
int 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);
@@ -3349,9 +2833,7 @@ PHP_METHOD(Redis, zReverseRange)
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
if(withscores) {
@@ -3402,9 +2884,7 @@ redis_generic_zrange_by_score(INTERNAL_FUNCTION_PARAMETERS, char *keyword) {
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
/* options */
if (z_options && Z_TYPE_P(z_options) == IS_ARRAY) {
@@ -3508,9 +2988,7 @@ PHP_METHOD(Redis, zCount)
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
int 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);
@@ -3539,9 +3017,7 @@ PHP_METHOD(Redis, zCard)
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, "ZCARD", "s", key, key_len);
@@ -3573,9 +3049,7 @@ PHP_METHOD(Redis, zScore)
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
val_free = redis_serialize(redis_sock, z_value, &val, &val_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
@@ -3606,9 +3080,7 @@ PHPAPI void generic_rank_method(INTERNAL_FUNCTION_PARAMETERS, char *keyword, int
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
val_free = redis_serialize(redis_sock, z_value, &val, &val_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
@@ -3656,9 +3128,7 @@ PHPAPI void generic_incrby_method(INTERNAL_FUNCTION_PARAMETERS, char *keyword, i
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
val_free = redis_serialize(redis_sock, z_value, &val, &val_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
@@ -3699,9 +3169,7 @@ PHPAPI void generic_z_command(INTERNAL_FUNCTION_PARAMETERS, char *command, int c
RETURN_FALSE;
}
- if(redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
arr_keys_hash = Z_ARRVAL_P(keys_array);
array_keys_count = zend_hash_num_elements(arr_keys_hash);
@@ -3863,9 +3331,7 @@ generic_hset(INTERNAL_FUNCTION_PARAMETERS, char *kw, void (*fun)(INTERNAL_FUNCTI
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
val_free = redis_serialize(redis_sock, z_value, &val, &val_len TSRMLS_CC);
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
@@ -3907,9 +3373,8 @@ PHP_METHOD(Redis, hGet)
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
+
int 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);
@@ -3937,9 +3402,7 @@ PHP_METHOD(Redis, hLen)
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
int key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, "HLEN", "s", key, key_len);
@@ -3961,6 +3424,7 @@ generic_hash_command_2(INTERNAL_FUNCTION_PARAMETERS, char *keyword, int keyword_
RedisSock *redis_sock;
char *key = NULL, *cmd, *member;
int key_len, cmd_len, member_len;
+ redis_object *obj;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oss",
&object, redis_ce,
@@ -3969,10 +3433,13 @@ generic_hash_command_2(INTERNAL_FUNCTION_PARAMETERS, char *keyword, int keyword_
return NULL;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- ZVAL_BOOL(return_value, 0);
- return NULL;
- }
+ obj = (redis_object*) zend_object_store_get_object(getThis() TSRMLS_CC);
+ redis_sock = obj->sock;
+ if (!redis_sock) {
+ ZVAL_BOOL(return_value, 0);
+ return NULL;
+ }
+
int 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);
@@ -4019,6 +3486,7 @@ generic_hash_command_1(INTERNAL_FUNCTION_PARAMETERS, char *keyword, int keyword_
RedisSock *redis_sock;
char *key = NULL, *cmd;
int key_len, cmd_len;
+ redis_object *obj;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os",
&object, redis_ce,
@@ -4027,10 +3495,13 @@ generic_hash_command_1(INTERNAL_FUNCTION_PARAMETERS, char *keyword, int keyword_
return NULL;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- ZVAL_BOOL(return_value, 0);
- return NULL;
- }
+ obj = (redis_object*) zend_object_store_get_object(getThis() TSRMLS_CC);
+ redis_sock = obj->sock;
+ if (!redis_sock) {
+ ZVAL_BOOL(return_value, 0);
+ return NULL;
+ }
+
int 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);
@@ -4157,9 +3628,7 @@ PHP_METHOD(Redis, hIncrBy)
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
/* check for validity of numeric string */
i = 0;
@@ -4203,9 +3672,8 @@ PHP_METHOD(Redis, hMget) {
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
+
nb_fields = zend_hash_num_elements(Z_ARRVAL_P(z_array));
if( nb_fields == 0) {
@@ -4291,9 +3759,7 @@ PHP_METHOD(Redis, hMset)
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
ht_hash = Z_ARRVAL_P(z_hash);
@@ -4399,9 +3865,7 @@ PHP_METHOD(Redis, multi)
/* if the flag is activated, send the command, the reply will be "QUEUED" or -ERR */
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
if(multi_value == MULTI || multi_value == PIPELINE) {
redis_sock->mode = multi_value;
@@ -4451,9 +3915,7 @@ PHP_METHOD(Redis, discard)
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
redis_sock->mode = ATOMIC;
@@ -4565,9 +4027,8 @@ PHP_METHOD(Redis, exec)
&object, redis_ce) == FAILURE) {
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+
+ REDIS_FROM_OBJECT(redis_sock, object)
IF_MULTI() {
@@ -4662,9 +4123,8 @@ PHP_METHOD(Redis, pipeline)
}
/* if the flag is activated, send the command, the reply will be "QUEUED" or -ERR */
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
+
redis_sock->mode = PIPELINE;
/*
@@ -4694,9 +4154,7 @@ PHP_METHOD(Redis, publish)
RETURN_NULL();
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
int 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);
@@ -4729,9 +4187,7 @@ PHP_METHOD(Redis, subscribe)
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ REDIS_FROM_OBJECT(redis_sock, object)
arr_hash = Z_ARRVAL_P(array);
array_count = zend_hash_num_elements(arr_hash);
@@ -4890,9 +4346,8 @@ PHP_METHOD(Redis, unsubscribe)
&object, redis_ce, &array) == FAILURE) {
RETURN_FALSE;
}
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+
+ REDIS_FROM_OBJECT(redis_sock, object)
arr_hash = Z_ARRVAL_P(array);
array_count = zend_hash_num_elements(arr_hash);
@@ -4918,204 +4373,599 @@ PHP_METHOD(Redis, unsubscribe)
}
}
- old_cmd = cmd;
- cmd_len = spprintf(&cmd, 0, "UNSUBSCRIBE %s\r\n", cmd);
- efree(old_cmd);
+ old_cmd = cmd;
+ cmd_len = spprintf(&cmd, 0, "UNSUBSCRIBE %s\r\n", cmd);
+ efree(old_cmd);
+
+ if (redis_sock_write(redis_sock, cmd, cmd_len TSRMLS_CC) < 0) {
+ efree(cmd);
+ RETURN_FALSE;
+ }
+ efree(cmd);
+
+ int i = 1;
+ zval *z_tab, **z_channel;
+
+ array_init(return_value);
+
+ while( i <= array_count) {
+ z_tab = redis_sock_read_multibulk_reply_zval(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock);
+
+ if(Z_TYPE_P(z_tab) == IS_ARRAY) {
+ if (zend_hash_index_find(Z_ARRVAL_P(z_tab), 1, (void**)&z_channel) == FAILURE) {
+ RETURN_FALSE;
+ }
+ add_assoc_bool(return_value, Z_STRVAL_PP(z_channel), 1);
+ } else {
+ //error
+ efree(z_tab);
+ RETURN_FALSE;
+ }
+ efree(z_tab);
+ i ++;
+ }
+}
+
+/* {{{ proto string Redis::bgrewriteaof()
+ */
+PHP_METHOD(Redis, bgrewriteaof)
+{
+ char *cmd;
+ int cmd_len = redis_cmd_format_static(&cmd, "BGREWRITEAOF", "");
+ generic_empty_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, cmd, cmd_len);
+
+}
+/* }}} */
+
+/* {{{ proto string Redis::slaveof([host, port])
+ */
+PHP_METHOD(Redis, slaveof)
+{
+ zval *object;
+ RedisSock *redis_sock;
+ char *cmd = "", *host = NULL;
+ int cmd_len, host_len;
+ long port = 6379;
+
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|sl",
+ &object, redis_ce, &host, &host_len, &port) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ REDIS_FROM_OBJECT(redis_sock, object)
+
+ if(host && host_len) {
+ cmd_len = redis_cmd_format_static(&cmd, "SLAVEOF", "sd", host, host_len, (int)port);
+ } else {
+ cmd_len = redis_cmd_format_static(&cmd, "SLAVEOF", "ss", "NO", 2, "ONE", 3);
+ }
+
+ REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len);
+ IF_ATOMIC() {
+ redis_boolean_response(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, NULL, NULL);
+ }
+ REDIS_PROCESS_RESPONSE(redis_boolean_response);
+}
+/* }}} */
+
+/* {{{ proto string Redis::object(key)
+ */
+PHP_METHOD(Redis, object)
+{
+ zval *object;
+ RedisSock *redis_sock;
+ char *cmd = "", *info = NULL, *key = NULL;
+ int cmd_len, info_len, key_len;
+
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oss",
+ &object, redis_ce, &info, &info_len, &key, &key_len) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ REDIS_FROM_OBJECT(redis_sock, object)
+
+ cmd_len = redis_cmd_format_static(&cmd, "OBJECT", "ss", info, info_len, key, key_len);
+ REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len);
+
+ if(info_len == 8 && (strncasecmp(info, "refcount", 8) == 0 || strncasecmp(info, "idletime", 8) == 0)) {
+ IF_ATOMIC() {
+ redis_long_response(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, NULL, NULL);
+ }
+ REDIS_PROCESS_RESPONSE(redis_long_response);
+ } else if(info_len == 8 && strncasecmp(info, "encoding", 8) == 0) {
+ IF_ATOMIC() {
+ redis_string_response(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, NULL, NULL);
+ }
+ REDIS_PROCESS_RESPONSE(redis_string_response);
+ } else { /* fail */
+ IF_ATOMIC() {
+ redis_boolean_response(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, NULL, NULL);
+ }
+ REDIS_PROCESS_RESPONSE(redis_boolean_response);
+ }
+}
+/* }}} */
+
+/* {{{ proto string Redis::getOption($option)
+ */
+PHP_METHOD(Redis, getOption) {
+ RedisSock *redis_sock;
+ zval *object;
+ long option;
+
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol",
+ &object, redis_ce, &option) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ REDIS_FROM_OBJECT(redis_sock, object)
+
+ switch(option) {
+
+ case REDIS_OPT_SERIALIZER:
+ RETURN_LONG(redis_sock->serializer);
+
+ case REDIS_OPT_PREFIX:
+ if(redis_sock->prefix) {
+ RETURN_STRINGL(redis_sock->prefix, redis_sock->prefix_len, 1);
+ }
+ RETURN_NULL();
+
+ default:
+ RETURN_FALSE;
+
+ }
+}
+/* }}} */
+
+/* {{{ proto string Redis::setOption(string $option, mixed $value)
+ */
+PHP_METHOD(Redis, setOption) {
+ RedisSock *redis_sock;
+ zval *object;
+ long option, val_long;
+ char *val_str;
+ int val_len;
+
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ols",
+ &object, redis_ce, &option, &val_str, &val_len) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ REDIS_FROM_OBJECT(redis_sock, object)
+
+ switch(option) {
+ case REDIS_OPT_SERIALIZER:
+ val_long = atol(val_str);
+ if(val_long == REDIS_SERIALIZER_NONE || val_long == REDIS_SERIALIZER_IGBINARY || val_long == REDIS_SERIALIZER_PHP) {
+ redis_sock->serializer = val_long;
+ RETURN_TRUE;
+ } else {
+ RETURN_FALSE;
+ }
+ break;
+
+ case REDIS_OPT_PREFIX:
+ if (redis_sock->prefix) {
+ efree(redis_sock->prefix);
+ }
+ if (val_len == 0) {
+ redis_sock->prefix = NULL;
+ redis_sock->prefix_len = 0;
+ } else {
+ redis_sock->prefix_len = val_len;
+ redis_sock->prefix = estrndup(val_str, val_len);
+ }
+ RETURN_TRUE;
+
+ default:
+ RETURN_FALSE;
+ }
+}
+/* }}} */
+
+/* {{{ proto Redis Redis::__construct()
+ Public constructor */
+PHP_METHOD(Redis, __construct)
+{
+ if (zend_parse_parameters_none() == FAILURE) {
+ RETURN_FALSE;
+ }
+}
+/* }}} */
+
+/* {{{ proto boolean Redis::connect(string host, int port [, double timeout])
+ */
+PHP_METHOD(Redis, connect)
+{
+ if (redis_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0) == FAILURE) {
+ RETURN_FALSE;
+ } else {
+ RETURN_TRUE;
+ }
+}
+/* }}} */
+
+/* {{{ proto boolean Redis::pconnect(string host, int port [, double timeout])
+ */
+PHP_METHOD(Redis, pconnect)
+{
+ if (redis_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1) == FAILURE) {
+ RETURN_FALSE;
+ } else {
+ RETURN_TRUE;
+ }
+}
+/* }}} */
+
+ZEND_DECLARE_MODULE_GLOBALS(redis)
+
+static zend_function_entry redis_functions[] = {
+ PHP_ME(Redis, __construct, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, connect, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, pconnect, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, close, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, ping, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, get, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, set, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, setex, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, setnx, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, getSet, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, randomKey, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, renameKey, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, renameNx, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, getMultiple, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, exists, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, delete, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, incr, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, incrBy, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, decr, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, decrBy, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, type, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, append, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, getRange, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, setRange, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, getBit, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, setBit, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, strlen, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, getKeys, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, sort, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, sortAsc, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, sortAscAlpha, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, sortDesc, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, sortDescAlpha, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, lPush, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, rPush, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, lPushx, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, rPushx, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, lPop, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, rPop, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, blPop, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, brPop, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, lSize, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, lRemove, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, listTrim, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, lGet, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, lGetRange, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, lSet, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, lInsert, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, sAdd, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, sSize, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, sRemove, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, sMove, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, sPop, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, sRandMember, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, sContains, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, sMembers, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, sInter, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, sInterStore, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, sUnion, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, sUnionStore, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, sDiff, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, sDiffStore, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, setTimeout, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, save, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, bgSave, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, lastSave, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, flushDB, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, flushAll, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, dbSize, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, auth, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, ttl, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, persist, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, info, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, select, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, move, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, bgrewriteaof, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, slaveof, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, object, NULL, ZEND_ACC_PUBLIC)
+
+ /* 1.1 */
+ PHP_ME(Redis, mset, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, msetnx, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, rpoplpush, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, brpoplpush, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, zAdd, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, zDelete, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, zRange, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, zReverseRange, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, zRangeByScore, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, zRevRangeByScore, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, zCount, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, zDeleteRangeByScore, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, zDeleteRangeByRank, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, zCard, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, zScore, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, zRank, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, zRevRank, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, zInter, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, zUnion, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, zIncrBy, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, expireAt, NULL, ZEND_ACC_PUBLIC)
+
+ /* 1.2 */
+ PHP_ME(Redis, hGet, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, hSet, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, hSetNx, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, hDel, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, hLen, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, hKeys, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, hVals, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, hGetAll, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, hExists, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, hIncrBy, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, hMset, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, hMget, NULL, ZEND_ACC_PUBLIC)
+
+ PHP_ME(Redis, multi, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, discard, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, exec, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, pipeline, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, watch, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, unwatch, NULL, ZEND_ACC_PUBLIC)
+
+ PHP_ME(Redis, publish, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, subscribe, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, unsubscribe, NULL, ZEND_ACC_PUBLIC)
+
+ /* options */
+ PHP_ME(Redis, getOption, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, setOption, NULL, ZEND_ACC_PUBLIC)
+
+ /* aliases */
+ PHP_MALIAS(Redis, open, connect, NULL, ZEND_ACC_PUBLIC)
+ PHP_MALIAS(Redis, popen, pconnect, NULL, ZEND_ACC_PUBLIC)
+ PHP_MALIAS(Redis, lLen, lSize, NULL, ZEND_ACC_PUBLIC)
+ PHP_MALIAS(Redis, sGetMembers, sMembers, NULL, ZEND_ACC_PUBLIC)
+ PHP_MALIAS(Redis, mget, getMultiple, NULL, ZEND_ACC_PUBLIC)
+ PHP_MALIAS(Redis, expire, setTimeout, NULL, ZEND_ACC_PUBLIC)
+ PHP_MALIAS(Redis, zunionstore, zUnion, NULL, ZEND_ACC_PUBLIC)
+ PHP_MALIAS(Redis, zinterstore, zInter, NULL, ZEND_ACC_PUBLIC)
+
+ PHP_MALIAS(Redis, zRemove, zDelete, NULL, ZEND_ACC_PUBLIC)
+ PHP_MALIAS(Redis, zRem, zDelete, NULL, ZEND_ACC_PUBLIC)
+ PHP_MALIAS(Redis, zRemoveRangeByScore, zDeleteRangeByScore, NULL, ZEND_ACC_PUBLIC)
+ PHP_MALIAS(Redis, zRemRangeByScore, zDeleteRangeByScore, NULL, ZEND_ACC_PUBLIC)
+ PHP_MALIAS(Redis, zRemRangeByRank, zDeleteRangeByRank, NULL, ZEND_ACC_PUBLIC)
+ PHP_MALIAS(Redis, zSize, zCard, NULL, ZEND_ACC_PUBLIC)
+ PHP_MALIAS(Redis, substr, getRange, NULL, ZEND_ACC_PUBLIC)
+ PHP_MALIAS(Redis, rename, renameKey, NULL, ZEND_ACC_PUBLIC)
+ PHP_MALIAS(Redis, del, delete, NULL, ZEND_ACC_PUBLIC)
+ PHP_MALIAS(Redis, keys, getKeys, NULL, ZEND_ACC_PUBLIC)
+ PHP_MALIAS(Redis, lrem, lRemove, NULL, ZEND_ACC_PUBLIC)
+ PHP_MALIAS(Redis, ltrim, listTrim, NULL, ZEND_ACC_PUBLIC)
+ PHP_MALIAS(Redis, lindex, lGet, NULL, ZEND_ACC_PUBLIC)
+ PHP_MALIAS(Redis, lrange, lGetRange, NULL, ZEND_ACC_PUBLIC)
+ PHP_MALIAS(Redis, scard, sSize, NULL, ZEND_ACC_PUBLIC)
+ PHP_MALIAS(Redis, srem, sRemove, NULL, ZEND_ACC_PUBLIC)
+ PHP_MALIAS(Redis, sismember, sContains, NULL, ZEND_ACC_PUBLIC)
+ PHP_MALIAS(Redis, zrevrange, zReverseRange, NULL, ZEND_ACC_PUBLIC)
+ {NULL, NULL, NULL}
+};
+
+zend_module_entry redis_module_entry = {
+#if ZEND_MODULE_API_NO >= 20010901
+ STANDARD_MODULE_HEADER,
+#endif
+ "redis",
+ NULL,
+ PHP_MINIT(redis),
+ NULL,
+ NULL,
+ NULL,
+ PHP_MINFO(redis),
+#if ZEND_MODULE_API_NO >= 20010901
+ PHP_REDIS_VERSION,
+#endif
+ STANDARD_MODULE_PROPERTIES
+};
+
+#ifdef COMPILE_DL_REDIS
+ZEND_GET_MODULE(redis)
+#endif
+
+PHPAPI zend_class_entry *redis_get_exception_base(int root TSRMLS_DC)
+{
+#if HAVE_SPL
+ if (!root) {
+ if (!spl_ce_RuntimeException) {
+ zend_class_entry **pce;
+
+ if (zend_hash_find(CG(class_table), "runtimeexception",
+ sizeof("RuntimeException"), (void **) &pce) == SUCCESS) {
+ spl_ce_RuntimeException = *pce;
+ return *pce;
+ }
+ } else {
+ return spl_ce_RuntimeException;
+ }
+ }
+#endif
+#if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 2)
+ return zend_exception_get_default();
+#else
+ return zend_exception_get_default(TSRMLS_C);
+#endif
+}
+
+/**
+ * redis_destructor_redis_sock
+ */
+static void redis_destructor_redis_sock(zend_rsrc_list_entry * rsrc TSRMLS_DC)
+{
+ RedisSock *redis_sock = (RedisSock *) rsrc->ptr;
+ redis_sock_disconnect(redis_sock TSRMLS_CC);
+ redis_free_socket(redis_sock);
+}
- if (redis_sock_write(redis_sock, cmd, cmd_len TSRMLS_CC) < 0) {
- efree(cmd);
- RETURN_FALSE;
- }
- efree(cmd);
+static zend_object_handlers redis_object_handlers;
- int i = 1;
- zval *z_tab, **z_channel;
+static zend_object_value redis_object_new(zend_class_entry *class_type TSRMLS_DC)
+{
+ redis_object *intern;
+ zend_object_value retval;
+ zval *tmp;
- array_init(return_value);
+ intern = emalloc(sizeof(redis_object));
+ memset(intern, 0, sizeof(redis_object));
- while( i <= array_count) {
- z_tab = redis_sock_read_multibulk_reply_zval(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock);
+ zend_object_std_init(&intern->std, class_type TSRMLS_CC);
+#ifdef ZEND_ENGINE_2_4
+ object_properties_init(&intern->std, class_type);
+#else
+ zend_hash_copy(intern->std.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
+#endif
- if(Z_TYPE_P(z_tab) == IS_ARRAY) {
- if (zend_hash_index_find(Z_ARRVAL_P(z_tab), 1, (void**)&z_channel) == FAILURE) {
- RETURN_FALSE;
- }
- add_assoc_bool(return_value, Z_STRVAL_PP(z_channel), 1);
- } else {
- //error
- efree(z_tab);
- RETURN_FALSE;
- }
- efree(z_tab);
- i ++;
- }
+ (&retval)->handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t) zend_objects_free_object_storage, NULL TSRMLS_CC);
+ (&retval)->handlers = &redis_object_handlers;
+
+ return retval;
}
-/* {{{ proto string Redis::bgrewriteaof()
+/**
+ * PHP_MINIT_FUNCTION
*/
-PHP_METHOD(Redis, bgrewriteaof)
+PHP_MINIT_FUNCTION(redis)
{
- char *cmd;
- int cmd_len = redis_cmd_format_static(&cmd, "BGREWRITEAOF", "");
- generic_empty_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, cmd, cmd_len);
+ zend_class_entry redis_class_entry;
-}
-/* }}} */
+ INIT_CLASS_ENTRY(redis_class_entry, "Redis", redis_functions);
+ redis_class_entry.create_object = redis_object_new;
+ redis_ce = zend_register_internal_class_ex(&redis_class_entry, NULL, NULL TSRMLS_CC);
+ memcpy(&redis_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
-/* {{{ proto string Redis::slaveof([host, port])
- */
-PHP_METHOD(Redis, slaveof)
-{
- zval *object;
- RedisSock *redis_sock;
- char *cmd = "", *host = NULL;
- int cmd_len, host_len;
- long port = 6379;
+ 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,
+ redis_get_exception_base(0 TSRMLS_CC),
+ NULL TSRMLS_CC
+ );
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|sl",
- &object, redis_ce, &host, &host_len, &port) == FAILURE) {
- RETURN_FALSE;
- }
- if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
- RETURN_FALSE;
- }
+ le_redis_sock = zend_register_list_destructors_ex(
+ redis_destructor_redis_sock,
+ NULL,
+ redis_sock_name, module_number
+ );
- if(host && host_len) {
- cmd_len = redis_cmd_format_static(&cmd, "SLAVEOF", "sd", host, host_len, (int)port);
- } else {
- cmd_len = redis_cmd_format_static(&cmd, "SLAVEOF", "ss", "NO", 2, "ONE", 3);
- }
+ add_constant_long(redis_ce, "REDIS_NOT_FOUND", REDIS_NOT_FOUND);
+ add_constant_long(redis_ce, "REDIS_STRING", REDIS_STRING);
+ add_constant_long(redis_ce, "REDIS_SET", REDIS_SET);
+ add_constant_long(redis_ce, "REDIS_LIST", REDIS_LIST);
+ add_constant_long(redis_ce, "REDIS_ZSET", REDIS_ZSET);
+ add_constant_long(redis_ce, "REDIS_HASH", REDIS_HASH);
- REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len);
- IF_ATOMIC() {
- redis_boolean_response(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, NULL, NULL);
- }
- REDIS_PROCESS_RESPONSE(redis_boolean_response);
-}
-/* }}} */
+ add_constant_long(redis_ce, "ATOMIC", ATOMIC);
+ add_constant_long(redis_ce, "MULTI", MULTI);
+ add_constant_long(redis_ce, "PIPELINE", PIPELINE);
-/* {{{ proto string Redis::object(key)
- */
-PHP_METHOD(Redis, object)
-{
- zval *object;
- RedisSock *redis_sock;
- char *cmd = "", *info = NULL, *key = NULL;