Created
April 6, 2020 05:02
-
-
Save yuhangch/71ab60ea26b65276b0fd1b0c584f6473 to your computer and use it in GitHub Desktop.
Save serialized pictures into redis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pickle | |
import redis | |
class CACHE: | |
def __init__(self, host='127.0.0.1',password='123456'): | |
pool = redis.ConnectionPool(host=host, password=password) | |
self.conn = redis.Redis(connection_pool=pool) | |
def insert_image(self, frame_id, frame): | |
# 将图片序列化存入redis中 | |
b = pickle.dumps(frame) # frame is numpy.ndarray | |
self.conn.set(frame_id,b) | |
def get_image(self, frame_id): | |
# 从redis中取出序列化的图片并进行反序列化 | |
return pickle.loads(self.conn.get(frame_id)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment