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

Skip to content

Commit c4aef95

Browse files
Documentation: More docblocks and examples
[skip ci]
1 parent e609fbe commit c4aef95

6 files changed

Lines changed: 158 additions & 13 deletions

redis.stub.php

Lines changed: 150 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class Redis {
4040
* 'retryInterval' => 100,
4141
*
4242
* // Which backoff algorithm to use. 'decorrelated jitter' is
43-
* // likely the best one for most solutiona, but there are many
43+
* // likely the best one for most solution, but there are many
4444
* // to choose from:
4545
* // REDIS_BACKOFF_ALGORITHM_DEFAULT
4646
* // REDIS_BACKOFF_ALGORITHM_CONSTANT
@@ -143,7 +143,7 @@ public function _pack(mixed $value): string;
143143
* as set with Redis::setOption().
144144
*
145145
* @param string $value The value which has been serialized and compressed.
146-
* @return mixed The uncompressed and deserialized value.
146+
* @return mixed The uncompressed and eserialized value.
147147
*
148148
*/
149149
public function _unpack(string $value): mixed;
@@ -294,6 +294,7 @@ public function brpoplpush(string $src, string $dst, int|float $timeout): Redis|
294294
* Following are examples of the two main ways to call this method.
295295
*
296296
* <code>
297+
* <?php
297298
* // Method 1 - Variadic, with the last argument being our timeout
298299
* $redis->bzPopMax('key1', 'key2', 'key3', 1.5);
299300
*
@@ -1187,14 +1188,114 @@ public function sUnion(string $key, string ...$other_keys): Redis|array|false;
11871188
*/
11881189
public function sUnionStore(string $dst, string $key, string ...$other_keys): Redis|int|false;
11891190

1190-
public function save(): bool;
1191+
/**
1192+
* Persist the Redis database to disk. This command will block the server until the save is
1193+
* completed. For a nonblocking alternative, see Redis::bgsave().
1194+
*
1195+
* @see https://redis.io/commands/save
1196+
* @see Redis::bgsave()
1197+
*
1198+
* @return Redis|bool Returns true unless an error occurs.
1199+
*/
1200+
public function save(): Redis|bool;
11911201

1202+
/**
1203+
* Incrementally scan the Redis keyspace, with optional pattern and type matching.
1204+
*
1205+
* @see https://redis.io/commands/scan
1206+
* @see Redis::setOption()
1207+
*
1208+
* @param int $iterator The cursor returned by Redis for every subsequent call to SCAN. On
1209+
* the initial invocation of the call, it should be initialized by the
1210+
* caller to NULL. Each time SCAN is invoked, the iterator will be
1211+
* updated to a new number, until finally Redis will set the value to
1212+
* zero, indicating that the scan is complete.
1213+
*
1214+
* @param string $pattern An optional glob-style pattern for matching key names. If passed as
1215+
* NULL, it is the equivalent of sending '*' (match every key).
1216+
*
1217+
* @param int $count A hint to redis that tells it how many keys to return in a single
1218+
* call to SCAN. The larger the number, the longer Redis may block
1219+
* clients while iterating the key space.
1220+
*
1221+
* @param string $type An optional argument to specify which key types to scan (e.g.
1222+
* 'STRING', 'LIST', 'SET')
1223+
*
1224+
* @return array|false An array of keys, or false if no keys were returned for this
1225+
* invocation of scan. Note that it is possible for Redis to return
1226+
* zero keys before having scanned the entire key space, so the caller
1227+
* should instead continue to SCAN until the iterator reference is
1228+
* returned to zero.
1229+
*
1230+
* A note about Redis::SCAN_NORETRY and Redis::SCAN_RETRY.
1231+
*
1232+
* For convenience, PhpRedis can retry SCAN commands itself when Redis returns an empty array of
1233+
* keys with a nonzero iterator. This can happen when matching against a pattern that very few
1234+
* keys match inside a key space with a great many keys. The following example demonstrates how
1235+
* to use Redis::scan() with the option disabled and enabled.
1236+
*
1237+
* <code>
1238+
* <?php
1239+
*
1240+
* $redis = new Redis(['host' => 'localhost']);
1241+
*
1242+
* $redis->setOption(Redis::OPT_SCAN, Redis::SCAN_NORETRY);
1243+
*
1244+
* $it = NULL;
1245+
*
1246+
* do {
1247+
* $keys = $redis->scan($it, '*zorg*');
1248+
* foreach ($keys as $key) {
1249+
* echo "KEY: $key\n";
1250+
* }
1251+
* } while ($it != 0);
1252+
*
1253+
* $redis->setOption(Redis::OPT_SCAN, Redis::SCAN_RETRY);
1254+
*
1255+
* $it = NULL;
1256+
*
1257+
* // When Redis::SCAN_RETRY is enabled, we can use simpler logic, as we will never receive an
1258+
* // empty array of keys when the iterator is nonzero.
1259+
* while ($keys = $redis->scan($it, '*zorg*')) {
1260+
* foreach ($keys as $key) {
1261+
* echo "KEY: $key\n";
1262+
* }
1263+
* }
1264+
* ?>
1265+
* </code>
1266+
*/
11921267
public function scan(?int &$iterator, ?string $pattern = null, int $count = 0, string $type = NULL): array|false;
11931268

11941269
public function scard(string $key): Redis|int|false;
11951270

11961271
public function script(string $command, mixed ...$args): mixed;
11971272

1273+
/**
1274+
* Select a specific Redis database.
1275+
*
1276+
* @param int $db The database to select. Note that by default Redis has 16 databases (0-15).
1277+
*
1278+
* @return Redis|bool true on success and false on failure
1279+
*
1280+
* <code>
1281+
* <?php
1282+
* $redis = new Redis(['host' => 'localhost']);
1283+
*
1284+
* $redis->select(1);
1285+
* $redis->set('this_is_db_1', 'test');
1286+
*
1287+
* $redis->select(0);
1288+
* var_dump($redis->exists('this_is_db_1'));
1289+
*
1290+
* $redis->select(1);
1291+
* var_dump($redis->exists('this_is_db_1'));
1292+
*
1293+
* // --- OUTPUT ---
1294+
* // int(0)
1295+
* // int(1)
1296+
* ?>
1297+
* </code>
1298+
*/
11981299
public function select(int $db): Redis|bool;
11991300

12001301
public function set(string $key, mixed $value, mixed $opt = NULL): Redis|string|bool;
@@ -1217,6 +1318,21 @@ public function setRange(string $key, int $start, string $value);
12171318
*
12181319
* OPT_SCAN enum Redis::OPT_SCAN_RETRY, or Redis::OPT_SCAN_NORETRY
12191320
*
1321+
* Redis::SCAN_NORETRY (default)
1322+
* --------------------------------------------------------
1323+
* PhpRedis will only call `SCAN` once for every time the
1324+
* user calls Redis::scan(). This means it is possible for
1325+
* an empty array of keys to be returned while there are
1326+
* still more keys to be processed.
1327+
*
1328+
* Redis::SCAN_RETRY
1329+
* --------------------------------------------------------
1330+
* PhpRedis may make multiple calls to `SCAN` for every
1331+
* time the user calls Redis::scan(), and will never return
1332+
* an empty array of keys unless Redis returns the iterator
1333+
* to zero (meaning the `SCAN` is complete).
1334+
*
1335+
*
12201336
* OPT_SERIALIZER int One of the installed serializers, which can vary depending
12211337
* on how PhpRedis was compiled. All of the supported serializers
12221338
* are as follows:
@@ -1303,8 +1419,8 @@ public function touch(array|string $key_or_array, string ...$more_keys): Redis|i
13031419
*
13041420
* @param string $operation The operation you wish to perform.  This can
13051421
* be one of the following values:
1306-
* 'GET' - Retreive the Redis slowlog as an array.
1307-
* 'LEN' - Retreive the length of the slowlog.
1422+
* 'GET' - Retrieve the Redis slowlog as an array.
1423+
* 'LEN' - Retrieve the length of the slowlog.
13081424
* 'RESET' - Remove all slowlog entries.
13091425
* <code>
13101426
* <?php
@@ -1315,7 +1431,7 @@ public function touch(array|string $key_or_array, string ...$more_keys): Redis|i
13151431
* </code>
13161432
*
13171433
* @param int $length This optional argument can be passed when operation
1318-
* is 'get' and will specify how many elements to retreive.
1434+
* is 'get' and will specify how many elements to retrieve.
13191435
* If omitted Redis will send up to a default number of
13201436
* entries, which is configurable.
13211437
*
@@ -1385,6 +1501,32 @@ public function sortDesc(string $key, ?string $pattern = null, mixed $get = null
13851501
*/
13861502
public function sortDescAlpha(string $key, ?string $pattern = null, mixed $get = null, int $offset = -1, int $count = -1, ?string $store = null): array;
13871503

1504+
/**
1505+
* Remove one or more values from a Redis SET key.
1506+
*
1507+
* @see https://redis.io/commands/srem
1508+
*
1509+
* @param string $key The Redis SET key in question.
1510+
* @param mixed $value The first value to remove.
1511+
* @param mixed $more_values One or more additional values to remove.
1512+
*
1513+
* @return Redis|int|false The number of values removed from the set or false on failure.
1514+
*
1515+
* <code>
1516+
* <?php
1517+
* $redis = new Redis(['host' => 'localhost']);
1518+
*
1519+
* $redis->pipeline()->del('set1')
1520+
* ->sadd('set1', 'foo', 'bar', 'baz')
1521+
* ->exec();
1522+
*
1523+
* var_dump($redis->sRem('set1', 'foo', 'bar', 'not-in-the-set'));
1524+
*
1525+
* // --- OUTPUT ---
1526+
* // int(2)
1527+
* ?>
1528+
* </code>
1529+
*/
13881530
public function srem(string $key, mixed $value, mixed ...$other_values): Redis|int|false;
13891531

13901532
public function sscan(string $key, ?int &$iterator, ?string $pattern = null, int $count = 0): array|false;
@@ -1502,7 +1644,7 @@ public function zPopMax(string $key, int $value = null): Redis|array|false;
15021644
public function zPopMin(string $key, int $value = null): Redis|array|false;
15031645

15041646
/**
1505-
* Retreive a range of elements of a sorted set between a start and end point.
1647+
* Retrieve a range of elements of a sorted set between a start and end point.
15061648
* How the command works in particular is greatly affected by the options that
15071649
* are passed in.
15081650
*
@@ -1556,7 +1698,7 @@ public function zRangeByScore(string $key, string $start, string $end, array $op
15561698
* @param string $end The ending index to store
15571699
* @param array|bool|null $options Our options array that controls how the command will function.
15581700
*
1559-
* @return Redis|int|false The number of elements stored in dstkey or false on failure.
1701+
* @return Redis|int|false The number of elements stored in $dstkey or false on failure.
15601702
*
15611703
* See Redis::zRange for a full description of the possible options.
15621704
*/

redis_arginfo.h

Lines changed: 2 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: 8e423eab8d5b732655e7fcaab4d0800aadc38747 */
2+
* Stub hash: ed7bf573247cb4bd4ead254d75ad5b60a97313be */
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, 0, "null")
@@ -739,7 +739,7 @@ ZEND_END_ARG_INFO()
739739

740740
#define arginfo_class_Redis_sUnionStore arginfo_class_Redis_sDiffStore
741741

742-
#define arginfo_class_Redis_save arginfo_class_Redis_clearLastError
742+
#define arginfo_class_Redis_save arginfo_class_Redis_bgSave
743743

744744
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_Redis_scan, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE)
745745
ZEND_ARG_TYPE_INFO(1, iterator, IS_LONG, 1)

redis_cluster.stub.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,9 @@ public function spop(string $key, int $count = 0): RedisCluster|string|array|fal
441441

442442
public function srandmember(string $key, int $count = 0): RedisCluster|string|array|false;
443443

444+
/**
445+
* @see Redis::srem
446+
*/
444447
public function srem(string $key, mixed $value, mixed ...$other_values): RedisCluster|int|false;
445448

446449
public function sscan(string $key, ?int &$iterator, ?string $pattern = null, int $count = 0): array|false;

redis_cluster_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: 836411b2d661943a61fd5a2aadac30997a506cde */
2+
* Stub hash: 37a25fa4537a2d10a2c2a8b09292e77e5cc35d59 */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster___construct, 0, 0, 1)
55
ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 1)

redis_cluster_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: 836411b2d661943a61fd5a2aadac30997a506cde */
2+
* Stub hash: 37a25fa4537a2d10a2c2a8b09292e77e5cc35d59 */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster___construct, 0, 0, 1)
55
ZEND_ARG_INFO(0, name)

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: 8e423eab8d5b732655e7fcaab4d0800aadc38747 */
2+
* Stub hash: ed7bf573247cb4bd4ead254d75ad5b60a97313be */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis___construct, 0, 0, 0)
55
ZEND_ARG_INFO(0, options)

0 commit comments

Comments
 (0)