diff options
-rw-r--r-- | common.h | 1 | ||||
-rw-r--r-- | library.c | 2 | ||||
-rw-r--r-- | redis.c | 1 | ||||
-rw-r--r-- | tests/RedisTest.php | 94 |
4 files changed, 56 insertions, 42 deletions
@@ -33,6 +33,7 @@ #define REDIS_LIST 3 #define REDIS_ZSET 4 #define REDIS_HASH 5 +#define REDIS_STREAM 6 #ifdef PHP_WIN32 #define PHP_REDIS_API __declspec(dllexport) @@ -807,6 +807,8 @@ PHP_REDIS_API void redis_type_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock * l = REDIS_ZSET; } else if (strncmp(response, "+hash", 5) == 0){ l = REDIS_HASH; + } else if (strncmp(response, "+stream", 7) == 0) { + l = REDIS_STREAM; } else { l = REDIS_NOT_FOUND; } @@ -649,6 +649,7 @@ static void add_class_constants(zend_class_entry *ce, int is_cluster TSRMLS_DC) zend_declare_class_constant_long(ce, ZEND_STRL("REDIS_LIST"), REDIS_LIST TSRMLS_CC); zend_declare_class_constant_long(ce, ZEND_STRL("REDIS_ZSET"), REDIS_ZSET TSRMLS_CC); zend_declare_class_constant_long(ce, ZEND_STRL("REDIS_HASH"), REDIS_HASH TSRMLS_CC); + zend_declare_class_constant_long(ce, ZEND_STRL("REDIS_STREAM"), REDIS_STREAM TSRMLS_CC); /* Cluster doesn't support pipelining at this time */ if(!is_cluster) { diff --git a/tests/RedisTest.php b/tests/RedisTest.php index a865ffd7..9f92c780 100644 --- a/tests/RedisTest.php +++ b/tests/RedisTest.php @@ -696,47 +696,57 @@ class Redis_Test extends TestSuite public function testType() { - // 0 => none, (key didn't exist) - // 1=> string, - // 2 => set, - // 3 => list, - // 4 => zset, - // 5 => hash - - // string - $this->redis->set('key', 'val'); - $this->assertEquals(Redis::REDIS_STRING, $this->redis->type('key')); - - // list - $this->redis->lPush('keyList', 'val0'); - $this->redis->lPush('keyList', 'val1'); - $this->assertEquals(Redis::REDIS_LIST, $this->redis->type('keyList')); - - // set - $this->redis->del('keySet'); - $this->redis->sAdd('keySet', 'val0'); - $this->redis->sAdd('keySet', 'val1'); - $this->assertEquals(Redis::REDIS_SET, $this->redis->type('keySet')); - - // sadd with numeric key - $this->redis->del(123); - $this->assertTrue(1 === $this->redis->sAdd(123, 'val0')); - $this->assertTrue(['val0'] === $this->redis->sMembers(123)); - - // zset - $this->redis->del('keyZSet'); - $this->redis->zAdd('keyZSet', 0, 'val0'); - $this->redis->zAdd('keyZSet', 1, 'val1'); - $this->assertEquals(Redis::REDIS_ZSET, $this->redis->type('keyZSet')); - - // hash - $this->redis->del('keyHash'); - $this->redis->hSet('keyHash', 'key0', 'val0'); - $this->redis->hSet('keyHash', 'key1', 'val1'); - $this->assertEquals(Redis::REDIS_HASH, $this->redis->type('keyHash')); - - //None - $this->assertEquals(Redis::REDIS_NOT_FOUND, $this->redis->type('keyNotExists')); + // 0 => none, (key didn't exist) + // 1=> string, + // 2 => set, + // 3 => list, + // 4 => zset, + // 5 => hash + // 6 => stream + + // string + $this->redis->set('key', 'val'); + $this->assertEquals(Redis::REDIS_STRING, $this->redis->type('key')); + + // list + $this->redis->lPush('keyList', 'val0'); + $this->redis->lPush('keyList', 'val1'); + $this->assertEquals(Redis::REDIS_LIST, $this->redis->type('keyList')); + + // set + $this->redis->del('keySet'); + $this->redis->sAdd('keySet', 'val0'); + $this->redis->sAdd('keySet', 'val1'); + $this->assertEquals(Redis::REDIS_SET, $this->redis->type('keySet')); + + // sadd with numeric key + $this->redis->del(123); + $this->assertTrue(1 === $this->redis->sAdd(123, 'val0')); + $this->assertTrue(['val0'] === $this->redis->sMembers(123)); + + // zset + $this->redis->del('keyZSet'); + $this->redis->zAdd('keyZSet', 0, 'val0'); + $this->redis->zAdd('keyZSet', 1, 'val1'); + $this->assertEquals(Redis::REDIS_ZSET, $this->redis->type('keyZSet')); + + // hash + $this->redis->del('keyHash'); + $this->redis->hSet('keyHash', 'key0', 'val0'); + $this->redis->hSet('keyHash', 'key1', 'val1'); + $this->assertEquals(Redis::REDIS_HASH, $this->redis->type('keyHash')); + + // stream + if ($this->minVersionCheck("5.0")) { + $this->redis->del('stream'); + $this->redis->xAdd('stream', '*', ['foo' => 'bar']); + $this->assertEquals(Redis::REDIS_STREAM, $this->redis->type('stream')); + } + + // None + $this->redis->del('keyNotExists'); + $this->assertEquals(Redis::REDIS_NOT_FOUND, $this->redis->type('keyNotExists')); + } public function testStr() { @@ -2447,7 +2457,7 @@ class Redis_Test extends TestSuite $this->redis->del('key'); $this->redis->zAdd('key', 0, 'a', 1, 'b', 2, 'c', 3, 'd', 4, 'e'); $this->assertTrue(array('e' => 4.0, 'd' => 3.0, 'c' => 2.0) === $this->redis->zPopMax('key', 3)); - + // zPopMin with a COUNT argument $this->redis->del('key'); $this->redis->zAdd('key', 0, 'a', 1, 'b', 2, 'c', 3, 'd', 4, 'e'); |