corningsun
0.05D
V2EX  ›  Redis

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

  •  
  •   corningsun · Jul 25, 2018 · 7749 views
    This topic created in 3026 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
    leveraging
    Jul 25, 2018
    1
    a[12][012] ....
    yangtukun1412
    yangtukun1412
    Jul 25, 2018
    2
    然而这是通配符, 不是正则.
    Lonely
    Lonely
    Jul 25, 2018 via iPhone
    3
    楼主这种人直接 block。
    agagega
    agagega
    Jul 25, 2018 via iPhone
    4
    我印象里人家没说这是正则
    rrfeng
    rrfeng
    Jul 25, 2018 via Android
    5
    rename keys ""
    wwqgtxx
    wwqgtxx
    Jul 25, 2018 via iPhone
    6
    官方文档哪个地方说了支持正则了…
    CC11001100
    CC11001100
    Jul 25, 2018
    7
    搜下 redis glob
    ynyounuo
    ynyounuo
    Jul 25, 2018
    8
    > glob-style patterns

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

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

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

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

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


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