Decided to store images in Redis, how to do it correctly? Now I do this:
$redis->set('image_path', 'here is the base64 image code');
I'm not sure this is normal.
Decided to store images in Redis, how to do it correctly? Now I do this:
$redis->set('image_path', 'here is the base64 image code');
I'm not sure this is normal.
It is perfectly ok to store images in Valkey/Redis. Keys and values are both binary-safe
Strings are binary safe, this means that a string can contain any kind of data, for instance a JPEG image or a serialized Ruby object.
A String value can be at max 512 Megabytes in length.
You can store the image in binary instead of base64 and it will be more efficient:
You can do
$client->set('profile_picture', file_get_contents("profile.png"));
Here is my simple example of storing image file into Redis Database and retrieve them as well
from PIL import Image
import redis
from io import BytesIO
output = BytesIO()
im = Image.open("/home/user/im.jpg")
im.save(output, format=im.format)
r = redis.StrictRedis(host='localhost', port= 6379, db =0)
r.set('imgdata', output.getvalue())
output.close()
r.save #redis-cli --raw get 'imgdata' >test.jpg
© 2022 - 2024 — McMap. All rights reserved.