Skip to content

Latest commit

 

History

History
56 lines (40 loc) · 1.04 KB

File metadata and controls

56 lines (40 loc) · 1.04 KB

设置过期时间

[[toc]]

[toc]

package main

import (
    "fmt"
    "github.com/garyburd/redigo/redis"
)

func main() {
    c, err := redis.Dial("tcp", "localhost:6379")
    if err != nil {
        fmt.Println("conn redis failed,", err)
        return
    }

    defer c.Close()
    _, err = c.Do("expire", "abc", 10)
    if err != nil {
        fmt.Println(err)
        return
    }
}

命令行运行:

    go run main.go

Redis命令行窗口:

    127.0.0.1:6379> get abc
    "100"

    # 10秒后过期
    127.0.0.1:6379> get abc
    (nil)

END 链接