In a redis db I gotta save two things, 2. the hash of a question image, then a list of…
- User
In a redis db I gotta save two things, 2. the hash of a question image, then a list of hashes of answer images to those questions. How should i implement this in python so i can search for a question, then get a list of answers. The whole system works only on hashes so the code does not need any example questions or images just placeholder phash hashes. Make functions for adding a new question hash without any answers, the make one to add a answer has to a specified question hash
- Assistant
You can implement this functionality using the Redis Python client, such as the
redis-pylibrary. Here's an example implementation:First, import the necessary libraries and establish a connection to the Redis database:
pythonimport redis # Establish Redis connection redis_db = redis.Redis(host='localhost', port=6379, db=0)Next, define the functions to add a new question hash and add an answer hash to a specified question hash:
python