python - Redis 中的字典列表

标签 python redis

如何使用 Python-redis 在 Redis 中根据键保留字典列表。以下是我针对的数据结构:

'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'}],
}

想要添加到 session 列表以及添加新 session 并检索它们。我如何使用 Python-redis 执行此操作?

最佳答案

pickle 序列化你的字典 {'image': 'image-url', 'url' : 'url', 'title' : 'test_title', 'description' : 'test_description'}json 。使用 redis 列表将它们存储为字符串。使用 browsing_history:SESSION_KEY_1 之类的键访问这些列表。如果您需要获取所有 session key 的列表,您可能需要维护一组 key 字符串 browsing_history:*

关于python - Redis 中的字典列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8664664/

相关文章:

python - 为什么python中的继承要求父类显式继承对象?

python - PMML GBDTLRClassifier 中的分类特征设置错误

database - 雷迪斯 + 路亚。我可以返回结果而不将其存储在内存中吗?

redis - 如何将字节数据转换为 String 或 Lua 中的任何其他类似类型

redis - 如何知道jedis消息有没有推送

python - 拆分每个第 n 个字符串元素并合并到数组中的最佳方法?

python - 如何在执行 Dask 任务之间保留一些 Python 对象状态?

python - 在python中通过正则表达式提取多种日期格式

mysql - 获取与 Redis 中给定模式匹配的哈希的键数 (hlen) 的最大值

Redis事务和watch命令