@@ -2454,15 +2454,229 @@ public function xlen(string $key): Redis|int|false;
24542454
24552455 public function xpending (string $ key , string $ group , ?string $ start = null , ?string $ end = null , int $ count = -1 , ?string $ consumer = null ): Redis |array |false ;
24562456
2457+ /**
2458+ * Get a range of entries from a STREAM key.
2459+ *
2460+ * @see https://redis.io/commands/xrange
2461+ *
2462+ * @param string $key The stream key name to list.
2463+ * @param string $start The minimum ID to return.
2464+ * @param string $end The maximum ID to return.
2465+ * @param int $count An optional maximum number of entries to return.
2466+ *
2467+ * @return Redis|array|bool The entries in the stream within the requested range or false on failure.
2468+ *
2469+ * <code>
2470+ * <?php
2471+ * $redis = new Redis(['host' => 'localhost']);
2472+ *
2473+ * $redis->del('stream');
2474+ *
2475+ * for ($i = 0; $i < 2; $i++) {
2476+ * for ($j = 1; $j <= 2; $j++) {
2477+ * $redis->xAdd('stream', "$i-$j", ['message' => "$i:$j"]);
2478+ * }
2479+ * }
2480+ *
2481+ * //Array
2482+ * //(
2483+ * // [0-1] => Array
2484+ * // (
2485+ * // [message] => 0:1
2486+ * // )
2487+ * //
2488+ * // [0-2] => Array
2489+ * // (
2490+ * // [message] => 0:2
2491+ * // )
2492+ * //
2493+ * //)
2494+ * $redis->xRange('stream', '0-1', '0-2');
2495+ *
2496+ * // '-' and '+' are special values which mean 'minimum possible',
2497+ * // and 'maximum possible' id, respectively.
2498+ * $redis->xRange('stream', '-', '+');
2499+ * ?>
2500+ * </code>
2501+ */
24572502 public function xrange (string $ key , string $ start , string $ end , int $ count = -1 ): Redis |array |bool ;
24582503
2504+ /**
2505+ * Consume one or more unconsumed elements in one or more streams.
2506+ *
2507+ * @see https://redis.io/commands/xread
2508+ *
2509+ * @param array $streams An associative array with stream name keys and minimum id values.
2510+ * @param int $count An optional limit to how many entries are returnd *per stream*
2511+ * @param int $block An optional maximum number of milliseconds to block the caller if no
2512+ * data is available on any of the provided streams.
2513+ *
2514+ * <code>
2515+ * $redis = new Redis(['host' => 'localhost']);
2516+ *
2517+ * $redis->del('s03', 's03');
2518+ *
2519+ * $redis->xAdd('s03', '3-1', ['title' => 'The Search, Part I']);
2520+ * $redis->xAdd('s03', '3-2', ['title' => 'The Search, Part II']);
2521+ * $redis->xAdd('s03', '3-3', ['title' => 'The House Of Quark']);
2522+ *
2523+ * $redis->xAdd('s04', '4-1', ['title' => 'The Way of the Warrior']);
2524+ * $redis->xAdd('s04', '4-3', ['title' => 'The Visitor']);
2525+ * $redis->xAdd('s04', '4-4', ['title' => 'Hippocratic Oath']);
2526+ *
2527+ * // Array
2528+ * // (
2529+ * // [s03] => Array
2530+ * // (
2531+ * // [3-3] => Array
2532+ * // (
2533+ * // [title] => The House Of Quark
2534+ * // )
2535+ * //
2536+ * // )
2537+ * //
2538+ * // [s04] => Array
2539+ * // (
2540+ * // [4-3] => Array
2541+ * // (
2542+ * // [title] => The Visitor
2543+ * // )
2544+ * //
2545+ * // [4-4] => Array
2546+ * // (
2547+ * // [title] => Hippocratic Oath
2548+ * // )
2549+ * //
2550+ * // )
2551+ * //
2552+ * // )
2553+ * print_r($redis->xRead(['s03' => '3-2', 's04' => '4-1']));
2554+ * </code>
2555+ */
24592556 public function xread (array $ streams , int $ count = -1 , int $ block = -1 ): Redis |array |bool ;
24602557
24612558 public function xreadgroup (string $ group , string $ consumer , array $ streams , int $ count = 1 , int $ block = 1 ): Redis |array |bool ;
24622559
2463- public function xrevrange (string $ key , string $ start , string $ end , int $ count = -1 ): Redis |array |bool ;
2560+ /**
2561+ * Get a range of entries from a STREAM ke in reverse cronological order.
2562+ *
2563+ * @see https://redis.io/commands/xrevrange
2564+ * @see https://redis.io/commands/xrange
2565+ *
2566+ * @param string $key The stream key to query.
2567+ * @param string $end The maximum message ID to include.
2568+ * @param string $start The minimum message ID to include.
2569+ * @param int $count An optional maximum number of messages to include.
2570+ *
2571+ * @return Redis|array|bool The entries within the requested range, from newest to oldest.
2572+ *
2573+ * <code>
2574+ * <?php
2575+ * $redis = new Redis(['host' => 'localhost']);
2576+ *
2577+ * $redis->del('stream');
2578+ *
2579+ * for ($i = 0; $i < 2; $i++) {
2580+ * for ($j = 1; $j <= 2; $j++) {
2581+ * $redis->xAdd('stream', "$i-$j", ['message' => "$i:$j"]);
2582+ * }
2583+ * }
2584+ *
2585+ * // Array
2586+ * // (
2587+ * // [0-2] => Array
2588+ * // (
2589+ * // [message] => 0:2
2590+ * // )
2591+ * //
2592+ * // [0-1] => Array
2593+ * // (
2594+ * // [message] => 0:1
2595+ * // )
2596+ * //
2597+ * // )
2598+ * $redis->xRevRange('stream', '0-2', '0-1');
2599+ *
2600+ * // '-' and '+' are special values which mean 'minimum possible',
2601+ * // and 'maximum possible' id, respectively.
2602+ * $redis->xRevRange('stream', '+', '-');
2603+ * ?>
2604+ * </code>
2605+ *
2606+ */
2607+ public function xrevrange (string $ key , string $ end , string $ start , int $ count = -1 ): Redis |array |bool ;
24642608
2465- public function xtrim (string $ key , int $ maxlen , bool $ approx = false , bool $ minid = false , int $ limit = -1 ): Redis |int |false ;
2609+ /**
2610+ * Truncate a STREAM key in various ways.
2611+ *
2612+ * @see https://redis.io/commands/xtrim
2613+ *
2614+ * @param string $key The STREAM key to trim.
2615+ * @param string $threshold This can either be a maximum length, or a minimum id.
2616+ * MAXLEN - An integer describing the maximum desired length of the stream after the command.
2617+ * MINID - An ID that will become the new minimum ID in the stream, as Redis will trim all
2618+ * messages older than this ID.
2619+ * @param bool $approx Whether redis is allowed to do an approximate trimming of the stream. This is
2620+ * more efficient for Redis given how streams are stored internally.
2621+ * @param int $count An optional upper bound on how many entries Redis should attempt to trim before
2622+ * returning to the caller.
2623+ * @param bool $minid When set to `true`, users should pass a minimum ID to the `$threshold` argument.
2624+ * @param int $limit An optional upper bound on how many entries to trim during the command.
2625+ *
2626+ * <code>
2627+ * <?php
2628+ * $redis = new Redis(['host' => 'localhost']);
2629+ *
2630+ * $redis->del('stream');
2631+ * $redis->xAdd('stream', '1-1', ['one' => 'one']);
2632+ * $redis->xAdd('stream', '1-2', ['one' => 'two']);
2633+ * $redis->xAdd('stream', '2-1', ['two' => 'one']);
2634+ * $redis->xAdd('stream', '2-2', ['two' => 'two']);
2635+ *
2636+ * // Trim to three elemn
2637+ * $redis->xTrim('stream', 3);
2638+ *
2639+ * // Array
2640+ * // (
2641+ * // [1-2] => Array
2642+ * // (
2643+ * // [one] => two
2644+ * // )
2645+ * //
2646+ * // [2-1] => Array
2647+ * // (
2648+ * // [two] => one
2649+ * // )
2650+ * //
2651+ * // [2-2] => Array
2652+ * // (
2653+ * // [two] => two
2654+ * // )
2655+ * //
2656+ * // )
2657+ * $redis->xRange('stream', '-', '+');
2658+ *
2659+ * // Now let's trim everything older than '2-1'
2660+ * $redis->xTrim('stream', '2-1', false, true);
2661+ *
2662+ * // Array
2663+ * // (
2664+ * // [2-1] => Array
2665+ * // (
2666+ * // [two] => one
2667+ * // )
2668+ * //
2669+ * // [2-2] => Array
2670+ * // (
2671+ * // [two] => two
2672+ * // )
2673+ * //
2674+ * // )
2675+ * print_r($redis->xRange('stream', '-', '+'));
2676+ * ?>
2677+ * </code>
2678+ */
2679+ public function xtrim (string $ key , string $ threshold , bool $ approx = false , bool $ minid = false , int $ limit = -1 ): Redis |int |false ;
24662680
24672681 /**
24682682 * Add one or more elements and scores to a Redis sorted set.
@@ -3362,6 +3576,8 @@ public function zdiffstore(string $dst, array $keys): Redis|int|false;
33623576 /**
33633577 * Compute the intersection of one or more sorted sets and return the members
33643578 *
3579+ * @see https://redis.io/commands/zinter
3580+ *
33653581 * @param array $keys One ore more sorted sets.
33663582 * @param array $weights An optional array of weights to be applied to each set when performing
33673583 * the intersection.
@@ -3404,8 +3620,81 @@ public function zdiffstore(string $dst, array $keys): Redis|int|false;
34043620 */
34053621 public function zinter (array $ keys , ?array $ weights = null , ?array $ options = null ): Redis |array |false ;
34063622
3623+ /**
3624+ * Similar to ZINTER but instead of returning the intersected values, this command returns the
3625+ * cardinality of the intersected set.
3626+ *
3627+ * @see https://redis.io/commands/zintercard
3628+ * @see https://redis.io/commands/zinter
3629+ * @see Redis::zinter()
3630+ *
3631+ * @param array $keys One ore more sorted set key names.
3632+ * @param int $limit An optional upper bound on the returned cardinality. If set to a value
3633+ * greater than zero, Redis will stop processing the intersection once the
3634+ * resulting cardinality reaches this limit.
3635+ *
3636+ * @return Redis|int|false The cardinality of the intersection or false on failure.
3637+ *
3638+ * <code>
3639+ * <?php
3640+ * $redis = new Redis(['host' => 'localhost']);
3641+ *
3642+ * $redis->del('zs1', 'zs2');
3643+ *
3644+ * $redis->zAdd('zs1', 1, 'one', 2, 'two', 3, 'three', 4, 'four');
3645+ * $redis->zAdd('zs2', 2, 'two', 4, 'four');
3646+ *
3647+ * // count(['two', 'four']) == 2
3648+ * $redis->zInterCard(['zs1', 'zs2']);
3649+ * ?>
3650+ * </code>
3651+ */
34073652 public function zintercard (array $ keys , int $ limit = -1 ): Redis |int |false ;
34083653
3654+ /**
3655+ * Compute the intersection of one ore more sorted sets storing the result in a new sorted set.
3656+ *
3657+ * @see https://redis.io/commands/zinterstore
3658+ * @see https://redis.io/commands/zinter
3659+ *
3660+ * @param string $dst The destination sorted set to store the intersected values.
3661+ * @param array $keys One ore more sorted set key names.
3662+ * @param array $weights An optional array of floats to weight each passed input set.
3663+ * @param string $aggregate An optional aggregation method to use.
3664+ *
3665+ * 'SUM' - Store sum of all intersected members (this is the default).
3666+ * 'MIN' - Store minimum value for each intersected member.
3667+ * 'MAX' - Store maximum value for each intersected member.
3668+ *
3669+ * @return Redis|int|false The total number of members writtern to the destination set or false on failure.
3670+ *
3671+ * <code>
3672+ * <?php
3673+ * $redis = new Redis(['host' => 'localhost']);
3674+ *
3675+ * $redis->del('zs', 'zs2', 'zs3');
3676+ * $redis->zAdd('zs1', 3, 'apples', 2, 'pears');
3677+ * $redis->zAdd('zs2', 4, 'pears', 3, 'bananas');
3678+ * $redis->zAdd('zs3', 2, 'figs', 3, 'pears');
3679+ *
3680+ * // Returns 1 (only 'pears' is in every set)
3681+ * $redis->zInterStore('fruit-sum', ['zs1', 'zs2', 'zs3']);
3682+ *
3683+ * // Array
3684+ * // (
3685+ * // [pears] => 9
3686+ * // )
3687+ * $redis->zRange('fruit-sum', 0, -1, true);
3688+ *
3689+ * $redis->zInterStore('fruit-max', ['zs1', 'zs2', 'zs3'], NULL, 'MAX');
3690+ *
3691+ * // Array
3692+ * // (
3693+ * // [pears] => 4
3694+ * // )
3695+ * print_r($redis->zRange('fruit-max', 0, -1, true));
3696+ * ?>
3697+ */
34093698 public function zinterstore (string $ dst , array $ keys , ?array $ weights = null , ?string $ aggregate = null ): Redis |int |false ;
34103699
34113700 /**
0 commit comments