File size: 646 Bytes
6fd136c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import os
from typing import List, TypedDict
from uuid import uuid4
import redis

# Define the structure of user input data
class UserInput(TypedDict):
    text: str
    emotions: str
    songs: List[str]

# Class for Redis storage operations
class RedisStorage:
    def __init__(self, host: str, password: str):
        # Initialize Redis client
        self._client = redis.Redis(host=host, port="35043", password=password, ssl=True)

    # Function to store user input data in Redis
    def store(self, data: UserInput) -> bool:
        uid = uuid4()
        response = self._client.json().set(f"data:{uid}", "$", data)
        return response