Home >Backend Development >PHP Tutorial >Does the picture belong to resource? If so, how to store the picture into redis/memcached memory?
redis/memcached cannot store resources into cache, so are pictures considered resources?
Is there a way to store images in server memory, just like normal data.
(not the front-end expires cache, but stored in the server memory cache)
redis/memcached cannot store resources into cache, so are pictures considered resources?
Is there a way to store images in server memory, just like normal data.
(not the front-end expires cache, but stored in the server memory cache)
Read the image file content directly and put it directly into redis.
Redis is binary safe and can be stored with confidence.
<code><?php /** @var Redis $redis */ /** @var string $filename */ // store.php $img = file_get_contents($filename); $redis->set('img', $img); // show.php $img = $redis->get('img'); header('Content-Type: image/png'); // you may change image/png to image/jpeg if you pic is jpeg. header('Content-Length: ' . strlen($img)); echo $img;</code>
Convert the image to base64
and then store it in redis