I set Redis as a shared sevice in my application, as following:

$di->setShared('imagesCache', function () {
    $config = $this->getConfig();
    $redis = new Redis();
    if (!empty($auth = $config->cache->images_cache->auth)) {
        $redis->auth($auth);
    }
    $redis->pconnect(
        $config->cache->images_cache->host,
        $config->cache->images_cache->port
    );
    $redis->select($config->cache->images_cache->database);
    return $redis;
});

I use this service to fetch some data from Redis cache, the problem is when requesting GET /products, it fetches the images for the first product and the others not. Products are saved in DB0 in Redis and the images on DB01. The images are saved as hash-keys in DB01 like this: product:sample-product-id => [image1, image2, image3, ...] .

I traced the code line by line to find out what's going on without any luck to know the main cause.

On the other hand, when I set Redis as a non-shared service, it works fine, but this is not optimal for me to initiate a new connnection each time I want to fetch images for each product.

Any one faced this before ?