3294 Commits

Author SHA1 Message Date
Jakub Onderka
0a85bd824a Simplify redis_unpack method calling
This method always unpack given string to zval, so it is not necessary to check output value
2025-04-02 13:02:52 -07:00
Michael Grunder
60ca48f3ce Redis Cluster does not have SELECT. (#2644) 2025-04-01 11:33:44 -07:00
Michael Grunder
0445e683e7 Refactor getWithMeta logic (#2643)
* Refactor `getWithMeta`

* Consolidate `getWithMeta()` test.

* Review comments
2025-03-31 12:42:29 -07:00
Jakub Onderka
4f6a3ed1e7 New option 'database' for Redis class constructor (#2597)
* New option 'database' for Redis class constructor

Selecting database is very common action after connecting to Redis. This simplifies lazy connecting to Redis, when requested database will be selected after first command.

* More specific exception message when invalid auth or database number is provided

Before it was just 'Redis server went away'

* Rename reselect_db method to redis_select_db and slightly optimise it
2025-03-26 18:05:33 -07:00
Remi Collet
3828c9293b cleanup session temp file (#2641)
* cleanup session temp file

* Fix Deprecated: Automatic conversion of false to array
2025-03-26 15:25:22 -07:00
michael-grunder
52e2b8a788 Prepare for 6.2.0 release 2025-03-24 12:06:17 -07:00
michael-grunder
300c5fb218 Make execHello protected
This lets a subclass override it
2025-03-21 11:23:58 -07:00
michael-grunder
fa3eb00683 Add tests for serverName() and serverVersion() 2025-03-20 14:18:44 -07:00
Pavlo Yatsukhnenko
cbaf095ff7 Allow calling methods only in atomic mode 2025-03-20 10:38:56 -07:00
Pavlo Yatsukhnenko
056c2dbee7 Introduce Redis::serverName and Redis::serverVersion methods
Right now we can't implement `HELLO` command to switch protocol
because we don't support new reply types that come with RESP3.
But we can use `HELLO` reply to expose some server information.
2025-03-20 10:38:56 -07:00
Pavlo Yatsukhnenko
f73f5fcce5 Fix arguments order for SET command
Redis and Valkey doesn't consider command as invalid if order of arguments
is changed but other servers like DragonflyDB does.
In this commit `SET` command is fixed to more strictly follow the specs.
Also fixed usage of `zend_tmp_string` for `ifeq` argument.
2025-03-16 12:10:53 -07:00
michael-grunder
e73130fee0 Fix error length calculation + UB sanity check.
For an error reply we're starting at `buf + 1` so we want `len - 1`. As
a sanity check we now return early if `len < 1`.

Also, make certain that len > 2 for our special detection of `*-1` since
we're doing `memcmp(buf + 1, "-1", 2);`
2025-03-11 09:38:41 -07:00
michael-grunder
d342e4ac18 Implement GETDEL for RedisCluster
Fixes #2629
2025-03-06 10:06:26 -08:00
Pavlo Yatsukhnenko
36ab585039 Merge pull request #2627 from phpredis/feature/with-meta
Add `getWithMeta` method
2025-02-26 16:53:48 +02:00
Pavlo Yatsukhnenko
807f806fe8 Reorganize tests 2025-02-25 17:40:23 +02:00
Pavlo Yatsukhnenko
1b72964e39 Update CHANGELOG.md 2025-02-25 16:27:39 +02:00
Pavlo Yatsukhnenko
9036ffca6a Add getWithMeta method 2025-02-25 16:27:10 +02:00
michael-grunder
abb0f6ccc8 Add details to the option doc block 2025-02-05 14:12:42 -08:00
michael-grunder
29e5cf0d8c Minor refactor of ignroe numbers option
* We want to run the logic if either a serializer OR a compression
  option is set.
* IEE754 doubles can theoretically have a huge number of characters.
2025-02-05 14:12:42 -08:00
michael-grunder
f9ce9429ef Introduce Redis::OPT_PACK_IGNORE_NUMBERS option.
Adds an option that instructs PhpRedis to not serialize or compress
numeric values. Specifically where `Z_TYPE_P(z) == IS_LONG` or
`Z_TYPE_P(z) == IS_DOUBLE`.

This flag lets the user enable serialization and/or compression while
still using the various increment/decrement command (`INCR`, `INCRBY`,
`DECR`, `DECRBY`, `INCRBYFLOAT`, `HINCRBY`, and `HINCRBYFLOAT`).

Because PhpRedis can't be certain that this option was enabled when
writing keys, there is a small runtime cost on the read-side that tests
whether or not the value its reading is a pure integer or floating point
value.

See #23
2025-02-05 14:12:42 -08:00
Pavlo Yatsukhnenko
41e114177a Merge pull request #2618 from phpredis/codeql-v3
Update codeql to v3
2025-02-01 20:20:21 +02:00
Pavlo Yatsukhnenko
a10bca35bb Update codeql to v3 2025-01-31 22:07:21 +02:00
James Kennedy
c7b8784310 Invalidate slot cache on failed cluster connections 2025-01-20 15:34:53 -08:00
michael-grunder
a2eef77f44 Implement Valkey >= 8.1 IFEQ set option
Implement the new `IFEQ` `SET` option that will be included in `Valkey`
8.1.

See: valkey-io/valkey#1324
2025-01-20 08:04:27 -08:00
michael-grunder
faa4bc2086 Don't cast a uint64_t to a long.
We recently updated PhpRedis to handle `SCAN` cursors > 2^63 as strings
(as internally PHP integers are longs).

However, the `redis_build_scan_cmd` took the cursor as a long, which
would overflow if the value was > `2^63`.

This commit simply changes the function to take a `uint64_t` and call
our specific `redis_append_sstr_u64` so we send the cursor to Redis
correctly.

Fixes #2454.
2025-01-13 12:13:44 -08:00
michael-grunder
3f8dba6a44 Regnerate stub hash 2025-01-13 11:08:28 -08:00
Pavlo Yatsukhnenko
9e504ede34 Set priority to 60 2025-01-02 14:40:59 -08:00
OHZEKI Naoki
5cad207637 Fix phpdoc type of '$pattern' 2025-01-02 12:11:49 -08:00
peter15914
43e6cab879 Fix potential NULL dereference
The return value of INI_STR() is always checked for NULL.
2025-01-02 11:34:52 -08:00
Bentley O'Kane-Chase
044b30386f Reduce buffer size for signed integer, strlen(-9223372036854775808) = 20 + 1 for '\0' 2024-12-17 17:08:36 -08:00
Bentley O'Kane-Chase
35c5988027 Formatting improvements 2024-12-17 17:08:36 -08:00
Bentley O'Kane-Chase
138d07b67c Print cursor as unsigned 64 bit integer 2024-12-17 17:08:36 -08:00
Jakub Onderka
f68544f703 Refactor and avoid allocation in rawcommand method 2024-12-10 09:52:35 -08:00
michael-grunder
42a427695e Use defines for callback growth + sanity check
See #2595
2024-12-10 09:51:49 -08:00
Jakub Onderka
a551fdc94c Switch from linked list to growing array for reply callbacks
Reduce allocation and deallocation count and also memory usage when using pipelining
2024-12-09 10:40:39 -08:00
Jakub Onderka
be38856205 Reuse redis_sock_append_auth method
In library.c, there are currently two methods for constructing AUTH command, so we can reuse code from redis_sock_append_auth also in redis_sock_auth_cmd method
2024-12-01 11:44:53 -08:00
Jakub Onderka
571ffbc8e0 Switch pipeline_cmd from smart_str to smart_string
As we don't need to extract zend_string from pipeline_cmd, we can use simple smart_string structure
2024-12-01 11:39:55 -08:00
Jakub Onderka
7895636a3a Remove unused redis_debug_response method from library.c 2024-11-27 11:25:05 -08:00
Jakub Onderka
2434ba294c Optimise HMGET method
Allocate output array to expected size and reuse already allocated string for output array keys
2024-11-27 10:33:42 -08:00
Jakub Onderka
aba09933db Avoid unnecessary allocation in redis_hset_cmd
This will slightly reduce memory usage for HSET command
2024-11-26 18:28:09 -08:00
Jakub Onderka
4082dd07f7 Avoid unnecessary allocation in redis_hdel_cmd
This will slightly reduce memory usage for HDEL command
2024-11-26 18:28:09 -08:00
Jakub Onderka
99650e1545 Avoid unnecessary allocation in redis_key_varval_cmd
This will slightly reduce memory usage for commands like RPUSH, LPUSH, SADD, SREM, etc
2024-11-26 18:28:09 -08:00
Jakub Onderka
f6906470a5 Use zval_get_tmp_string method that is faster when provided zval is string 2024-11-26 18:28:09 -08:00
Jakub Onderka
2a2f908f2b Optimise constructing Redis command string
Instead of snprintf method, use zend_print_long_to_buf that can be inlined
2024-11-26 17:20:11 -08:00
Jakub Onderka
5156e03202 If no command is issued in multi mode, return immutable empty array 2024-11-26 10:39:23 -08:00
Jakub Onderka
426de2bb71 Test for empty pipeline and multi 2024-11-26 10:39:23 -08:00
Jakub Onderka
400503b871 Optimise method array_zip_values_and_scores
Initialize array with know size and reuse already allocated keys
2024-11-26 10:39:23 -08:00
Jakub Onderka
83a19656f4 Faster parameter parsing in redis_key_cmd and redis_key_long_val_cmd 2024-11-26 10:39:23 -08:00
Jakub Onderka
3a2f3f45fc Use immutable empty array in Redis::hKeys 2024-11-26 10:39:23 -08:00
Jakub Onderka
60b5a8860a Use immutable empty array in Redis::exec 2024-11-26 10:39:23 -08:00