diff options
author | michael-grunder <michael.grunder@gmail.com> | 2014-06-08 07:37:23 +0400 |
---|---|---|
committer | michael-grunder <michael.grunder@gmail.com> | 2015-05-06 00:41:33 +0300 |
commit | 711950df9dc4a424bb0b9d2ce4dc09c8ea75573d (patch) | |
tree | 1b11a925723896a87609e4d4d7d3d778e9f8c704 /redis_cluster.c | |
parent | 6534d933e1c12e4389de174dea09107838b768fd (diff) |
SRANDMEMBER
Implemented SRANDMEMBER command for Redis and RedisCluster
Diffstat (limited to 'redis_cluster.c')
-rw-r--r-- | redis_cluster.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/redis_cluster.c b/redis_cluster.c index 2cf77bce..e5675374 100644 --- a/redis_cluster.c +++ b/redis_cluster.c @@ -62,6 +62,7 @@ zend_function_entry redis_cluster_functions[] = { PHP_ME(RedisCluster, scard, NULL, ZEND_ACC_PUBLIC) PHP_ME(RedisCluster, smembers, NULL, ZEND_ACC_PUBLIC) PHP_ME(RedisCluster, sismember, NULL, ZEND_ACC_PUBLIC) + PHP_ME(RedisCluster, srandmember, NULL, ZEND_ACC_PUBLIC) PHP_ME(RedisCluster, strlen, NULL, ZEND_ACC_PUBLIC) PHP_ME(RedisCluster, persist, NULL, ZEND_ACC_PUBLIC) PHP_ME(RedisCluster, ttl, NULL, ZEND_ACC_PUBLIC) @@ -361,6 +362,35 @@ PHP_METHOD(RedisCluster, spop) { } /* }}} */ +/* {{{ proto string|array RedisCluster::srandmember(string key, [long count]) */ +PHP_METHOD(RedisCluster, srandmember) { + redisCluster *c = GET_CONTEXT(); + char *cmd; int cmd_len; short slot; + short have_count; + + if(redis_srandmember_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, c->flags, + &cmd, &cmd_len, &slot, NULL, &have_count) + ==FAILURE) + { + RETURN_FALSE; + } + + if(cluster_send_command(c,slot,cmd,cmd_len TSRMLS_CC)<0 || c->err!=NULL) { + efree(cmd); + RETURN_FALSE; + } + + // Clean up command + efree(cmd); + + // Response type differs if we use WITHSCORES or not + if(have_count) { + cluster_mbulk_resp(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, NULL); + } else { + cluster_bulk_resp(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, NULL); + } +} + /* {{{ proto string RedisCluster::strlen(string key) */ PHP_METHOD(RedisCluster, strlen) { CLUSTER_PROCESS_KW_CMD("STRLEN", redis_key_cmd, cluster_bulk_resp); |