8000 SRANDMEMBER can return any type because of serialization. · phpredis/phpredis@6673b5b · GitHub
[go: up one dir, main page]

Skip to content

Commit 6673b5b

Browse files
SRANDMEMBER can return any type because of serialization.
1 parent 99f9fd8 commit 6673b5b

File tree

5 files changed

+34
-4
lines changed

5 files changed

+34
-4
lines changed

redis.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2826,7 +2826,7 @@ public function sPop(string $key, int $count = 0): Redis|string|array|false;
28262826
* @example $redis->sRandMember('myset', 10);
28272827
* @example $redis->sRandMember('myset', -10);
28282828
*/
2829-
public function sRandMember(string $key, int $count = 0): Redis|string|array|false;
2829+
public function sRandMember(string $key, int $count = 0): mixed;
28302830

28312831
/**
28322832
* Returns the union of one or more Redis SET keys.

redis_arginfo.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 70b942571cb2e3ef0b2531492840d9207f693b00 */
2+
* Stub hash: a888154a03dc0edbe479e0226f012a34c7cb4100 */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis___construct, 0, 0, 0)
< 8000 code>55
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_ARRAY, 1, "null")
@@ -750,7 +750,10 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_sPop, 0, 1, Redi
750750
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, count, IS_LONG, 0, "0")
751751
ZEND_END_ARG_INFO()
752752

753-
#define arginfo_class_Redis_sRandMember arginfo_class_Redis_sPop
753+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Redis_sRandMember, 0, 1, IS_MIXED, 0)
754+
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
755+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, count, IS_LONG, 0, "0")
756+
ZEND_END_ARG_INFO()
754757

755758
#define arginfo_class_Redis_sUnion arginfo_class_Redis_sDiff
756759

redis_legacy_arginfo.h

Lines changed: 1 addition & 1 deletion

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 70b942571cb2e3ef0b2531492840d9207f693b00 */
2+
* Stub hash: a888154a03dc0edbe479e0226f012a34c7cb4100 */
33
44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis___construct, 0, 0, 0)
55
ZEND_ARG_INFO(0, options)

tests/RedisTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1697,6 +1697,13 @@ public function testsRandMember() {
16971697
$this->assertInArray($reply_mem, $mems);
16981698
}
16991699

1700+
/* Ensure we can handle basically any return type */
1701+
foreach ([3.1415, new stdClass(), 42, 'hello', NULL] as $val) {
1702+
$this->assertEquals(1, $this->redis->del('set0'));
1703+
$this->assertEquals(1, $this->redis->sadd('set0', $val));
1704+
$this->assertSameType($val, $this->redis->srandmember('set0'));
1705+
}
1706+
17001707
$this->redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_NONE);
17011708
}
17021709

tests/TestSuite.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,15 @@ protected function assertIsInt($v): bool {
237237
return false;
238238
}
239239

240+
protected function assertIsFloat($v): bool {
241+
if (is_float($v))
242+
return true;
243+
244+
self::$errors []= $this->assertionTrace("%s is not a float", $this->printArg($v));
245+
246+
return false;
247+
}
248+
240249
protected function assertIsObject($v, ?string $type = NULL): bool {
241250
if ( ! is_object($v)) {
242251
self::$errors []= $this->assertionTrace("%s is not an object", $this->printArg($v));
@@ -250,6 +259,17 @@ protected function assertIsObject($v, ?string $type = NULL): bool {
250259
return true;
251260
}
252261

262+
protected function assertSameType($expected, $actual): bool {
263+
if (gettype($expected) === gettype($actual))
264+
return true;
265+
266+
self::$errors []= $this->assertionTrace("%s is not the same type as %s",
267+
$this->printArg($actual),
268+
$this->printArg($expected));
269+
270+
return false;
271+
}
272+
253273
protected function assertIsArray($v, ?int $size = null): bool {
254274
if ( ! is_array($v)) {
255275
self::$errors []= $this->assertionTrace("%s is not an array", $this->printArg($v));

0 commit comments

Comments
 (0)
0