Redis中的dict列表

2024-09-23 10:30:24 发布

您现在位置:Python中文网/ 问答频道 /正文

如何使用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来实现这一点?


Tags: keytestimageredisurl目标列表title
1条回答
网友
1楼 · 发布于 2024-09-23 10:30:24

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

相关问题 更多 >