120 Commits

Author SHA1 Message Date
michael-grunder
547475295a Introduce "must use attribute"
Conditionally add `[[nodiscard]]` (c23) or
`__attribute__((warn_unused_result))` when the compiler supports it.

This commit initially just adds iit to `cluster_map_keyspace` but we can
go throughour API adding it where appropriate.
2025-10-06 12:52:36 -07:00
michael-grunder
c4b2ea6ca5 Fix VEMB reply handling in RedisCluster 2025-09-01 09:41:12 -07:00
michael-grunder
d80b725824 Implement VGETATTR command 2025-09-01 09:41:12 -07:00
michael-grunder
7f9b1f416e Implement VLINKS command 2025-09-01 09:41:12 -07:00
michael-grunder
1deca62841 Implement VRANDMEMBER
`VRANDMEMBER` has the exact same semantics of `SRANDMEMBER` so make
`SRANDMEMBER` a keyword based command and use it for `VRANDMEMBER`.

See #2543
2025-09-01 09:41:12 -07:00
michael-grunder
0fda9f293b Implement VCARD, VDIM, and VINFO
All of these commands have the same form `<cmd> key`. `VINFO` is a bit
of an outlier however that uses simple strings as opposed to bulk
strings for the key names, meaning we had to create a custom handler.

See #2543
2025-09-01 09:41:12 -07:00
Michael Grunder
ce5b0facc2 Implement HGETEX, HSETEX, HGETDEL, and refactor HMGET (#2667)
* Rework HMGET and implement HGETEX

Instead of using a bespoke NULL terminated `zval**` array for the
context array we can use a `HashTable`. This might be a tiny bit more
expensive but Zend hashtables are quite efficient and this should also
be less error prone.

* Rework our `HashTable` context array to store keys

Instead of sending an array of values we can instead add the fields as
keys to our context array. That way when we combine the keys with the
Redis provided values we can do it in-place and then just give the
HashTable to the user to then do with what they want.

* Implement HGETDEL command.

* Fix edge cases to abide by legacy behavior.

Previously we coerced integer strings into integer keys when zipping
`HMGET` responses. This commit adds logic so we continue to do this and
do not change semantics.

* Implement `HGETDEL` and `HGETEX` for `RedisCluster`.

This commit implements the new commands and reworks the `HMGET` reply
handler to use the new context `HashTable`.

* Fix an edge case where we get zero multiblk elements

* Tests for `HGETEX` and `HGETDEL`

* Minor logic improvement

We don't need to check if `c->reply_len > 0` in the last else block
since we have already determined it must be.

* Implement `HSETEX` for `Redis` and `RedisCluster`

* Use `zval_get_tmp_string` ro populating non-long keys
2025-07-16 16:46:09 -07:00
Michael Grunder
0445e683e7 Refactor getWithMeta logic (#2643)
* Refactor `getWithMeta`

* Consolidate `getWithMeta()` test.

* Review comments
2025-03-31 12:42:29 -07:00
Pavlo Yatsukhnenko
9036ffca6a Add getWithMeta method 2025-02-25 16:27:10 +02:00
James Kennedy
c7b8784310 Invalidate slot cache on failed cluster connections 2025-01-20 15:34:53 -08:00
michael-grunder
2612d444e5 Update RedisCluster scan logic for large SCAN cursors.
We also need to update the `RedisCluster` logic to handle very large
curosr values, in addition to handling them for the `Redis` and
`RedisArray` classes.

See #2454, #2458
2024-03-18 11:54:02 -07:00
Viktor Szépe
37c5f8d451 Fix typos 2024-02-21 13:16:12 -08:00
Pavlo Yatsukhnenko
7a055cada8 Use on-stack allocated valiables 2023-04-02 18:44:11 +03:00
michael-grunder
ccd419a4c8 Small refactor of some methods
* Use our `redis_cmd_append_sstr_key_*` and `redis_cmd_append_sstr_zval`
  wrappers, which handle key prefixing and serialization transparently.

* Rework ZADD so it can handle the bulk double response from the `INCR`
  options.
2023-03-01 11:45:47 -08:00
michael-grunder
acb5db7661 Refactor OBJECT command. 2022-12-06 12:42:29 -08:00
michael-grunder
f62363c2a3 Refactor SRANDMEMBER command. 2022-12-06 10:46:32 -08:00
michael-grunder
27900f39d2 Implement new ZSET commands for cluster
* Implement `ZDIFF`, `ZINTER`, `ZUNION`, `ZMSCORE`, and
  `ZRANDMEMBER` for `RedisCluster`.
* Refactor `ZUNIONSTORE` command and switch to using our centralized
  zset option parsing handler.

See #1894
2022-12-02 09:11:00 -08:00
michael-grunder
e222b85ecf Implement HRANDFIELD for RedisCluster
See #1894
2022-12-01 22:12:19 -08:00
Michael Grunder
fa5d1af9ff Implement GEOSEARCH and GEOSEARCHSTORE for RedisCluster. (#2277)
* Implement GEOSEARCH and GEOSEARCHSTORE for RedisCluster.

See #1894
2022-12-01 21:54:15 -08:00
michael-grunder
7121aaae5c Implement LPOS for RedisCluster
See #1894
2022-12-01 14:05:43 -08:00
michael-grunder
90828019de Refactor network IO tracking.
* Create inline wrappers of the low-level php_stream_* functions that
  also keep track of the number of bytes written/read.

* Change the logic to aggregate network traffic until the user
  explicitly "resets" it.  I think this will be a more common use-case
  (running many commands and then seeing overall network IO).

See #2106
2022-11-25 13:41:47 -08:00
Pavlo Yatsukhnenko
1d6c52ee39 Small cosmetic changes in cluster_library 2022-10-26 12:16:32 -07:00
michael-grunder
71bcbcb973 Implement ZRANGESTORE and add ZRANGE options
* Add ZRANGESTORE command.

* Add Redis 6.2's `REV`, `BYLEX`, and `BYSCORE` to ZRANGE options.

* Refactor several ZRANGE family commands into a single reply and
  options handler, using PHP's new argument parsing macros.

* Extend our tests to use the new ZRANGE options.

See #1894
2022-10-22 12:46:01 -07:00
michael-grunder
6ea978eb72 [B]LMPOP and [B]ZMPOP commands
Implement the new Redis 7.0.0 commands to pop multiple elements from one
or more lists/zsets.

Additionally, remove INTERNAL_FUNCTION_PARAMETERS from the
redis_sock_read_multibulk_reply_zval helper function as it wasn't
actually being used.
2022-10-08 09:23:13 -07:00
michael-grunder
6430050808 SINTERCARD and ZINTERCARD commands
Implement Redis 7.0.0 commands SINTERCARD and ZINTERCARD.
2022-10-01 10:42:23 -07:00
Michael Grunder
b3ce048669 Fix non standards conforming prototypes. (#2150)
These now generate warnings with GCC 13
2022-09-14 22:54:22 -07:00
Pavlo Yatsukhnenko
df97cc3531 Issue #1894
Add the COUNT argument to LPOP and RPOP
2022-06-07 18:51:55 +03:00
Pavlo Yatsukhnenko
5a269ab6d0 Don't allow reconnect on read response 2022-04-03 19:52:18 +03:00
Bar Shaul
12bf3fddac Added support for remapping the cluster's keyspace on a failover 2021-10-28 12:10:55 +03:00
Pavlo Yatsukhnenko
b0b9dd78ef [WIP] Issue #1894
Add GET option to SET command
2021-04-10 21:26:29 +03:00
Michael Grunder
950e8de807 Issue.1847 cluster segfault (#1850)
Fix for #1847 when dealing with NULL multi bulk replies in RedisCluster.

Adds `Redis::OPT_NULL_MULTIBULK_AS_NULL` setting to have PhpRedis
treat NULL multi bulk replies as `NULL` instead of `[]`.

Co-authored-by: Alex Offshore <offshore@aopdg.ru>
2020-09-28 11:07:46 -07:00
Pavlo Yatsukhnenko
f771ea16b7 Issue #1607 (#1806) 2020-07-07 13:18:01 -07:00
Michael Grunder
a311cc4ec3 Support for Redis 6 ACLs (#1791)
Add support for Redis 6 ACLs in the `Redis`, `RedisCluster`, and `RedisArray` classes.

On a related note, it adds a mechanism for users to customize how we generate persistent connection IDs such that they can be grouped in different ways depending on the specific use case required (e.g. it would allow connections to be grouped by username, or by user-defined persistent_id, or both).
2020-06-24 17:00:01 -07:00
Michael Grunder
5ca4141c72 Issue.1765 (#1774)
Various improvements and fixes to cluster slot caching.

* Improves slot caching so any unique set of seeds all hash to the same key

* Fix a couple of memory leaks.

* Fixes a segfault when executing a multiple key command such as `MGET` or `MSET` while the cluster is resharding.
2020-06-07 13:50:22 -07:00
Pavlo Yatsukhnenko
58dab5649f Store auth information in cluster->flags->auth 2020-06-05 10:27:48 +03:00
Pavlo Yatsukhnenko
35372a1f64 Authenticate in redis_sock_server_open 2020-03-30 22:34:12 +03:00
Pavlo Yatsukhnenko
460c8f2923 Various small changes in cluster_library 2020-03-10 23:16:35 +02:00
michael-grunder
ba73fbee74 Initial commit of ASK redirection fix
See #1693
2020-01-31 09:14:22 -08:00
Tyson Andre
f52bd8a853 Fix typos detected by codespell 2020-01-06 09:08:36 -05:00
Michael Booth
23b1a9d84c Enable slot caching for session cluster 2019-12-02 09:00:12 +00:00
Remi Collet
943802272a cleanup TSRMLS_* usage 2019-07-09 15:26:44 +02:00
Pavlo Yatsukhnenko
ac9dca0a92 Fix xInfo ro RedisCluster 2019-06-12 13:50:50 +03:00
michael-grunder
5cb30fb2a6 Adds OPT_REPLY_LITERAL for rawCommand and EVAL
Adds an option to process the actual strings in simple string replies as
opposed to translating them to `true`.  This only applies to
`rawCommand` and `eval` because as far as I know know vanilla Redis
command attaches any information besides `OK` to simple string replies.

Addresses #1550
2019-05-13 09:38:18 -07:00
michael-grunder
9f0d7bc0a4 WIP: Reimplementation of cluster slot caching
RedisCluster currently has a high construction overhead because
every request has to issue a CLUSTER SLOTS command to map the
keyspace.  The issue is especially evident when a request only
does a few commands.
2019-02-08 18:08:17 -08:00
michael-grunder
f9928642b5 PHP 5 is dead, long live PHP 7
This commit removes support for PHP 5 by getting rid of all of our Zend
compatibility layer methods, as well as any call checking against
PHP_MAJOR_VERSION or ZEND_MODULE_API_NO.

Unit tests are all passing for Redis, RedisCluster, and RedisArray but
this should still be considered a work in progress until more testing
can be done.

Addresses issue #1448
2019-01-26 20:57:16 -08:00
Pavlo Yatsukhnenko
c5994f2a42 RedisCluster auth 2019-01-17 23:05:52 +02:00
Marc de Jonge
cd6ebc6d7f Reset the socket after a timeout to make sure no wrong data is received (#1417)
* Reset the socket after a timeout to make sure no wrong data is received

* Remove the lazy_connect completely

* Missing TSRMLS_CC

* Remove redundant check if the stream exists

* Add the redis_sock_server_open to the CLUSTER_SEND_PAYLOAD macro
2018-10-08 08:57:51 +03:00
Michael Grunder
2c9e057236 Streams (#1413)
Streams API
2018-09-29 11:59:01 -07:00
Pavlo Yatsukhnenko
1d99787375 Change connect/reconnect logic
Persistant connections can be closed via close method.
Connection marked as failed only after reconnection attempts.
2018-08-22 09:02:31 +03:00
Pavlo Yatsukhnenko
28ec432247 Issue #1358
Use `cluster_free` in `free_cluster_context` to free cluster object.
Call `cluster_disconnect` before destroying cluster object.
2018-05-31 11:24:28 +03:00