安装完毕后解压目录如下
点击redis-server.exe启动redis
然后在启动cmd客户端
package mainimport ( "fmt" "github.com/garyburd/redigo/redis")func main() { var p *int var a int p = &a *p = 0 c,err := redis.Dial("tcp","localhost:6379") if err != nil { fmt.Println("conn redis Failed,",err) return } defer c.Close() _,err = c.Do("Set","abc", 100) if err != nil { fmt.Println(err) return }//redis-cli.exe -h 127.0.0.1 -p 6379 r,err := redis.Int(c.Do("Get","abc")) if err != nil { fmt.Println("get abc Failed,err) return } fmt.Println(r)}
输出如下:
PS E:\golang\go_pro\src\rediss> go run main.go100hash类型
package mainimport ( "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("HSet","books",1000) if err != nil { fmt.Println(err) return } r,err := redis.Int(c.Do("HGet","abc")) if err != nil { fmt.Println("get abc Failed,err) return } fmt.Println(r)}
输出如下:
PS E:\golang\go_pro\src\rediss> go run main.go1000批量set类型
package mainimport ( "fmt" "github.com/garyburd/redigo/redis")func main() { c,err = c.Do("MSet",100,"efg",300) if err != nil { fmt.Println(err) return } r,err := redis.Ints(c.Do("MGet","efg")) if err != nil { fmt.Println("get abc Failed,err) return } for _,v := range r { fmt.Println(v) }}
输出如下:
PS E:\golang\go_pro\src\rediss> go run main.go100300队列 *** 作
package mainimport ( "fmt" "github.com/garyburd/redigo/redis")func main() { c,err = c.Do("lpush","book_List","ceg",30) if err != nil { fmt.Println(err) return } r,err := redis.String(c.Do("lpop","book_List")) if err != nil { fmt.Println("get abc Failed,err) return } fmt.Println(r)}
输出如下:
PS E:\golang\go_pro\src\rediss> go run main.go30redis.Pool
package mainimport ( "fmt" "github.com/garyburd/redigo/redis")var pool *redis.Poolfunc init() { pool = &redis.Pool{ MaxIDle: 16,MaxActive: 0,IDleTimeout: 300,Dial: func() (redis.Conn,error) { return redis.Dial("tcp","localhost:6379") },}}func main() { c := pool.Get() defer c.Close() _,err := c.Do("Set", 100) if err != nil { fmt.Println(err) return } r,err) return } fmt.Println(r) pool.Close()}
输出如下:
PS E:\golang\go_pro\src\rediss> go run main.go100总结
以上是内存溢出为你收集整理的golang基础-redis使用全部内容,希望文章能够帮你解决golang基础-redis使用所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)