Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpredis/phpredis.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormichael-grunder <michael.grunder@gmail.com>2014-06-07 20:41:31 +0400
committermichael-grunder <michael.grunder@gmail.com>2015-05-06 00:38:07 +0300
commit21f666e435509fa3783451e7b9e9719b370362a5 (patch)
treee89d7fdd1d1f2df790fec25a8ed2586a645b2450
parent01d312f42789475ca6184e427b55c3c46937c048 (diff)
Rework no arg commands, remove non-redis method
Each of the commands that take no arguments can be reworked such that they use the new calling convention in Redis proper Impelemnted BITPOS Removed Redis::resetStat. This isn't a Redis method, but rather an option on CONFIG, and it probably should be called that way.
-rw-r--r--php_redis.h1
-rw-r--r--redis.c143
-rw-r--r--redis_commands.c41
3 files changed, 52 insertions, 133 deletions
diff --git a/php_redis.h b/php_redis.h
index 94bec033..2c35c822 100644
--- a/php_redis.h
+++ b/php_redis.h
@@ -103,7 +103,6 @@ PHP_METHOD(Redis, ttl);
PHP_METHOD(Redis, pttl);
PHP_METHOD(Redis, persist);
PHP_METHOD(Redis, info);
-PHP_METHOD(Redis, resetStat);
PHP_METHOD(Redis, select);
PHP_METHOD(Redis, move);
PHP_METHOD(Redis, zAdd);
diff --git a/redis.c b/redis.c
index 91c5aaa1..e3070a7d 100644
--- a/redis.c
+++ b/redis.c
@@ -176,7 +176,6 @@ static zend_function_entry redis_functions[] = {
PHP_ME(Redis, pttl, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Redis, persist, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Redis, info, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Redis, resetStat, 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)
@@ -858,53 +857,7 @@ PHP_METHOD(Redis, bitcount)
/* {{{ proto integer Redis::bitpos(string key, int bit, [int start], [int end]) */
PHP_METHOD(Redis, bitpos)
{
- zval *object;
- RedisSock *redis_sock;
- char *key, *cmd;
- int key_len, cmd_len, argc, key_free=0;
- long bit, start, end;
-
- argc = ZEND_NUM_ARGS();
-
- if(zend_parse_method_parameters(argc TSRMLS_CC, getThis(), "Osl|ll",
- &object, redis_ce, &key, &key_len, &bit,
- &start, &end)==FAILURE)
- {
- RETURN_FALSE;
- }
-
- if(redis_sock_get(object, &redis_sock TSRMLS_CC, 0) < 0) {
- RETURN_FALSE;
- }
-
- /* We can prevalidate the first argument */
- if(bit != 0 && bit != 1) {
- RETURN_FALSE;
- }
-
- /* Prefix our key */
- key_free = redis_key_prefix(redis_sock, &key, &key_len);
-
- /* Various command semantics */
- if(argc == 2) {
- cmd_len = redis_cmd_format_static(&cmd, "BITPOS", "sd", key, key_len,
- bit);
- } else if(argc == 3) {
- cmd_len = redis_cmd_format_static(&cmd, "BITPOS", "sdd", key, key_len,
- bit, start);
- } else {
- cmd_len = redis_cmd_format_static(&cmd, "BITPOS", "sddd", key, key_len,
- bit, start, end);
- }
-
- /* Free our key if it was prefixed */
- if(key_free) efree(key);
-
- REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len);
- IF_ATOMIC() {
- redis_long_response(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, NULL, NULL);
- }
- REDIS_PROCESS_RESPONSE(redis_long_response);
+ REDIS_PROCESS_CMD(bitpos, redis_long_response);
}
/* }}} */
@@ -961,6 +914,7 @@ PHP_METHOD(Redis, setnx)
}
/* }}} */
+
/* {{{ proto string Redis::getSet(string key, string value)
*/
PHP_METHOD(Redis, getSet)
@@ -1276,9 +1230,7 @@ PHP_REDIS_API void redis_unwatch_response(INTERNAL_FUNCTION_PARAMETERS, RedisSoc
*/
PHP_METHOD(Redis, unwatch)
{
- char cmd[] = "*1" _NL "$7" _NL "UNWATCH" _NL;
- generic_empty_cmd_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, estrdup(cmd), sizeof(cmd)-1, redis_unwatch_response);
-
+ REDIS_PROCESS_KW_CMD("UNWATCH", redis_empty_cmd, redis_unwatch_response);
}
/* }}} */
@@ -2593,38 +2545,11 @@ PHP_METHOD(Redis, lSet) {
}
/* }}} */
-PHP_REDIS_API void generic_empty_cmd_impl(INTERNAL_FUNCTION_PARAMETERS, char *cmd, int cmd_len, ResultCallback result_callback) {
- zval *object;
- RedisSock *redis_sock;
-
- 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) < 0) {
- RETURN_FALSE;
- }
-
- REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len);
- IF_ATOMIC() {
- result_callback(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, NULL, NULL);
- }
- REDIS_PROCESS_RESPONSE(result_callback);
-}
-
-PHP_REDIS_API void generic_empty_cmd(INTERNAL_FUNCTION_PARAMETERS, char *cmd, int cmd_len, ...) {
- generic_empty_cmd_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, cmd, cmd_len, redis_boolean_response);
-}
-
/* {{{ proto string Redis::save()
*/
PHP_METHOD(Redis, save)
{
- char *cmd;
- int cmd_len = redis_cmd_format_static(&cmd, "SAVE", "");
- generic_empty_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, cmd, cmd_len);
-
+ REDIS_PROCESS_KW_CMD("SAVE", redis_empty_cmd, redis_boolean_response);
}
/* }}} */
@@ -2632,52 +2557,23 @@ PHP_METHOD(Redis, save)
*/
PHP_METHOD(Redis, bgSave)
{
- char *cmd;
- int cmd_len = redis_cmd_format_static(&cmd, "BGSAVE", "");
- generic_empty_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, cmd, cmd_len);
-
+ REDIS_PROECSS_KW_CMD("BGSAVE", redis_empty_cmd, redis_boolean_response);
}
/* }}} */
-PHP_REDIS_API void generic_empty_long_cmd(INTERNAL_FUNCTION_PARAMETERS, char *cmd, int cmd_len, ...) {
-
- zval *object;
- RedisSock *redis_sock;
-
- 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) < 0) {
- RETURN_FALSE;
- }
-
- REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len);
- IF_ATOMIC() {
- redis_long_response(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, NULL, NULL);
- }
- REDIS_PROCESS_RESPONSE(redis_long_response);
-}
-
/* {{{ proto integer Redis::lastSave()
*/
PHP_METHOD(Redis, lastSave)
{
- char *cmd;
- int cmd_len = redis_cmd_format_static(&cmd, "LASTSAVE", "");
- generic_empty_long_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, cmd, cmd_len);
+ REDIS_PROCESS_KW_CMD("LASTSAVE", redis_empty_cmd, redis_long_response);
}
/* }}} */
-
/* {{{ proto bool Redis::flushDB()
*/
PHP_METHOD(Redis, flushDB)
{
- char *cmd;
- int cmd_len = redis_cmd_format_static(&cmd, "FLUSHDB", "");
- generic_empty_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, cmd, cmd_len);
+ REDIS_PROCESS_KW_CMD("FLUSHDB", redis_empty_cmd, redis_boolean_response);
}
/* }}} */
@@ -2685,9 +2581,7 @@ PHP_METHOD(Redis, flushDB)
*/
PHP_METHOD(Redis, flushAll)
{
- char *cmd;
- int cmd_len = redis_cmd_format_static(&cmd, "FLUSHALL", "");
- generic_empty_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, cmd, cmd_len);
+ REDIS_PROCESS_KW_CMD("FLUSHALL", redis_empty_cmd, redis_boolean_response);
}
/* }}} */
@@ -2695,9 +2589,7 @@ PHP_METHOD(Redis, flushAll)
*/
PHP_METHOD(Redis, dbSize)
{
- char *cmd;
- int cmd_len = redis_cmd_format_static(&cmd, "DBSIZE", "");
- generic_empty_long_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, cmd, cmd_len);
+ REDIS_PROCESS_KW_CMD("DBSIZE", redis_empty_cmd, redis_long_response);
}
/* }}} */
@@ -2792,17 +2684,6 @@ PHP_METHOD(Redis, info) {
}
/* }}} */
-/* {{{ proto string Redis::resetStat()
- */
-PHP_METHOD(Redis, resetStat)
-{
- char *cmd;
- int cmd_len = redis_cmd_format_static(&cmd, "CONFIG", "s",
- "RESETSTAT", 9);
- generic_empty_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, cmd, cmd_len);
-}
-/* }}} */
-
/* {{{ proto bool Redis::select(long dbNumber)
*/
PHP_METHOD(Redis, select) {
@@ -4422,10 +4303,8 @@ PHP_METHOD(Redis, punsubscribe)
*/
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);
-
+ REDIS_PROCESS_KW_CMD("BGREWRITEAOF", redis_empty_cmd,
+ redis_boolean_response);
}
/* }}} */
diff --git a/redis_commands.c b/redis_commands.c
index c824e282..55e8e91d 100644
--- a/redis_commands.c
+++ b/redis_commands.c
@@ -669,4 +669,45 @@ int redis_hmset_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
return SUCCESS;
}
+/* BITPOS */
+int redis_bitpos_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
+ char **cmd, int *cmd_len, short *slot, void **ctx)
+{
+ char *key;
+ int argc, key_len, key_free;
+ long bit, start, end;
+
+ argc = ZEND_NUM_ARGS();
+ if(zend_parse_parameters(argc TSRMLS_CC, "sl|ll", &key, &key_len, &bit,
+ &start, &end)==FAILURE)
+ {
+ return FAILURE;
+ }
+
+ // Prevalidate bit
+ if(bit != 0 && bit != 1) {
+ return FAILURE;
+ }
+
+ // Prefix key
+ key_free = redis_key_prefix(redis_sock, &key, &key_len);
+
+ // Construct command based on arg count
+ if(argc == 2) {
+ *cmd_len = redis_cmd_format_static(cmd, "BITPOS", "sd", key, key_len,
+ bit);
+ } else if(argc == 3) {
+ *cmd_len = redis_cmd_format_static(cmd, "BITPOS", "sdd", key, key_len,
+ bit, start);
+ } else {
+ *cmd_len = redis_cmd_format_static(cmd, "BITPOS", "sddd", key, key_len,
+ bit, start, end);
+ }
+
+ // Set our slot
+ CMD_SET_SLOT(slot, key, key_len);
+
+ return SUCCESS;
+}
+
/* vim: set tabstop=4 softtabstops=4 noexpandtab shiftwidth=4: */