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

Skip to content

Commit 7d5db51

Browse files
Documentation: SSCAN docblock and example
[skip ci]
1 parent 0dd2836 commit 7d5db51

3 files changed

Lines changed: 63 additions & 2 deletions

File tree

redis.stub.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,6 +1893,67 @@ public function sortDescAlpha(string $key, ?string $pattern = null, mixed $get =
18931893
*/
18941894
public function srem(string $key, mixed $value, mixed ...$other_values): Redis|int|false;
18951895

1896+
/**
1897+
* Scan the members of a redis SET key.
1898+
*
1899+
* @see https://redis.io/commands/sscan
1900+
* @see https://redis.io/commands/scan
1901+
* @see Redis::setOption()
1902+
*
1903+
* @param string $key The Redis SET key in question.
1904+
* @param int $iterator A reference to an iterator which should be initialized to NULL that
1905+
* PhpRedis will update with the value returned from Redis after each
1906+
* subsequent call to SSCAN. Once this cursor is zero you know all
1907+
* members have been traversed.
1908+
* @param string $pattern An optional glob style pattern to match against, so Redis only
1909+
* returns the subset of members matching this pattern.
1910+
* @param int $count A hint to Redis as to how many members it should scan in one command
1911+
* before returning members for that iteration.
1912+
*
1913+
* <code>
1914+
* $redis = new Redis(['host' => 'localhost']);
1915+
*
1916+
* $redis->del('myset');
1917+
* for ($i = 0; $i < 10000; $i++) {
1918+
* $redis->sAdd('myset', "member:$i");
1919+
* }
1920+
* $redis->sadd('myset', 'foofoo');
1921+
*
1922+
* $redis->setOption(Redis::OPT_SCAN, Redis::SCAN_NORETRY);
1923+
*
1924+
* $scanned = 0;
1925+
* $it = NULL;
1926+
*
1927+
* // Without Redis::SCAN_RETRY we may receive empty results and
1928+
* // a nonzero iterator.
1929+
* do {
1930+
* // Scan members containing '5'
1931+
* $members = $redis->sscan('myset', $it, '*5*');
1932+
* foreach ($members as $member) {
1933+
* echo "NORETRY: $member\n";
1934+
* $scanned++;
1935+
* }
1936+
* } while ($it != 0);
1937+
* echo "TOTAL: $scanned\n";
1938+
*
1939+
* $redis->setOption(Redis::OPT_SCAN, Redis::SCAN_RETRY);
1940+
*
1941+
* $scanned = 0;
1942+
* $it = NULL;
1943+
*
1944+
* // With Redis::SCAN_RETRY PhpRedis will never return an empty array
1945+
* // when the cursor is non-zero
1946+
* while (($members = $redis->sscan('myset', $it, '*5*'))) {
1947+
* foreach ($members as $member) {
1948+
* echo "RETRY: $member\n";
1949+
* $scanned++;
1950+
* }
1951+
* }
1952+
* echo "TOTAL: $scanned\n";
1953+
* ?>
1954+
* </code>
1955+
*
1956+
*/
18961957
public function sscan(string $key, ?int &$iterator, ?string $pattern = null, int $count = 0): array|false;
18971958

18981959
/** @return Redis|int|false*/

redis_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: 8a3b18f9b816cfb6aac50ef147008d7349496e08 */
2+
* Stub hash: 5554480fcf6749dcfd69f371ad8dbd07fd8ed4c4 */
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")

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: 8a3b18f9b816cfb6aac50ef147008d7349496e08 */
2+
* Stub hash: 5554480fcf6749dcfd69f371ad8dbd07fd8ed4c4 */
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)