Skip to content

Commit 70a55f3

Browse files
Documentation: More docblocks for eventual
[skip ci]
1 parent 9934088 commit 70a55f3

3 files changed

Lines changed: 122 additions & 10 deletions

File tree

redis.stub.php

Lines changed: 118 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2044,9 +2044,65 @@ public function srem(string $key, mixed $value, mixed ...$other_values): Redis|i
20442044
*/
20452045
public function sscan(string $key, ?int &$iterator, ?string $pattern = null, int $count = 0): array|false;
20462046

2047-
/** @return Redis|int|false*/
2048-
public function strlen(string $key);
2047+
/**
2048+
* Retrieve the length of a Redis STRING key.
2049+
*
2050+
* @param string $key The key we want the length of.
2051+
*
2052+
* @return Redis|int|false The length of the string key if it exists, zero if it does not, and
2053+
* false on failure.
2054+
*
2055+
* <code>
2056+
* <?php
2057+
* $redis = new Redis(['host' => 'localhost']);
2058+
*
2059+
* $redis->del('string');
2060+
*
2061+
* $redis->set('string', 'foo');
2062+
*
2063+
* // strlen('foo') == 3
2064+
* $redis->strlen('string');
2065+
*
2066+
* $redis->append('string', 'bar');
2067+
*
2068+
* // strlen('foobar') == 6
2069+
* $redis->strlen('string');
2070+
*
2071+
* ?>
2072+
* </code>
2073+
*/
2074+
public function strlen(string $key): Redis|int|false;
20492075

2076+
/**
2077+
* Subscribe to one or more Redis pubsub channels.
2078+
*
2079+
* @param array $channels One or more channel names.
2080+
* @param callable $cb The callback PhpRedis will invoke when we receive a message
2081+
* from one of the subscribed channels.
2082+
*
2083+
* @return bool True on success, false on faiilure. Note that this command will block the
2084+
* client in a subscribe loop, waiting for messages to arrive.
2085+
*
2086+
* <code>
2087+
* <?php
2088+
* $redis = new Redis(['host' => 'localhost']);
2089+
*
2090+
* $redis->subscribe(['channel-1', 'channel-2'], function ($redis, $channel, $message) {
2091+
* echo "[$channel]: $message\n";
2092+
*
2093+
* // Unsubscribe from the message channel when we read 'quit'
2094+
* if ($message == 'quit') {
2095+
* echo "Unsubscribing from '$channel'\n";
2096+
* $redis->unsubscribe([$channel]);
2097+
* }
2098+
* });
2099+
*
2100+
* // Once we read 'quit' from both channel-1 and channel-2 the subscribe loop will be
2101+
* // broken and this command will execute.
2102+
* echo "Subscribe loop ended\n";
2103+
* ?>
2104+
* </code>
2105+
*/
20502106
public function subscribe(array $channels, callable $cb): bool;
20512107

20522108
/**
@@ -2127,16 +2183,67 @@ public function swapdb(int $src, int $dst): Redis|bool;
21272183
*/
21282184
public function time(): Redis|array;
21292185

2186+
/**
2187+
* Get the amount of time a Redis key has before it will expire, in seconds.
2188+
*
2189+
* @param string $key The Key we want the TTL for.
2190+
* @return Redis|int|false (a) The number of seconds until the key expires, or -1 if the key has
2191+
* no expiration, and -2 if the key does not exist. In the event of an
2192+
* error, this command will return false.
2193+
*
2194+
* <code>
2195+
* <?php
2196+
* $redis = new Redis(['host' => 'localhost']);
2197+
*
2198+
* $redis->multi()
2199+
* ->setex('expires_in_60s', 60, 'test')
2200+
* ->set('doesnt_expire', 'persistent')
2201+
* ->del('not_a_key')
2202+
* ->exec();
2203+
*
2204+
* // Returns <= 60
2205+
* $redis->ttl('expires_in_60s');
2206+
*
2207+
* // Returns -1
2208+
* $redis->ttl('doesnt_expire');
2209+
*
2210+
* // Returns -2 (key doesn't exist)
2211+
* $redis->ttl('not_a_key');
2212+
*
2213+
* ?>
2214+
* </code>
2215+
*/
21302216
public function ttl(string $key): Redis|int|false;
21312217

2132-
/** @return Redis|int|false*/
2133-
public function type(string $key);
2218+
/**
2219+
* Get the type of a given Redis key.
2220+
*
2221+
* @see https://redis.io/commands/type
2222+
*
2223+
* @param string $key The key to check
2224+
* @return Redis|int|false The Redis type constant or false on failure.
2225+
*
2226+
* The Redis class defines several type constants that correspond with Redis key types.
2227+
*
2228+
* Redis::REDIS_NOT_FOUND
2229+
* Redis::REDIS_STRING
2230+
* Redis::REDIS_SET
2231+
* Redis::REDIS_LIST
2232+
* Redis::REDIS_ZSET
2233+
* Redis::REDIS_HASH
2234+
* Redis::REDIS_STREAM
2235+
*/
2236+
public function type(string $key): Redis|int|false;
21342237

21352238
/**
21362239
* Delete one or more keys from the Redis database. Unlike this operation, the actual
21372240
* deletion is asynchronous, meaning it is safe to delete large keys without fear of
21382241
* Redis blocking for a long period of time.
21392242
*
2243+
* @see https://redis.io/commands/unlink
2244+
* @see https://redis.io/commands/del
2245+
* @see Redis::del()
2246+
*
21402247
* @param array|string $key_or_keys Either an array with one or more keys or a string with
21412248
* the first key to delete.
21422249
* @param string $other_keys If the first argument passed to this method was a string
@@ -2158,6 +2265,13 @@ public function type(string $key);
21582265
*/
21592266
public function unlink(array|string $key, string ...$other_keys): Redis|int|false;
21602267

2268+
/**
2269+
* Unsubscribe from one or more subscribed channels.
2270+
*
2271+
* @see https://redis.io/commands/unsubscribe
2272+
* @see Redis::subscribe()
2273+
*
2274+
*/
21612275
public function unsubscribe(array $channels): Redis|array|bool;
21622276

21632277
/** @return bool|Redis */

redis_arginfo.h

Lines changed: 3 additions & 5 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: 3cd40e39fce29d74a80c4c7627e52a2b2499a1f4 */
2+
* Stub hash: 7baf9e08800a4280ebbf346f397b3b833d4f03e2 */
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")
@@ -836,9 +836,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_Redis_sscan, 0, 2, MAY_BE_
836836
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, count, IS_LONG, 0, "0")
837837
ZEND_END_ARG_INFO()
838838

839-
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_strlen, 0, 0, 1)
840-
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
841-
ZEND_END_ARG_INFO()
839+
#define arginfo_class_Redis_strlen arginfo_class_Redis_expiretime
842840

843841
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Redis_subscribe, 0, 2, _IS_BOOL, 0)
844842
ZEND_ARG_TYPE_INFO(0, channels, IS_ARRAY, 0)
@@ -855,7 +853,7 @@ ZEND_END_ARG_INFO()
855853

856854
#define arginfo_class_Redis_ttl arginfo_class_Redis_expiretime
857855

858-
#define arginfo_class_Redis_type arginfo_class_Redis_strlen
856+
#define arginfo_class_Redis_type arginfo_class_Redis_expiretime
859857

860858
#define arginfo_class_Redis_unlink arginfo_class_Redis_del
861859

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