美文网首页
go-redis使用

go-redis使用

作者: 哆啦在这A梦在哪 | 来源:发表于2018-11-30 11:43 被阅读6次

一。连接,设值,取值,设置过期时间

con, err := redis.Dial("tcp", "127.0.0.1:6379")
    if err != nil {
        log.Println("use tcp connect redis(127.0.0.1:6379) is default")
        return
    }
    defer con.Close()

    _, err = con.Do("set", "namecode", "shitingbao", "EX", "5")
    if err != nil {
        log.Println("redis set is default", err)
        return
    }

    name, err := redis.String(con.Do("get", "namecode"))
    if err != nil {
        log.Println("get redis values is default:", err)
        return
    }
    log.Println("get name is:", name)
    time.Sleep(6 * time.Second)
    cname, err := redis.String(con.Do("get", "namecode"))
    if err != nil {
        log.Println("get namecode is default:", err)
        return
    }
    log.Println("cname is:", cname)

相关文章

  • go-redis使用

    一。连接,设值,取值,设置过期时间

  • Golang使用Redis

    go使用Redis 文档链接:https://godoc.org/github.com/go-redis/redis

  • golang操作redis

    项目依赖地址go-redis https://github.com/go-redis/redis[https://...

  • go使用redis

    在go中可以使用github.com/go-redis/redis[https://github.com/go-r...

  • 22.Redis

    在项目开发中redis的使用也比较频繁,本文介绍了Go语言中go-redis库的基本使用。《Redis 实战》 R...

  • go-redis库的返回值

    github.com/go-redis/redis 是go语言中封装的最便利使用的redis客户端,但是它的使用会...

  • Go语言操作Redis

    Go语言操作Redis 在项目开发中redis的使用也比较频繁,本文介绍了Go语言中go-redis库的基本使用。...

  • go-redis 发布/订阅

    go-redis 发布/订阅 最近golang 的项目开始使用redis 对于redis 真的是接触少,而且是go...

  • go-redis 源码分析:连接池

    笔者最近在项目中基于 go-redis 实现 Redis 缓存优化性能。go-redis 是一个 Go 语言实现的...

  • go操作redis cluster集群

    github.com/go-redis/redis 非常友好的SDK

网友评论

      本文标题:go-redis使用

      本文链接:https://www.haomeiwen.com/subject/mroccqtx.html