Skip to content

Commit

Permalink
add config function
Browse files Browse the repository at this point in the history
  • Loading branch information
David Edler committed Dec 29, 2011
1 parent c6672f0 commit ccc824a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
2 changes: 2 additions & 0 deletions php_redis.h
Expand Up @@ -153,6 +153,8 @@ PHP_METHOD(Redis, unsubscribe);
PHP_METHOD(Redis, getOption);
PHP_METHOD(Redis, setOption);

PHP_METHOD(Redis, config);

#ifdef PHP_WIN32
#define PHP_REDIS_API __declspec(dllexport)
#else
Expand Down
47 changes: 47 additions & 0 deletions redis.c
Expand Up @@ -202,6 +202,9 @@ static zend_function_entry redis_functions[] = {
PHP_ME(Redis, getOption, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Redis, setOption, NULL, ZEND_ACC_PUBLIC)

/* config */
PHP_ME(Redis, config, NULL, ZEND_ACC_PUBLIC)

/* aliases */
PHP_MALIAS(Redis, open, connect, NULL, ZEND_ACC_PUBLIC)
PHP_MALIAS(Redis, popen, pconnect, NULL, ZEND_ACC_PUBLIC)
Expand Down Expand Up @@ -5268,5 +5271,49 @@ PHP_METHOD(Redis, setOption) {
}
/* }}} */

/* {{{ proto boolean Redis::config(string operation, string key [, mixed value])
*/
PHP_METHOD(Redis, config)
{
zval *object;
RedisSock *redis_sock;
char *key = NULL, *val = NULL, *cmd, *operation = NULL;
int key_len, val_len, cmd_len, operation_len;
int val_free = 0, key_free = 0;
zval *z_value = NULL;
long expire = -1;

if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oss|z",
&object, redis_ce, &operation, &operation_len, &key, &key_len,
&z_value) == FAILURE) {
RETURN_FALSE;
}

if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
RETURN_FALSE;
}

key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);

if (z_value == NULL) {
cmd_len = redis_cmd_format_static(&cmd, "CONFIG", "ss", operation, operation_len, key, key_len);
}
else {
val_free = redis_serialize(redis_sock, z_value, &val, &val_len TSRMLS_CC);
cmd_len = redis_cmd_format_static(&cmd, "CONFIG", "sss", operation, operation_len, 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);
}
/* }}} */

/* vim: set tabstop=4 softtabstop=4 noexpandtab shiftwidth=4: */

0 comments on commit ccc824a

Please sign in to comment.