如何使用Python Redis在Redis中针对密钥保留dict列表。以下是我的目标数据结构:
'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'}],
}
希望将添加到会话列表中,以及添加新会话并重试它们。如何使用Python redis来实现这一点?
用pickle或json序列化字典
{'image': 'image-url', 'url' : 'url', 'title' : 'test_title', 'description' : 'test_description'}
。使用redis list将它们存储为字符串。使用像browsing_history:SESSION_KEY_1
这样的键来访问这些列表。如果需要获取所有会话密钥的列表,则可能需要为密钥browsing_history:*
维护一组字符串。相关问题 更多 >
编程相关推荐