phithon
5.05D
V2EX  ›  Redis

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

  •  
  •   phithon ·
    phith0n · Aug 18, 2015 · 7201 views
    This topic created in 4107 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
    zts1993
    Aug 18, 2015
    1
    存储的话上 mongo 啊

    下面认真回答

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