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

Skip to content

Commit b04684d

Browse files
Documentation: More docblocks with examples
[skip ci]
1 parent 70a55f3 commit b04684d

4 files changed

Lines changed: 193 additions & 3 deletions

File tree

redis.stub.php

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2404,6 +2404,70 @@ public function zRange(string $key, mixed $start, mixed $end, array|bool|null $o
24042404

24052405
public function zRangeByLex(string $key, string $min, string $max, int $offset = -1, int $count = -1): Redis|array|false;
24062406

2407+
/**
2408+
* Retrieve a range of members from a sorted set by their score.
2409+
*
2410+
* @see https://redis.io/commands/zrangebyscore
2411+
*
2412+
* @param string $key The sorted set to query.
2413+
* @param string $start The minimum score of elements that Redis should return.
2414+
* @param string $end The maximum score of elements that Redis should return.
2415+
* @param array $options Options that change how Redis will execute the command.
2416+
*
2417+
* OPTION TYPE MEANING
2418+
* 'WITHSCORES' bool Whether to also return scores.
2419+
* 'LIMIT' [offset, count] Limit the reply to a subset of elements.
2420+
*
2421+
* @return Redis|array|false The number of matching elements or false on failure.
2422+
*
2423+
* <code>
2424+
* </php
2425+
* $redis = new Redis(['host' => 'localhost']);
2426+
*
2427+
* $redis->del('zs');
2428+
*
2429+
* for ($i = 0; $i < 50; $i++) {
2430+
* $redis->zAdd('zs', $i, "mem:$i");
2431+
* }
2432+
*
2433+
* // Array
2434+
* // (
2435+
* // [0] => mem:0
2436+
* // [1] => mem:1
2437+
* // [2] => mem:2
2438+
* // [3] => mem:3
2439+
* // [4] => mem:4
2440+
* // )
2441+
* $redis->zRangeByScore('zs', 0, 4);
2442+
*
2443+
* // Array
2444+
* // (
2445+
* // [mem:20] => 20
2446+
* // [mem:21] => 21
2447+
* // [mem:22] => 22
2448+
* // [mem:23] => 23
2449+
* // [mem:24] => 24
2450+
* // [mem:25] => 25
2451+
* // [mem:26] => 26
2452+
* // [mem:27] => 27
2453+
* // [mem:28] => 28
2454+
* // [mem:29] => 29
2455+
* // [mem:30] => 30
2456+
* // )
2457+
* $redis->zRangeByScore('zs', 20, 30, ['WITHSCORES' => true]);
2458+
*
2459+
* // Array
2460+
* // (
2461+
* // [mem:25] => 25
2462+
* // [mem:26] => 26
2463+
* // [mem:27] => 27
2464+
* // [mem:28] => 28
2465+
* // [mem:29] => 29
2466+
* // )
2467+
* $redis->zRangeByScore('zs', 20, 30, ['WITHSCORES' => true, 'LIMIT' => [5, 5]]);
2468+
* ?>
2469+
* </code>
2470+
*/
24072471
public function zRangeByScore(string $key, string $start, string $end, array $options = []): Redis|array|false;
24082472

24092473
/**
@@ -2427,12 +2491,138 @@ public function zRangeByScore(string $key, string $start, string $end, array $op
24272491
public function zrangestore(string $dstkey, string $srckey, string $start, string $end,
24282492
array|bool|null $options = NULL): Redis|int|false;
24292493

2494+
/**
2495+
* Retrieve one or more random members from a Redis sorted set.
2496+
*
2497+
* @see https://redis.io/commands/zrandmember
2498+
*
2499+
* @param string $key The sorted set to pull random members from.
2500+
* @param array $options One or more options that determine exactly how the command operates.
2501+
*
2502+
* OPTION TYPE MEANING
2503+
* 'COUNT' int The number of random members to return.
2504+
* 'WITHSCORES' bool Whether to return scores and members instead of
2505+
* just members.
2506+
* <code>
2507+
* <?php
2508+
* $redis = new Redis(['host' => 'localhost']);
2509+
*
2510+
* $redis->multi()->del('zs')->zadd('zs', 1, 'one', 2, 'two', 3, 'three')->exec();
2511+
*
2512+
* // Return two random members from our set, with scores
2513+
* $redis->zRandMember('zs', ['COUNT' => 2, 'WITHSCORES' => true]);
2514+
*
2515+
* ?>
2516+
* </code>
2517+
*/
24302518
public function zRandMember(string $key, array $options = null): Redis|string|array;
24312519

2520+
/**
2521+
* Get the rank of a member of a sorted set, by score.
2522+
*
2523+
* @see https://redis.io/commands/zrank
2524+
*
2525+
* @param string $key The sorted set to check.
2526+
* @param mixed $memeber The member to test.
2527+
*
2528+
* <code>
2529+
* <?php
2530+
* $redis = new Redis(['host' => 'localhost']);
2531+
*
2532+
* $redis->multi()->del('zs')->zadd('zs', 0, 'zero', 1, 'one', 2, 'two', 3, 'three')->exec();
2533+
*
2534+
* // Rank 0
2535+
* $redis->zRank('zs', 'zero');
2536+
*
2537+
* // Rank 3
2538+
* $redis->zRank('zs', 'three');
2539+
*
2540+
* ?>
2541+
* </code>
2542+
*
2543+
*/
24322544
public function zRank(string $key, mixed $member): Redis|int|false;
24332545

2546+
/**
2547+
* Remove one or more members from a Redis sorted set.
2548+
*
2549+
* @see https://redis.io/commands/zrem
2550+
*
2551+
* @param mixed $key The sorted set in question.
2552+
* @param mixed $member The first member to remove.
2553+
* @param mixed $other_members One or more members to remove passed in a variadic fashion.
2554+
*
2555+
* @return Redis|int|false The number of members that were actually removed or false on failure.
2556+
*
2557+
* <code>
2558+
* <?php
2559+
* $redis = new Redis(['host' => 'localhost']);
2560+
*
2561+
* $redis->del('zs');
2562+
*
2563+
* for ($i = 0; $i < 10; $i++) {
2564+
* $redis->zAdd('zs', $i, "mem:$i");
2565+
* }
2566+
*
2567+
* // Remove a few elements
2568+
* $redis->zRem('zs', 'mem:0', 'mem:1', 'mem:2', 'mem:6', 'mem:7', 'mem:8', 'mem:9');
2569+
*
2570+
* // Array
2571+
* // (
2572+
* // [0] => mem:3
2573+
* // [1] => mem:4
2574+
* // [2] => mem:5
2575+
* // )
2576+
* $redis->zRange('zs', 0, -1);
2577+
* ?>
2578+
*/
24342579
public function zRem(mixed $key, mixed $member, mixed ...$other_members): Redis|int|false;
24352580

2581+
/**
2582+
* Remove zero or more elements from a Redis sorted set by legographical range.
2583+
*
2584+
* @see https://redis.io/commands/zremrangebylex
2585+
* @see Redis::zrangebylex()
2586+
*
2587+
* @param string $key The sorted set to remove elements from.
2588+
* @param string $min The start of the lexographical range to remove.
2589+
* @param string $max The end of the lexographical range to remove
2590+
*
2591+
* @return Redis|int|false The number of elements removed from the set or false on failure.
2592+
*
2593+
* <code>
2594+
* <?php
2595+
* $redis = new Redis(['host' => 'localhost']);
2596+
*
2597+
* $redis->pipeline()->del('zs')
2598+
* ->zAdd('zs', 1, 'apple', 2, 'banana', 3, 'carrot', 4, 'date', 5, 'eggplant')
2599+
* ->exec();
2600+
*
2601+
*
2602+
* // Remove a* (inclusive) .. b* (exclusive), meaning 'apple' will be removed, but 'banana' not
2603+
* $redis->zRemRangeByLex('zs', '[a', '(b');
2604+
*
2605+
* // Array
2606+
* // (
2607+
* // [0] => banana
2608+
* // [1] => carrot
2609+
* // [2] => date
2610+
* // [3] => eggplant
2611+
* // )
2612+
* print_r($redis->zRange('zs', 0, -1));
2613+
*
2614+
* // Remove the elements between 'banana' and 'eggplant'
2615+
* $redis->zRemRangeByLex('zs', '(banana', '(eggplant');
2616+
*
2617+
* // Array
2618+
* // (
2619+
* // [0] => banana
2620+
* // [1] => eggplant
2621+
* // )
2622+
* print_r($redis->zRange('zs', 0, -1));
2623+
* ?>
2624+
* </code>
2625+
*/
24362626
public function zRemRangeByLex(string $key, string $min, string $max): Redis|int|false;
24372627

24382628
public function zRemRangeByRank(string $key, int $start, int $end): 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: 7baf9e08800a4280ebbf346f397b3b833d4f03e2 */
2+
* Stub hash: 08c0be22623f22153c7df080cfb93388b73fa259 */
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_commands.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,7 @@ static int redis_cmd_append_sstr_score(smart_string *dst, zval *score) {
10651065
return SUCCESS;
10661066

10671067
/* Nothing appended, failure */
1068-
php_error_docref(NULL, E_WARNING, "Weights must be numeric or '-inf','inf','+inf'");
1068+
php_error_docref(NULL, E_WARNING, "scores must be numeric or '-inf', 'inf', '+inf'");
10691069
return FAILURE;
10701070
}
10711071

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: 7baf9e08800a4280ebbf346f397b3b833d4f03e2 */
2+
* Stub hash: 08c0be22623f22153c7df080cfb93388b73fa259 */
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)