Skip to content

Commit b15e78b

Browse files
committed
Merge branch 'edlerd-master'
2 parents 87dfaf4 + 8edc96e commit b15e78b

File tree

3 files changed

+74
-1
lines changed

3 files changed

+74
-1
lines changed

README.markdown

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2304,7 +2304,7 @@ $redis->hIncrBy('user:1', 'salary', 100); // Joe earns 100 more now.
23042304

23052305
## hMGet
23062306
##### Description
2307-
Retirieve the values associated to the specified fields in the hash.
2307+
Retrieve the values associated to the specified fields in the hash.
23082308
##### Parameters
23092309
*key*
23102310
*memberKeys* Array
@@ -2317,3 +2317,19 @@ $redis->hSet('h', 'field1', 'value1');
23172317
$redis->hSet('h', 'field2', 'value2');
23182318
$redis->hmGet('h', array('field1', 'field2')); /* returns array('field1' => 'value1', 'field2' => 'value2') */
23192319
</pre>
2320+
2321+
## config
2322+
##### Description
2323+
Get or Set the redis config keys.
2324+
##### Parameters
2325+
*operation* (string) either `GET` or `SET`
2326+
*key* string for `SET`, glob-pattern for `GET`. See http://redis.io/commands/config-get for examples.
2327+
*value* optional string (only for `SET`)
2328+
##### Return value
2329+
*Associative array* for `GET`, key -> value
2330+
*bool* for `SET`
2331+
##### Examples
2332+
<pre>
2333+
$redis->config("GET", "*max-*-entries*");
2334+
$redis->config("SET", "dir", "/var/run/redis/dumps/");
2335+
</pre>

php_redis.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ PHP_METHOD(Redis, unsubscribe);
153153
PHP_METHOD(Redis, getOption);
154154
PHP_METHOD(Redis, setOption);
155155

156+
PHP_METHOD(Redis, config);
157+
156158
#ifdef PHP_WIN32
157159
#define PHP_REDIS_API __declspec(dllexport)
158160
#else

redis.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ static zend_function_entry redis_functions[] = {
202202
PHP_ME(Redis, getOption, NULL, ZEND_ACC_PUBLIC)
203203
PHP_ME(Redis, setOption, NULL, ZEND_ACC_PUBLIC)
204204

205+
/* config */
206+
PHP_ME(Redis, config, NULL, ZEND_ACC_PUBLIC)
207+
205208
/* aliases */
206209
PHP_MALIAS(Redis, open, connect, NULL, ZEND_ACC_PUBLIC)
207210
PHP_MALIAS(Redis, popen, pconnect, NULL, ZEND_ACC_PUBLIC)
@@ -5268,5 +5271,57 @@ PHP_METHOD(Redis, setOption) {
52685271
}
52695272
/* }}} */
52705273

5274+
/* {{{ proto boolean Redis::config(string op, string key [, mixed value])
5275+
*/
5276+
PHP_METHOD(Redis, config)
5277+
{
5278+
zval *object;
5279+
RedisSock *redis_sock;
5280+
char *key = NULL, *val = NULL, *cmd, *op = NULL;
5281+
int key_len, val_len, cmd_len, op_len;
5282+
enum {CFG_GET, CFG_SET} mode;
5283+
5284+
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oss|s",
5285+
&object, redis_ce, &op, &op_len, &key, &key_len,
5286+
&val, &val_len) == FAILURE) {
5287+
RETURN_FALSE;
5288+
}
5289+
5290+
/* op must be GET or SET */
5291+
if(strncasecmp(op, "GET", 3) == 0) {
5292+
mode = CFG_GET;
5293+
} else if(strncasecmp(op, "SET", 3) == 0) {
5294+
mode = CFG_SET;
5295+
} else {
5296+
RETURN_FALSE;
5297+
}
5298+
5299+
if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
5300+
RETURN_FALSE;
5301+
}
5302+
5303+
if (mode == CFG_GET && val == NULL) {
5304+
cmd_len = redis_cmd_format_static(&cmd, "CONFIG", "ss", op, op_len, key, key_len);
5305+
5306+
REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len)
5307+
IF_ATOMIC() {
5308+
redis_sock_read_multibulk_reply_zipped_strings(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, NULL, NULL);
5309+
}
5310+
REDIS_PROCESS_RESPONSE(redis_sock_read_multibulk_reply_zipped_strings);
5311+
5312+
} else if(mode == CFG_SET && val != NULL) {
5313+
cmd_len = redis_cmd_format_static(&cmd, "CONFIG", "sss", op, op_len, key, key_len, val, val_len);
5314+
5315+
REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len)
5316+
IF_ATOMIC() {
5317+
redis_boolean_response(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, NULL, NULL);
5318+
}
5319+
REDIS_PROCESS_RESPONSE(redis_boolean_response);
5320+
} else {
5321+
RETURN_FALSE;
5322+
}
5323+
}
5324+
/* }}} */
5325+
52715326
/* vim: set tabstop=4 softtabstop=4 noexpandtab shiftwidth=4: */
52725327

0 commit comments

Comments
 (0)