linux go安装redis/mongo扩展

linux go安装redis/mongo扩展

1.安装

安装redis go get github.com/garyburd/redigo/redis
安装mongo go get gopkg.in/mgo.v2
可能的报错:
package gopkg.in/redis.v4: exec: “git”: executable file not found in ‘$PATH’
缺少git , 执行 yum install git
package labix.org/v2/mgo: exec: “bzr”: executable file not found in $PATH
缺少gzr,执行yum install bzr
如果mgo安装不上,可下载源码,安装至 /root/go/src/gopkg.in/mgo.v2

连接

redis

import (
    "fmt"
    "github.com/garyburd/redigo/redis"
)
func main() {
    session, err := redis.Dial("tcp", "localhost:6379")
    if err != nil {
        panic(err)
    }
    session.Do("lpush", "redlist", "test")
}

mongo

import (
    "fmt"
    "github.com/garyburd/redigo/redis"
)
func main() {
    session, err := mgo.Dial("localhost:27017")
    if err != nil {
        panic(err)
    }
    defer session.Close()
}
阅读更多
换一批

没有更多推荐了,返回首页