@@ -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*/
0 commit comments