corningsun
0.05D
V2EX  ›  Redis

Redis keys 的正则都是骗人的吗?

  •  
  •   corningsun · Jul 25, 2018 · 7347 views
    This topic created in 2873 days ago, the information mentioned may be changed or developed.

    https://redis.io/commands/keys

    demo 里面给了下面几种用法,难道是只支持这几种吗?

    ()| 这些都不支持吗?

    h?llo matches hello, hallo and hxllo
    h*llo matches hllo and heeeello
    h[ae]llo matches hello and hallo, but not hillo
    h[^e]llo matches hallo, hbllo, ... but not hello
    h[a-b]llo matches hallo and hbllo
    

    假设有如下 10 个 key, 怎么只获取 a1,a2,a10,a11?

    redis> KEYS *
    1) "a1"
    2) "a2"
    3) "a3"
    ...
    10) "a10"
    11) "a11"
    
    12 replies    2018-07-25 15:56:02 +08:00
    leveraging
        1
    leveraging  
       Jul 25, 2018
    a[12][012] ....
    yangtukun1412
        2
    yangtukun1412  
       Jul 25, 2018
    然而这是通配符, 不是正则.
    Lonely
        3
    Lonely  
       Jul 25, 2018 via iPhone
    楼主这种人直接 block。
    agagega
        4
    agagega  
       Jul 25, 2018 via iPhone
    我印象里人家没说这是正则
    rrfeng
        5
    rrfeng  
       Jul 25, 2018 via Android
    rename keys ""
    wwqgtxx
        6
    wwqgtxx  
       Jul 25, 2018 via iPhone
    官方文档哪个地方说了支持正则了…
    CC11001100
        7
    CC11001100  
       Jul 25, 2018
    搜下 redis glob
    ynyounuo
        8
    ynyounuo  
       Jul 25, 2018
    > glob-style patterns

    > In computer programming, glob patterns specify sets of filenames with wildcard characters.
    https://www.wikiwand.com/en/Glob_(programming)
    easylee
        9
    easylee  
       Jul 25, 2018 via Android   ❤️ 8
    @Lonely #3

    看了你的最近 97 条回复,我还是先一步 block 你吧。
    corningsun
        10
    corningsun  
    OP
       Jul 25, 2018
    @yangtukun1412
    @agagega
    @wwqgtxx

    谢谢,理解错了 模式的意思,以为是正则匹配的。
    caola
        11
    caola  
       Jul 25, 2018
    @corningsun 我从没听说过 redis 有正则,但只有一个通配符,
    建议你给加上特定前缀,以后就可以通过前缀+通配符,查询这些数据

    你觉得通配符还不能满足,那么建议使用 eval 来传入 lua 代码,来实现特殊的需求,查询的结果会让你满意的
    xiangyuecn
        12
    xiangyuecn  
       Jul 25, 2018
    听人家建议生产环境慎用 keys

    **Warning**
    https://redis.io/commands/keys


    相对比较少的 key 列表可以存一份到一个 set 里,一次性取出来。。一次性查很多 key 的。。用 scan ?听说的
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   914 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 50ms · UTC 22:37 · PVG 06:37 · LAX 15:37 · JFK 18:37
    ♥ Do have faith in what you're doing.