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

Skip to content

Commit bb06ffa

Browse files
Documentation: Even more docblocks
1 parent 980ea6b commit bb06ffa

3 files changed

Lines changed: 191 additions & 19 deletions

File tree

redis.stub.php

Lines changed: 182 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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
/**

redis_arginfo.h

Lines changed: 7 additions & 7 deletions
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: 55e15f9e5c33b941552643c0302becdc3241212e */
2+
* Stub hash: 357d950a0dd1960a29c514c47385a0d9a5e422b2 */
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")
@@ -762,15 +762,15 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_set, 0, 2, Redis
762762
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_MIXED, 0, "NULL")
763763
ZEND_END_ARG_INFO()
764764

765-
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_setBit, 0, 0, 3)
765+
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_setBit, 0, 3, Redis, MAY_BE_LONG|MAY_BE_FALSE)
766766
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
767767
ZEND_ARG_TYPE_INFO(0, idx, IS_LONG, 0)
768768
ZEND_ARG_TYPE_INFO(0, value, _IS_BOOL, 0)
769769
ZEND_END_ARG_INFO()
770770

771-
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_setRange, 0, 0, 3)
771+
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_setRange, 0, 3, Redis, MAY_BE_LONG|MAY_BE_FALSE)
772772
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
773-
ZEND_ARG_TYPE_INFO(0, start, IS_LONG, 0)
773+
ZEND_ARG_TYPE_INFO(0, index, IS_LONG, 0)
774774
ZEND_ARG_TYPE_INFO(0, value, IS_STRING, 0)
775775
ZEND_END_ARG_INFO()
776776

@@ -781,13 +781,13 @@ ZEND_END_ARG_INFO()
781781

782782
#define arginfo_class_Redis_setex arginfo_class_Redis_psetex
783783

784-
#define arginfo_class_Redis_setnx arginfo_class_Redis_lPushx
785-
786-
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_sismember, 0, 2, Redis, MAY_BE_BOOL)
784+
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_setnx, 0, 2, Redis, MAY_BE_BOOL)
787785
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
788786
ZEND_ARG_TYPE_INFO(0, value, IS_MIXED, 0)
789787
ZEND_END_ARG_INFO()
790788

789+
#define arginfo_class_Redis_sismember arginfo_class_Redis_setnx
790+
791791
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_slaveof, 0, 0, Redis, MAY_BE_BOOL)
792792
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, host, IS_STRING, 0, "NULL")
793793
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, port, IS_LONG, 0, "6379")

redis_legacy_arginfo.h

Lines changed: 2 additions & 6 deletions
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: 55e15f9e5c33b941552643c0302becdc3241212e */
2+
* Stub hash: 357d950a0dd1960a29c514c47385a0d9a5e422b2 */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis___construct, 0, 0, 0)
55
ZEND_ARG_INFO(0, options)
@@ -651,11 +651,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_setBit, 0, 0, 3)
651651
ZEND_ARG_INFO(0, value)
652652
ZEND_END_ARG_INFO()
653653

654-
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_setRange, 0, 0, 3)
655-
ZEND_ARG_INFO(0, key)
656-
ZEND_ARG_INFO(0, start)
657-
ZEND_ARG_INFO(0, value)
658-
ZEND_END_ARG_INFO()
654+
#define arginfo_class_Redis_setRange arginfo_class_Redis_lSet
659655

660656
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_setOption, 0, 0, 2)
661657
ZEND_ARG_INFO(0, option)

0 commit comments

Comments
 (0)