cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

[NFR]: `deleteMultiple()` is documented for Cache, but not implemented in Redis adapter

Open kunalray1993 opened this issue 8 months ago • 2 comments

Describe the bug

The cache documentation for Phalcon 5.9 shows that deleteMultiple() is available under cache operations:

  • delete
  • deleteMultiple
  • clear

However, when using Redis cache, calling deleteMultiple() results in the method not being found.

After checking the source code, I found that deleteMultiple() is not actually implemented in the Redis cache adapter, even though it is documented as supported.

Documentation reference

The current documentation states that deleteMultiple() can be used to delete multiple keys in one call:
Phalcon docs: Cache -> delete - deleteMultiple - clear

Expected behavior

Since the method is documented, deleteMultiple() should be implemented and callable when using the Redis cache adapter.

Also, Redis itself supports deleting multiple keys in a single command (DEL key1 key2 ...), so this can be implemented efficiently.

Actual behavior

Calling deleteMultiple() on Redis cache results in an error because the method is missing / not implemented.

Why this matters

Without deleteMultiple(), applications have to delete keys one by one, which leads to multiple Redis calls instead of a single bulk delete.

For example, with a custom implementation in my project that extends Phalcon\Cache\Adapter\Redis, Redis receives:

"DEL" "cache-key-1" "cache-key-2" "cache-key-3" "cache-key-4" "cache-key-5" "cache-key-6" "cache-key-7" "cache-key-8"

Sample code

for ($i = 1 ; $i <= 10 ; $i++) {
    $cacheKey = "cache-key-{$i}";
    CacheService::saveCacheData($cacheKey, $i, 60);
}

$cacheKeys = [];
for ($i = 1 ; $i <= 8 ; $i++) {
    $cacheKeys[] = "cache-key-{$i}";
}

CacheService::deleteMultipleCacheData($cacheKeys);

CacheService is our wrapper/service class for Redis cache operations.

Additional notes

I tested a custom implementation by extending Phalcon\Cache\Adapter\Redis and adding deleteMultiple() locally. It works as expected, and Redis executes a single multi-key DEL.

Since the underlying PHP Redis extension already supports multi-key deletion, it would be great if Phalcon either:

  1. Implements deleteMultiple() in the Redis adapter, or
  2. Updates the documentation to clarify that it is not currently supported.

Environment

  • Phalcon version: 5.9 docs referenced
  • Adapter: Redis

Suggested improvement

Implement deleteMultiple(array $keys): bool in the Redis adapter using Redis multi-key DEL (or UNLINK where appropriate).

kunalray1993 avatar Apr 01 '26 11:04 kunalray1993

Actually none of the adapters implement deleteMultiple

I will try to add that.

niden avatar Apr 06 '26 02:04 niden

Resolved in https://github.com/phalcon/cphalcon/pull/16883

Thank you @kunalray1993

niden avatar Apr 06 '26 16:04 niden