Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6ea5b3e

Browse files
crocodelemichael-grunder
authored andcommitted
Fix argument count issue in HSET with associative array, update method signature for HSET and add documentation
1 parent6673b5b commit6ea5b3e

File tree

5 files changed

+40
-10
lines changed

5 files changed

+40
-10
lines changed

‎redis.stub.php‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1800,7 +1800,21 @@ public function hMset(string $key, array $fieldvals): Redis|bool;
18001800
*/
18011801
publicfunctionhRandField(string$key, ?array$options =null):Redis|string|array|false;
18021802

1803-
publicfunctionhSet(string$key,string$member,mixed$value):Redis|int|false;
1803+
/**
1804+
* Add or update one or more hash fields and values.
1805+
*
1806+
* @param string $key The hash to create/update.
1807+
* @param mixed $fields_and_vals Argument pairs of fields and values. Alternatively, an associative array with the
1808+
* fields and their values.
1809+
*
1810+
* @return Redis|int|false The number of fields that were added, or false on failure.
1811+
*
1812+
* @see https://redis.io/commands/hset/
1813+
*
1814+
* @example $redis->hSet('player:1', 'name', 'Kim', 'score', 78);
1815+
* @example $redis->hSet('player:1', ['name' => 'Kim', 'score' => 78]);
1816+
*/
1817+
publicfunctionhSet(string$key,mixed ...$fields_and_vals):Redis|int|false;
18041818

18051819
/**
18061820
* Set a hash field and value, but only if that field does not exist

‎redis_arginfo.h‎

Lines changed: 3 additions & 4 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:a888154a03dc0edbe479e0226f012a34c7cb4100 */
2+
* Stub hash:1cc5fe0df8dfa7d95f2bc45c2383132a68629f24 */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis___construct,0,0,0)
55
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0,options,IS_ARRAY,1,"null")
@@ -439,10 +439,9 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_hRandField, 0, 1
439439
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0,options,IS_ARRAY,1,"null")
440440
ZEND_END_ARG_INFO()
441441

442-
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_hSet,0,3,Redis,MAY_BE_LONG|MAY_BE_FALSE)
442+
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_hSet,0,1,Redis,MAY_BE_LONG|MAY_BE_FALSE)
443443
ZEND_ARG_TYPE_INFO(0,key,IS_STRING,0)
444-
ZEND_ARG_TYPE_INFO(0,member,IS_STRING,0)
445-
ZEND_ARG_TYPE_INFO(0,value,IS_MIXED,0)
444+
ZEND_ARG_VARIADIC_TYPE_INFO(0,fields_and_vals,IS_MIXED,0)
446445
ZEND_END_ARG_INFO()
447446

448447
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_hSetNx,0,3,Redis,MAY_BE_BOOL)

‎redis_commands.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3481,7 +3481,7 @@ int redis_hset_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
34813481
}
34823482

34833483
/* Initialize our command */
3484-
redis_cmd_init_sstr(&cmdstr,1+zend_hash_num_elements(Z_ARRVAL(z_args[1])),ZEND_STRL("HSET"));
3484+
redis_cmd_init_sstr(&cmdstr,1+zend_hash_num_elements(Z_ARRVAL(z_args[1]))*2,ZEND_STRL("HSET"));
34853485

34863486
/* Append key */
34873487
zkey=zval_get_string(&z_args[0]);

‎redis_legacy_arginfo.h‎

Lines changed: 3 additions & 4 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:a888154a03dc0edbe479e0226f012a34c7cb4100 */
2+
* Stub hash:1cc5fe0df8dfa7d95f2bc45c2383132a68629f24 */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis___construct,0,0,0)
55
ZEND_ARG_INFO(0,options)
@@ -395,10 +395,9 @@ ZEND_END_ARG_INFO()
395395

396396
#definearginfo_class_Redis_hRandField arginfo_class_Redis_getEx
397397

398-
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_hSet,0,0,3)
398+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_hSet,0,0,1)
399399
ZEND_ARG_INFO(0,key)
400-
ZEND_ARG_INFO(0,member)
401-
ZEND_ARG_INFO(0,value)
400+
ZEND_ARG_VARIADIC_INFO(0,fields_and_vals)
402401
ZEND_END_ARG_INFO()
403402

404403
#definearginfo_class_Redis_hSetNx arginfo_class_Redis_hIncrBy

‎tests/RedisTest.php‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3237,6 +3237,24 @@ public function testHashes() {
32373237
$this->assertEquals('Object',$h1['z']);
32383238
$this->assertEquals('',$h1['t']);
32393239

3240+
// hset with fields + values as an associative array
3241+
if (version_compare($this->version,'4.0.0') >=0) {
3242+
$this->redis->del('h');
3243+
$this->assertEquals(3,$this->redis->hSet('h', ['x' =>123,'y' =>456,'z' =>'abc']));
3244+
$this->assertEquals(['x' =>'123','y' =>'456','z' =>'abc'],$this->redis->hGetAll('h'));
3245+
$this->assertEquals(0,$this->redis->hSet('h', ['x' =>789]));
3246+
$this->assertEquals(['x' =>'789','y' =>'456','z' =>'abc'],$this->redis->hGetAll('h'));
3247+
}
3248+
3249+
// hset with variadic fields + values
3250+
if (version_compare($this->version,'4.0.0') >=0) {
3251+
$this->redis->del('h');
3252+
$this->assertEquals(3,$this->redis->hSet('h','x',123,'y',456,'z','abc'));
3253+
$this->assertEquals(['x' =>'123','y' =>'456','z' =>'abc'],$this->redis->hGetAll('h'));
3254+
$this->assertEquals(0,$this->redis->hSet('h','x',789));
3255+
$this->assertEquals(['x' =>'789','y' =>'456','z' =>'abc'],$this->redis->hGetAll('h'));
3256+
}
3257+
32403258
// hstrlen
32413259
if (version_compare($this->version,'3.2.0') >=0) {
32423260
$this->redis->del('h');

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp