Redis中的Dicts列表

Sid*_*rth 5 python redis

如何使用Python-redis将Redis中的dicts列表与密钥保持一致.以下是我的目标数据结构:

'browsing_history' : {
    'session_key_1' : [{'image': 'image-url', 'url' : 'url', 'title' : 'test_title', 'description' : 'test_description'}, {''image': 'image-url2', 'url' : 'url2', 'title' : 'test_title2', 'description' : 'test_description2'}],
    'session_key_2' : [{'image': 'image-url', 'url' : 'url', 'title' : 'test_title', 'description' : 'test_description'}, {''image': 'image-url2', 'url' : 'url2', 'title' : 'test_title2', 'description' : 'test_description2'}],
}
Run Code Online (Sandbox Code Playgroud)

想要添加到会话列表中以及添加新会话以及还原它们.我怎么能用Python-redis做到这一点?

Ski*_*Ski 8

{'image': 'image-url', 'url' : 'url', 'title' : 'test_title', 'description' : 'test_description'}picklejson序列化你的字典.使用redis列表将它们存储为字符串.使用密钥browsing_history:SESSION_KEY_1来访问这些列表.如果需要获取所有会话密钥的列表,则可能需要维护一组密钥字符串browsing_history:*.