@@ -1215,29 +1215,321 @@ public function hGet(string $key, string $member): mixed;
12151215 */
12161216 public function hGetAll (string $ key ): Redis |array |false ;
12171217
1218- public function hIncrBy (string $ key , string $ member , int $ value ): Redis |int |false ;
1218+ /**
1219+ * Increment a hash field's value by an integer
1220+ *
1221+ * @see https://redis.io/commands/hincrby
1222+ *
1223+ * @param string $key The hash to modify
1224+ * @param string $field The field to increment
1225+ * @param int $value How much to increment the value.
1226+ *
1227+ * @return Redis|int|false The new value of the field.
1228+ *
1229+ * <code>
1230+ * <?php
1231+ * $redis = new Redis(['host' => 'localhost']);
1232+ *
1233+ * $redis->del('player');
1234+ *
1235+ * $redis->hmset('player', ['name' => 'Bob', 'level' => 1]);
1236+ *
1237+ * // int(2)
1238+ * $redis->hIncrBy('player', 'level', 1);
1239+ *
1240+ * // int(5)
1241+ * $redis->hIncrBy('player', 'level', 3);
1242+ * ?>
1243+ * </code>
1244+ *
1245+ */
1246+ public function hIncrBy (string $ key , string $ field , int $ value ): Redis |int |false ;
12191247
1220- public function hIncrByFloat (string $ key , string $ member , float $ value ): Redis |float |false ;
1248+ /**
1249+ * Increment a hash field by a floating point value
1250+ *
1251+ * @see https://redis.io/commands/hincrbyfloat
1252+ *
1253+ * @param string $key The hash with the field to increment.
1254+ * @param string $field The field to increment.
1255+ *
1256+ * @return Redis|float|false The field value after incremented.
1257+ *
1258+ * <code>
1259+ * $redis = new Redis(['host' => 'localhost']);
1260+ *
1261+ * $redis->del('trig-numbers')
1262+ *
1263+ * // float(3.1415926)
1264+ * $pi = $redis->hIncrByFloat('trig-numbers', 'pi', 3.1415926);
1265+ *
1266+ * // float(6.2831852)
1267+ * $redis->hIncrByFloat('trig-numbers', 'tau', 2 * $pi);
1268+ * ?>
1269+ * </code>
1270+ */
1271+ public function hIncrByFloat (string $ key , string $ field , float $ value ): Redis |float |false ;
12211272
1273+ /**
1274+ * Retrieve all of the fields of a hash.
1275+ *
1276+ * @see https://redis.io/commands/hkeys
1277+ *
1278+ * @param string $key The hash to query.
1279+ *
1280+ * @return Redis|array|false The fields in the hash or false if the hash doesn't exist.
1281+ *
1282+ * <code>
1283+ * <?php
1284+ * $redis = new Redis(['host' => 'localhost']);
1285+ *
1286+ * $redis->del('ships');
1287+ *
1288+ * $redis->hmset('ships', ['Enterprise' => 'NCC-1701D', 'Defiant' => 'NX-74205', 'Voyager' => 'NCC-74656']);
1289+ *
1290+ * // array(3) {
1291+ * // [0]=>
1292+ * // string(10) "Enterprise"
1293+ * // [1]=>
1294+ * // string(7) "Defiant"
1295+ * // [2]=>
1296+ * // string(7) "Voyager"
1297+ * // }
1298+ * $redis->hKeys('ships');
1299+ * ?>
1300+ * </code>
1301+ */
12221302 public function hKeys (string $ key ): Redis |array |false ;
12231303
1304+ /**
1305+ * Get the number of fields in a hash.
1306+ *
1307+ * @see https://redis.io/commands/hlen
1308+ *
1309+ * @param string $key The hash to check.
1310+ *
1311+ * @return Redis|int|false The number of fields or false if the key didn't exist.
1312+ */
12241313 public function hLen (string $ key ): Redis |int |false ;
12251314
1226- public function hMget (string $ key , array $ keys ): Redis |array |false ;
1315+ /**
1316+ * Get one or more fields from a hash.
1317+ *
1318+ * @see https://redis.io/commands/hmget
1319+ *
1320+ * @param string $key The hash to query.
1321+ * @param array $fields One or more fields to query in the hash.
1322+ *
1323+ * @return Redis|array|false The fields and values or false if the key didn't exist.
1324+ *
1325+ * <code>
1326+ * <?php
1327+ * $redis = new Redis(['host' => 'localhost']);
1328+ *
1329+ * $redis->del('player:1');
1330+ *
1331+ * $redis->hmset('player:1', ['name' => 'Alice', 'age' => '26', 'score' => '1337']);
1332+ *
1333+ * // array(2) {
1334+ * // ["name"]=>
1335+ * // string(5) "Alice"
1336+ * // ["score"]=>
1337+ * // string(4) "1337"
1338+ * // }
1339+ * $redis->hmget('player:1', ['name', 'score']);
1340+ * ?>
1341+ * </code>
1342+ */
1343+ public function hMget (string $ key , array $ fields ): Redis |array |false ;
12271344
1228- public function hMset (string $ key , array $ keyvals ): Redis |bool ;
1345+ /**
1346+ * Add or update one or more hash fields and values
1347+ *
1348+ * @see https://redis.io/commands/hmset
1349+ *
1350+ * @param string $key The hash to create/update
1351+ * @param array $fieldvals An associative array with fields and their values.
1352+ *
1353+ * @return Redis|bool True if the operation was successful
1354+ *
1355+ * <code>
1356+ * <?php
1357+ * $redis = new Redis(['host' => 'localhost']);
1358+ *
1359+ * $redis->hmset('updates', ['status' => 'starting', 'elapsed' => 0]);
1360+ * ?>
1361+ * </code>
1362+ */
1363+ public function hMset (string $ key , array $ fieldvals ): Redis |bool ;
12291364
1365+ /**
1366+ * Get one or more random field from a hash.
1367+ *
1368+ * @see https://redis.io/commands/hrandfield
1369+ *
1370+ * @param string $key The hash to query.
1371+ * @param array $options An array of options to modify how the command behaves.
1372+ *
1373+ * <code>
1374+ * $options = [
1375+ * 'COUNT' => int // An optional number of fields to return.
1376+ * 'WITHVALUES' => bool // Also return the field values.
1377+ * ];
1378+ * </code>
1379+ *
1380+ * @return Redis|array|string One or more random fields (and possibly values).
1381+ *
1382+ * <code>
1383+ * <?php
1384+ * $redis = new Redis(['host' => 'localhost']);
1385+ *
1386+ * $redis->del('settings');
1387+ *
1388+ * $redis->hmset('settings', ['path' => '/', 'state' => 'active', 'jobs' => 15]);
1389+ *
1390+ * $redis->hrandfield('settings');
1391+ *
1392+ * $redis->hrandfield('settings', ['count' => 2, 'withvalues' => true]);
1393+ * ?>
1394+ * </code>
1395+ */
12301396 public function hRandField (string $ key , array $ options = null ): Redis |string |array ;
12311397
12321398 public function hSet (string $ key , string $ member , mixed $ value ): Redis |int |false ;
12331399
1234- public function hSetNx (string $ key , string $ member , string $ value ): Redis |bool ;
1400+ /**
1401+ * Set a hash field and value, but only if that field does not exist
1402+ *
1403+ * @see https://redis.io/commands/hsetnx
1404+ *
1405+ * @param string $key The hash to update.
1406+ * @param string $field The value to set.
1407+ *
1408+ * @return Redis|bool True if the field was set and false if not.
1409+ *
1410+ * <code>
1411+ * $redis = new Redis(['host' => 'localhost']);
1412+ *
1413+ * $redis->del('player:1');
1414+ *
1415+ * $redis->hmset('player:1', ['name' => 'bob', 'score' => 0]);
1416+ *
1417+ * // bool(true)
1418+ * var_dump($redis->hsetnx('player:1', 'lock', 'enabled'));
1419+ *
1420+ * // bool(false)
1421+ * var_dump($redis->hsetnx('player:1', 'lock', 'enabled'));
1422+ * </code>
1423+ */
1424+ public function hSetNx (string $ key , string $ field , string $ value ): Redis |bool ;
12351425
1236- public function hStrLen (string $ key , string $ member ): Redis |int |false ;
1426+ /**
1427+ * Get the string length of a hash field
1428+ *
1429+ * @see https://redis.io/commands/hstrlen
1430+ *
1431+ * @param string $key The hash to query.
1432+ * @param string $field The field to query.
1433+ *
1434+ * @return Redis|int|false The string length of the field or false.
1435+ *
1436+ * <code>
1437+ * <?php
1438+ * $redis = new Redis(['host' => 'localhost']);
1439+ *
1440+ * $redis->del('hash');
1441+ * $redis->hmset('hash', ['50bytes' => str_repeat('a', 50)]);
1442+ *
1443+ * // int(50)
1444+ * $redis->hstrlen('hash', '50bytes');
1445+ *
1446+ * </code>
1447+ */
1448+ public function hStrLen (string $ key , string $ field ): Redis |int |false ;
12371449
1450+ /**
1451+ * Get all of the values from a hash.
1452+ *
1453+ * @see https://redis.io/commands/hvals
1454+ *
1455+ * @param string $key The hash to query.
1456+ *
1457+ * @return Redis|array|false The values from the hash.
1458+ *
1459+ * <code>
1460+ * <?php
1461+ * $redis = new Redis(['host' => 'localhost']);
1462+ *
1463+ * $redis->del('player');
1464+ *
1465+ * $redis->hmset('player', ['name' => 'Alice', 'score' => 1337]);
1466+ *
1467+ * // array(2) {
1468+ * // ["name"]=>
1469+ * // string(5) "Alice"
1470+ * // ["score"]=>
1471+ * // string(4) "1337"
1472+ * // }
1473+ * $redis->hgetall('player');
1474+ * ?>
1475+ * </code>
1476+ */
12381477 public function hVals (string $ key ): Redis |array |false ;
12391478
1240- public function hscan (string $ key , ?int &$ iterator , ?string $ pattern = null , int $ count = 0 ): Redis |bool |array ;
1479+
1480+ /**
1481+ * Iterate over the fields and values of a hash in an incremental fashion.
1482+ *
1483+ * @see https://redis.io/commands/hscan
1484+ * @see https://redis.io/commands/scan
1485+ *
1486+ * @param string $key The hash to query.
1487+ * @param int $iterator The scan iterator, which should be initialized to NULL before the first call.
1488+ * This value will be updated after every call to hscan, until it reaches zero
1489+ * meaning the scan is complete.
1490+ * @param string $pattern An optional glob-style pattern to filter fields with.
1491+ * @param int $count An optional hint to Redis about how many fields and values to return per HSCAN.
1492+ *
1493+ * @return Redis|array|bool An array with a subset of fields and values.
1494+ *
1495+ * <code>
1496+ * <?php
1497+ * $redis = new Redis(['host' => 'localhost']);
1498+ *
1499+ * $redis->del('big-hash');
1500+ *
1501+ * for ($i = 0; $i < 1000; $i++) {
1502+ * $fields["field:$i"] = "value:$i";
1503+ * }
1504+ *
1505+ * $redis->hmset('big-hash', $fields);
1506+ *
1507+ * $it = NULL;
1508+ *
1509+ * do {
1510+ * // Scan the hash but limit it to fields that match '*:1?3'
1511+ * $fields = $redis->hscan('big-hash', $it, '*:1?3');
1512+ *
1513+ * foreach ($fields as $field => $value) {
1514+ * echo "[$field] => $value\n";
1515+ * }
1516+ * } while ($it != 0);
1517+ *
1518+ * // --- OUTPUT ---
1519+ * // [field:143] => value:143
1520+ * // [field:133] => value:133
1521+ * // [field:163] => value:163
1522+ * // [field:183] => value:183
1523+ * // [field:153] => value:153
1524+ * // [field:113] => value:113
1525+ * // [field:103] => value:103
1526+ * // [field:193] => value:193
1527+ * // [field:123] => value:123
1528+ * // [field:173] => value:173
1529+ * ?>
1530+ * </code>
1531+ */
1532+ public function hscan (string $ key , ?int &$ iterator , ?string $ pattern = null , int $ count = 0 ): Redis |array |bool ;
12411533
12421534 /**
12431535 * Increment a key's value, optionally by a specifc amount.
0 commit comments