897 Commits

Author SHA1 Message Date
michael-grunder 085d61ecfb Create a strncmp wrapper
On some glibc implementations strncmp is a macro. This commit simply creates a
`redis_strncmp` static inline wrapper function so we can `ZEND_STRL` instead of
manually counting the length or using `sizeof(s)-1` each time.

Fixes #2565
2024-10-15 10:40:15 -07:00
michael-grunder 50529f56e4 Context array should be nullable
Fixes #2521
2024-07-10 12:33:37 -07:00
Michael Grunder 7050c98909 Play around with more ZEND_STRL usage (#2505)
* Play around with more ZEND_STRL usage

* strncasecmp is a macro on Windows
2024-06-15 14:48:30 -07:00
michael-grunder f8c762e70b Use ZEND_STRL where appropriate.
Use the `ZEND_STRL` macro in several places rather than manually sending
a static string and its length as a constant.
2024-06-01 13:41:26 -07:00
michael-grunder e18f6c6d9e Minor refactor 2024-05-28 20:32:50 -07:00
bitactive da4ab0a72c Add compression support for PHP Sessions (#2473)
* Add compression support for PHP Sessions

Previously, compression was available for standard data but not for
session handling. This update enables the compression of PHP sessions,
allowing for more efficient Redis memory usage.

* Move session compress/uncompress logic to helper functions

* Change session_compress_data to always set the out arguments and adjust PS_READ_FUNC
2024-04-08 14:40:15 -07:00
Pavlo Yatsukhnenko a9e53fd16e Fix segfault and remove redundant macros
Replace `SOCKET_WRITE_COMMAND` with `redis_sock_write` because it can't be used
with pre-defined commands (it frees memory in case of failed writing operation).
After replacement `SOCKET_WRITE_COMMAND` becomes redundant so remove it.
2024-03-21 15:14:36 +02:00
michael-grunder a51215ce2b Update random includes.
PHP 8.4 has some breaking changes with respect to where PHP's random methods and
helpers are.  This commit fixes those issues while staying backward compatible.

Fixes #2463
2024-03-18 15:14:07 -07: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
michael-grunder e52f0afaed Update SCAN to handle very large cursor values.
Technically Redis may return any unsigned 64 bit integer as a scan
cursor.  This presents a problem for PHP in that PHP's integers are
signed.  Because of that if a scan cursor is > 2^63 it will overflow and
fail to work properly.

This commit updates our SCAN family of commands to deliver cursors in
their string form.

```php
public function scan(null|int|string $iterator, ...);
```

On initial entry into our SCAN family we convert either a NULL or empty
string cursor to zero, and send the initial scan command.

As Redis replies with cursors we either represent them as a long (if
they are <= ZEND_ULONG_MAX) and as a string if greater.  This should
mean the fix is minimally breaking as the following code will still
work:

```php
$it = NULL;
do {
    print_r($redis->scan($it));
} while ($it !== 0);
```

The `$it !== 0` still works because the zero cursor will be represented
as an integer.  Only absurdly large (> 2^63) values are represented as a
string.

Fixes #2454
2024-03-17 10:59:14 -07:00
michael-grunder fa1a283ac9 Fix some typos 2024-03-13 13:46:58 -07:00
michael-grunder ed7c9f6f63 Implement WAITAOF command. 2024-02-14 12:03:29 -08:00
Pavlo Yatsukhnenko b835aaa3f9 Fix deprecation error when passing null to match_type parameter 2023-10-13 17:50:37 +03:00
Pavlo Yatsukhnenko 362e1141a3 Fix memory leak and segfault in Redis::exec 2023-09-23 14:11:45 +03:00
thomaston a3327d9d2b Fix bug: the pipeline mode socket return an unexpected result after reconnecting (#2358)
* fix bug: the pipeline mode socket return an unexpected result after reconnecting

* fix typos: pipeline is right

---------

Co-authored-by: marcofu <marcofu@tencent.com>
2023-07-20 11:48:53 -07:00
Pavlo Yatsukhnenko 7a055cada8 Use on-stack allocated valiables 2023-04-02 18:44:11 +03:00
Pavlo Yatsukhnenko f6c8b9c6d1 Use redis_sock_connect on connect 2023-04-02 13:46:21 +03:00
Pavlo Yatsukhnenko 2b2bc042da Merge pull request #2327 from phpredis/sentinel
Synchronize Redis and RedisSentinel constructors
2023-03-01 22:08:12 +02: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
Pavlo Yatsukhnenko 5a643b62d2 Use didicated zval to store result 2023-02-14 20:38:22 +02:00
Pavlo Yatsukhnenko ebb2386e52 Synchronize Redis and RedisSentinel constructors 2023-02-12 22:33:45 +02:00
Pavlo Yatsukhnenko d9cb594678 Fix redis_sock_read_multibulk_multi_reply_loop logic 2023-02-11 22:40:06 +02:00
Pavlo Yatsukhnenko 7c46ad2c05 Issue #2068
Add FCALL/FCALL_RO commands
2022-12-24 13:37:50 +02:00
Pavlo Yatsukhnenko 90a0e9cc0e Add Redis::function command 2022-12-18 18:21:42 +02:00
michael-grunder 6d10448109 Refactor MSET and MSETNX commands.
Switch to using our normal command handling logic for MSET and MSETNX.
2022-12-10 11:57:24 -08:00
michael-grunder 3574ef0867 Refactor INFO and SCRIPT commands.
Use `gen_varkey_cmd` for INFO and SCRIPT.
2022-12-10 11:45:08 -08:00
michael-grunder 8cb6dd17fe Refactor MGET command. 2022-12-07 11:18:25 -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 86f15ccaa1 Refactor SELECT command.
* Use our common command handler logic for SELECT.

* Shift updating `redis_sock->dbNumber` from the command itself to the
  reply handler, so we aren't erroneously pointing to a non-existent
  database before the command succeeds.
2022-12-06 10:46:17 -08:00
zorro-fr24 b6cf6361dd Add cluster support for strict sessions and lazy write
* Add ini setting redis.session.early_refresh to allow for session TTL updates on session start ( requires redis server version 6.2 or greater )
 * Enable cluster session support for strict mode sessions ( via PS_VALIDATE_SID_FUNC )
 * Cluster sessions used to write on every session, now we only write if the session has been modified.
 * Send EXPIRE instead of SETEX if sessioh has not been changed
 * If early refresh is enabled use GETEX for initial session read
 * When strict sessions are enabled, check whether the session exists first, validate sid and regenerate if necessary
2022-12-06 10:45:52 -08:00
michael-grunder 79c9d2241f Refactor rawCommand and WAIT 2022-12-03 23:32:24 -08:00
michael-grunder 121e9d9c29 Implement BLMOVE and add LMOVE/BLMOVE to cluster.
* Refactor `redis_lmove_cmd` to work for both `LMOVE` and `BLMOVE`
* Implement `LMOVE` and `BLMOVE` in RedisCluster.

See #1894
2022-12-01 13:48:03 -08:00
Pavlo Yatsukhnenko 7644736e13 Issue #2068, ssubscribe/sunsubscribe 2022-12-01 22:19:15 +02: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
michael-grunder 2a6dee5d4d Use PHP's new class constant mechanism.
Let gen_stub.php define the constants for us, including deriving their
actual values from C defines.

As a side-effect we have to drop support for PHP < 7.2 as it does not
have interned strings.
2022-11-24 09:26:44 -08:00
Pavlo Yatsukhnenko ff863f3f97 Refactor command command
Issue #2068
2022-11-19 14:04:38 +02:00
Pavlo Yatsukhnenko 504810a5d1 Issue #2068, Refactor ACL command 2022-11-01 12:53:23 +02:00
michael-grunder f2cef8be06 More docblocks and refactor SLAVEOF command.
Add additional complete docblocks for a few more commands.

Refactor SLAVEOF handler to conform with more modern PhpRedis command
handlers.

Create REPLICAOF and deprecate SLAVEOF as Redis has done since 5.0.0.
2022-10-31 22:32:43 -07:00
Pavlo Yatsukhnenko 2a0d1c1e6d Refactor PubSub command 2022-10-31 17:01:35 -07:00
Pavlo Yatsukhnenko 2bb6403883 Issue #1894
Add the CH, NX, XX arguments to GEOADD
2022-10-30 12:00:12 -07:00
michael-grunder dc1f2398d0 TOUCH command
Implement the TOUCH command and refactor several of our "variadic key"
commands, which were previously all using their own specific handlers.

While refactoring the code, I changed `EXISTS` to require one key (it
had previously been set to require zero keys).

Additonally, it looks like we had a disparity in two commands which
should be idential to PhpRedis:  SINTERSTORE and SUNIONSTORE.
Previously, SINTERSTORE required only one argument but SUNIONSTORE 2.

I simply changed SUNIONSTORE to also only require a single argument,
since that argument could be an array.

```php
$redis->sInterStore(['dst', 'src1', 'src2']);
$redis->sUnionStore(['dst', 'src1', 'src2']);
```
2022-10-26 01:38:42 -07:00
Pavlo Yatsukhnenko d73f3f4b08 Issue #2106 2022-10-24 09:17:22 +03:00
michael-grunder 8c7c5a3aa2 Refactor SORT and add SORT_RO command
See #2068
2022-10-23 13:18:13 -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 f3a408305a EVAL_RO and EVALSHA_RO
Implement Redis 7.0.0's readonly eval variants

See: #2068
2022-10-21 23:35:09 -07:00
michael-grunder d87f142826 Refactor SLOWLOG command
Refactor the slowlog command to use the new argument parsing API and
also change it so we no longer manually handle atomic/non-atomic
logic in the handler itself.
2022-10-19 12:58:39 -07:00
michael-grunder 36ef4bd8d1 Variadic CONFIG GET/SET
Redis 7.0.0 allows for getting and setting multiple config values as an
atomic operation.  In order to support this while maintaining backward
compatibility, the CONFIG command is reworked to also accept an array of
values or keys and values.

See: #2068
2022-10-19 09:15:16 -07:00
michael-grunder 44d03ca00a INFO with multiple sections
See #2068
2022-10-16 11:31:43 -07:00
michael-grunder 872ae1079f Implement Redis 7.0.0 [P]EXPIRE[AT] options
See #2068
2022-10-13 11:31:28 -07:00