@@ -1589,6 +1589,28 @@ public function save(): Redis|bool;
15891589 */
15901590 public function scan (?int &$ iterator , ?string $ pattern = null , int $ count = 0 , string $ type = NULL ): array |false ;
15911591
1592+ /**
1593+ * Retrieve the number of members in a Redis set.
1594+ *
1595+ * @see https://redis.io/commands/scard
1596+ *
1597+ * @param string $key The set to get the cardinality of.
1598+ *
1599+ * @return Redis|int|false The cardinality of the set or false on failure.
1600+ *
1601+ * <code>
1602+ * <?php
1603+ *
1604+ * $redis = new Redis(['host' => 'localhost']);
1605+ *
1606+ * $redis->del('set');
1607+ * $redis->sadd('set', 'one', 'two', 'three', 'four', 'five');
1608+ *
1609+ * // Returns 5
1610+ * $redis->scard('set');
1611+ * ?>
1612+ * </code>
1613+ */
15921614 public function scard (string $ key ): Redis |int |false ;
15931615
15941616 public function script (string $ command , mixed ...$ args ): mixed ;
@@ -1664,16 +1686,61 @@ public function select(int $db): Redis|bool;
16641686 */
16651687 public function set (string $ key , mixed $ value , mixed $ options = NULL ): Redis |string |bool ;
16661688
1667- /** @return Redis|int|false*/
1668- public function setBit (string $ key , int $ idx , bool $ value );
1689+ /**
1690+ * Set a specific bit in a Redis string to zero or one
1691+ *
1692+ * @see https://redis.io/commands/setbit
1693+ *
1694+ * @param string $key The Redis STRING key to modify
1695+ * @param bool $value Whether to set the bit to zero or one.
1696+ *
1697+ * @return Redis|int|false The original value of the bit or false on failure.
1698+ *
1699+ * <code>
1700+ * <?php
1701+ * $redis = new Redis(['host' => 'localhost']);
1702+ *
1703+ * $redis->set('foo', 'bar');
1704+ *
1705+ * // Flip the 7th bit to 1
1706+ * $redis->setbit('foo', 7, 1);
1707+ *
1708+ * // The bit flip turned 'bar' -> 'car'
1709+ * $redis->get('foo');
1710+ * ?>
1711+ * </code>
1712+ */
1713+ public function setBit (string $ key , int $ idx , bool $ value ): Redis |int |false ;
16691714
1670- /** @return Redis|int|false*/
1671- public function setRange (string $ key , int $ start , string $ value );
1715+ /**
1716+ * Update or append to a Redis string at a specific starting index
1717+ *
1718+ * @see https://redis.io/commands/setrange
1719+ *
1720+ * @param string $key The key to update
1721+ * @param int $index Where to insert the provided value
1722+ * @param string $value The value to copy into the string.
1723+ *
1724+ * @return Redis|int|false The new length of the string or false on failure
1725+ *
1726+ * <code>
1727+ * <?php
1728+ * $redis = new Redis(['host' => 'localhost']);
1729+
1730+ * $redis->set('message', 'Hello World');
16721731
1732+ * // Update 'Hello World' to 'Hello Redis'
1733+ * $redis->setRange('message', 6, 'Redis');
1734+ * ?>
1735+ * </code>
1736+ */
1737+ public function setRange (string $ key , int $ index , string $ value ): Redis |int |false ;
16731738
16741739 /**
16751740 * Set a configurable option on the Redis object.
16761741 *
1742+ * @see Redis::getOption()
1743+ *
16771744 * Following are a list of options you can set:
16781745 *
16791746 * OPTION TYPE DESCRIPTION
@@ -1773,8 +1840,33 @@ public function setOption(int $option, mixed $value): bool;
17731840 */
17741841 public function setex (string $ key , int $ expire , mixed $ value );
17751842
1776- /** @return bool|array|Redis */
1777- public function setnx (string $ key , mixed $ value );
1843+ /**
1844+ * Set a key to a value, but only if that key does not already exist.
1845+ *
1846+ * @see https://redis.io/commands/setnx
1847+ *
1848+ * @param string $key The key name to set.
1849+ * @param mixed $value What to set the key to.
1850+ *
1851+ * @return Redis|bool Returns true if the key was set and false otherwise.
1852+ *
1853+ * <code>
1854+ * <?php
1855+ * $redis = new Redis(['host' => 'localhost']);
1856+ *
1857+ * $redis->del('new-key');
1858+ * $redis->set('existing-key', 'already-exists');
1859+ *
1860+ * // Key is new, returns 1
1861+ * $redis->setnx('key1', 'here-is-a-new-key');
1862+ *
1863+ * // Key exists, returns 0
1864+ * $redis->setnx('existing-key', 'new-value');
1865+ * ?>
1866+ * </code>
1867+ *
1868+ */
1869+ public function setnx (string $ key , mixed $ value ): Redis |bool ;
17781870
17791871 /**
17801872 * Check whether a given value is the member of a Redis SET.
@@ -2335,6 +2427,29 @@ public function xgroup(string $operation, string $key = null, string $group = nu
23352427
23362428 public function xinfo (string $ operation , ?string $ arg1 = null , ?string $ arg2 = null , int $ count = -1 ): mixed ;
23372429
2430+
2431+ /**
2432+ * Get the number of messages in a Redis STREAM key.
2433+ *
2434+ * @see https://redis.io/commands/xlen
2435+ *
2436+ * @param string $key The Stream to check.
2437+ *
2438+ * @return Redis|int|false The number of messages or false on failure.
2439+ *
2440+ * <code>
2441+ * <?php
2442+ * $redis = new Redis(['host' => 'localhost']);
2443+ *
2444+ * $redis->del('stream');
2445+ * $redis->xadd('stream', '*', ['first' => 'message']);
2446+ * $redis->xadd('stream', '*', ['second' => 'message']);
2447+ *
2448+ * // int(2)
2449+ * $redis->xLen('stream');
2450+ * ?>
2451+ * </code>
2452+ */
23382453 public function xlen (string $ key ): Redis |int |false ;
23392454
23402455 public function xpending (string $ key , string $ group , ?string $ start = null , ?string $ end = null , int $ count = -1 , ?string $ consumer = null ): Redis |array |false ;
@@ -2349,6 +2464,67 @@ public function xrevrange(string $key, string $start, string $end, int $count =
23492464
23502465 public function xtrim (string $ key , int $ maxlen , bool $ approx = false , bool $ minid = false , int $ limit = -1 ): Redis |int |false ;
23512466
2467+ /**
2468+ * Add one or more elements and scores to a Redis sorted set.
2469+ *
2470+ * @see https://redis.io/commands/zadd
2471+ *
2472+ * @param string $key The sorted set in question.
2473+ * @param array|float $score_or_options Either the score for the first element, or an array
2474+ * containing one or more options for the operation.
2475+ * @param mixed $more_scores_and_mems A variadic number of additional scores and members.
2476+ *
2477+ * Following is information about the options that may be passed as the scond argument:
2478+ *
2479+ * <code>
2480+ * $options = [
2481+ * 'NX', # Only update elements that already exist
2482+ * 'NX', # Only add new elements but don't update existing ones.
2483+ *
2484+ * 'LT' # Only update existing elements if the new score is less than the existing one.
2485+ * 'GT' # Only update existing elements if the new score is greater than the existing one.
2486+ *
2487+ * 'CH' # Instead of returning the number of elements added, Redis will return the number
2488+ * # Of elements that were changed in the operation.
2489+ *
2490+ * 'INCR' # Instead of setting each element to the provide score, increment the elemnt by the
2491+ * # provided score, much like ZINCRBY. When this option is passed, you may only
2492+ * # send a single score and member.
2493+ * ];
2494+ *
2495+ * Note: 'GX', 'LT', and 'NX' cannot be passed together, and PhpRedis will send whichever one is last in
2496+ * the options array.
2497+ *
2498+ * <code>
2499+ * <?php
2500+ * $redis = new Redis(['host' => 'localhost']);
2501+ *
2502+ * $redis->del('zs');
2503+ *
2504+ * // Add three new elements to our zset
2505+ * $redis->zadd('zs', 1, 'first', 2, 'second', 3, 'third');
2506+ *
2507+ * // Array
2508+ * // (
2509+ * // [first] => 1
2510+ * // [second] => 2
2511+ * // [third] => 3
2512+ * // )
2513+ * $redis->zRange('zs', 0, -1, true);
2514+ *
2515+ * // Update only existing elements. Note that 'new-element' isn't added
2516+ * $redis->zAdd('zs', ['XX'], 8, 'second', 99, 'new-element');
2517+ *
2518+ * // Array
2519+ * // (
2520+ * // [first] => 1
2521+ * // [third] => 3
2522+ * // [second] => 8
2523+ * // )
2524+ * print_r($redis->zRange('zs', 0, -1, true));
2525+ * ?>
2526+ * </code>
2527+ */
23522528 public function zAdd (string $ key , array |float $ score_or_options , mixed ...$ more_scores_and_mems ): Redis |int |false ;
23532529
23542530 /**
0 commit comments