Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d7450b2

Browse files
Add support for STREAM to the type command
1 parent 5bf0c84 commit d7450b2

4 files changed

Lines changed: 56 additions & 42 deletions

File tree

common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#define REDIS_LIST 3
3434
#define REDIS_ZSET 4
3535
#define REDIS_HASH 5
36+
#define REDIS_STREAM 6
3637

3738
#ifdef PHP_WIN32
3839
#define PHP_REDIS_API __declspec(dllexport)

library.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,8 @@ PHP_REDIS_API void redis_type_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *
807807
l = REDIS_ZSET;
808808
} else if (strncmp(response, "+hash", 5) == 0){
809809
l = REDIS_HASH;
810+
} else if (strncmp(response, "+stream", 7) == 0) {
811+
l = REDIS_STREAM;
810812
} else {
811813
l = REDIS_NOT_FOUND;
812814
}

redis.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,7 @@ static void add_class_constants(zend_class_entry *ce, int is_cluster TSRMLS_DC)
649649
zend_declare_class_constant_long(ce, ZEND_STRL("REDIS_LIST"), REDIS_LIST TSRMLS_CC);
650650
zend_declare_class_constant_long(ce, ZEND_STRL("REDIS_ZSET"), REDIS_ZSET TSRMLS_CC);
651651
zend_declare_class_constant_long(ce, ZEND_STRL("REDIS_HASH"), REDIS_HASH TSRMLS_CC);
652+
zend_declare_class_constant_long(ce, ZEND_STRL("REDIS_STREAM"), REDIS_STREAM TSRMLS_CC);
652653

653654
/* Cluster doesn't support pipelining at this time */
654655
if(!is_cluster) {

tests/RedisTest.php

Lines changed: 52 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -696,47 +696,57 @@ public function testUnlink() {
696696

697697
public function testType()
698698
{
699-
// 0 => none, (key didn't exist)
700-
// 1=> string,
701-
// 2 => set,
702-
// 3 => list,
703-
// 4 => zset,
704-
// 5 => hash
705-
706-
// string
707-
$this->redis->set('key', 'val');
708-
$this->assertEquals(Redis::REDIS_STRING, $this->redis->type('key'));
709-
710-
// list
711-
$this->redis->lPush('keyList', 'val0');
712-
$this->redis->lPush('keyList', 'val1');
713-
$this->assertEquals(Redis::REDIS_LIST, $this->redis->type('keyList'));
714-
715-
// set
716-
$this->redis->del('keySet');
717-
$this->redis->sAdd('keySet', 'val0');
718-
$this->redis->sAdd('keySet', 'val1');
719-
$this->assertEquals(Redis::REDIS_SET, $this->redis->type('keySet'));
720-
721-
// sadd with numeric key
722-
$this->redis->del(123);
723-
$this->assertTrue(1 === $this->redis->sAdd(123, 'val0'));
724-
$this->assertTrue(['val0'] === $this->redis->sMembers(123));
725-
726-
// zset
727-
$this->redis->del('keyZSet');
728-
$this->redis->zAdd('keyZSet', 0, 'val0');
729-
$this->redis->zAdd('keyZSet', 1, 'val1');
730-
$this->assertEquals(Redis::REDIS_ZSET, $this->redis->type('keyZSet'));
731-
732-
// hash
733-
$this->redis->del('keyHash');
734-
$this->redis->hSet('keyHash', 'key0', 'val0');
735-
$this->redis->hSet('keyHash', 'key1', 'val1');
736-
$this->assertEquals(Redis::REDIS_HASH, $this->redis->type('keyHash'));
737-
738-
//None
739-
$this->assertEquals(Redis::REDIS_NOT_FOUND, $this->redis->type('keyNotExists'));
699+
// 0 => none, (key didn't exist)
700+
// 1=> string,
701+
// 2 => set,
702+
// 3 => list,
703+
// 4 => zset,
704+
// 5 => hash
705+
// 6 => stream
706+
707+
// string
708+
$this->redis->set('key', 'val');
709+
$this->assertEquals(Redis::REDIS_STRING, $this->redis->type('key'));
710+
711+
// list
712+
$this->redis->lPush('keyList', 'val0');
713+
$this->redis->lPush('keyList', 'val1');
714+
$this->assertEquals(Redis::REDIS_LIST, $this->redis->type('keyList'));
715+
716+
// set
717+
$this->redis->del('keySet');
718+
$this->redis->sAdd('keySet', 'val0');
719+
$this->redis->sAdd('keySet', 'val1');
720+
$this->assertEquals(Redis::REDIS_SET, $this->redis->type('keySet'));
721+
722+
// sadd with numeric key
723+
$this->redis->del(123);
724+
$this->assertTrue(1 === $this->redis->sAdd(123, 'val0'));
725+
$this->assertTrue(['val0'] === $this->redis->sMembers(123));
726+
727+
// zset
728+
$this->redis->del('keyZSet');
729+
$this->redis->zAdd('keyZSet', 0, 'val0');
730+
$this->redis->zAdd('keyZSet', 1, 'val1');
731+
$this->assertEquals(Redis::REDIS_ZSET, $this->redis->type('keyZSet'));
732+
733+
// hash
734+
$this->redis->del('keyHash');
735+
$this->redis->hSet('keyHash', 'key0', 'val0');
736+
$this->redis->hSet('keyHash', 'key1', 'val1');
737+
$this->assertEquals(Redis::REDIS_HASH, $this->redis->type('keyHash'));
738+
739+
// stream
740+
if ($this->minVersionCheck("5.0")) {
741+
$this->redis->del('stream');
742+
$this->redis->xAdd('stream', '*', ['foo' => 'bar']);
743+
$this->assertEquals(Redis::REDIS_STREAM, $this->redis->type('stream'));
744+
}
745+
746+
// None
747+
$this->redis->del('keyNotExists');
748+
$this->assertEquals(Redis::REDIS_NOT_FOUND, $this->redis->type('keyNotExists'));
749+
740750
}
741751

742752
public function testStr() {
@@ -2447,7 +2457,7 @@ public function testZPop() {
24472457
$this->redis->del('key');
24482458
$this->redis->zAdd('key', 0, 'a', 1, 'b', 2, 'c', 3, 'd', 4, 'e');
24492459
$this->assertTrue(array('e' => 4.0, 'd' => 3.0, 'c' => 2.0) === $this->redis->zPopMax('key', 3));
2450-
2460+
24512461
// zPopMin with a COUNT argument
24522462
$this->redis->del('key');
24532463
$this->redis->zAdd('key', 0, 'a', 1, 'b', 2, 'c', 3, 'd', 4, 'e');

0 commit comments

Comments
 (0)