The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
wo642436249

github.com/go-redis/redis 这个库, set 一个 key 时,如何设置过期时间?

  •  
  •   wo642436249 · Aug 12, 2019 · 5993 views
    This topic created in 2497 days ago, the information mentioned may be changed or developed.

    redisCli.Set(ip, nowTime, 6).Err(),想 6 秒后将这个 key 删除,但是这样写有问题,把 6 改为 0 就没事儿了,小白求解

    6 replies    2019-08-12 14:50:02 +08:00
    bot2020
        1
    bot2020  
       Aug 12, 2019
    set(key, value, expiration)
    bot2020
        2
    bot2020  
       Aug 12, 2019
    时间需要 time.Duration(expiration)
    bot2020
        3
    bot2020  
       Aug 12, 2019
    如果是 6 秒:redisCli.Set(ip, nowTime, 6*time.Second)
    myyou
        4
    myyou  
       Aug 12, 2019
    你传入的 6 是指 6 毫秒,6 秒=6 * time.Second
    songjiaxin2008
        5
    songjiaxin2008  
       Aug 12, 2019
    `time.Duration` 了解一下
    wo642436249
        6
    wo642436249  
    OP
       Aug 12, 2019
    @songjiaxin2008
    @myyou
    @iamzzir
    @iamzzir
    @iamzzir
    非常感谢大家的回复,已经清楚,怪我基础太差了,嘿嘿
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2848 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 12:56 · PVG 20:56 · LAX 05:56 · JFK 08:56
    ♥ Do have faith in what you're doing.