phithon
5.05D
V2EX  ›  Redis

是否使用 redis 里的复杂数据结构

  •  
  •   phithon ·
    phith0n · Aug 18, 2015 · 6795 views
    This topic created in 3943 days ago, the information mentioned may be changed or developed.

    最近开发一个 python 的扫描器,存储数据使用的 redis
    不过有点纠结,比如我的一个扫描结果是一个 dict

    {"target":"http://xxx/","whois":"[email protected]","real_ip":"127.0.0.1"}
    

    这样的,我是先将他 json 化(或序列化)后以字符串的形式存入 redis 呢,还是使用 redis 内部的 Hashes 数据结构来存呢?
    哪个效率比较高?全局考虑一下。

    9 replies    2015-10-09 14:43:33 +08:00
    zts1993
        1
    zts1993  
       Aug 18, 2015
    存储的话上 mongo 啊

    下面认真回答

    用内部 hash table 可以节约内存
    zts1993
        2
    zts1993  
       Aug 18, 2015
    @zts1993 hash 没有 table ,手误
    shiny
        3
    shiny  
    PRO
       Aug 18, 2015
    如果你经常只需要取其中一个字段里的内容,可以考虑用 hash
    tczzjin
        4
    tczzjin  
       Aug 18, 2015
    如果你的一个 dict 里面的字段不超过 1W 个,那么整个存到一个 hash 非常好,ziplist,hashmap 等等的效率和内存 redis 内置的优化很赞
    keakon
        5
    keakon  
       Aug 18, 2015
    没特殊需求不要用一个 hash 存一个对象,会丢失数据类型,浪费内存。
    est
        6
    est  
       Aug 18, 2015
    需要对 hash 里的字段进行查询,修改就用 hash ,如果只是用来保存,整存整取,就存 json 字符串。
    phithon
        8
    phithon  
    OP
       Aug 19, 2015
    @keakon
    @est
    嗯,因为都是整存整取,所以存 json 比较好
    memorycancel
        9
    memorycancel  
       Oct 9, 2015
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   962 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 44ms · UTC 21:54 · PVG 05:54 · LAX 14:54 · JFK 17:54
    ♥ Do have faith in what you're doing.