golang怎么使用redis,最基础的有效的方法

最近在学GO语言,我自己也喜欢使用redis,于是乎就顺便把go操作redis的方法也给学了,有个第三方包,在GitHub上面找的 

go get github.com/alphazero/Go-Redis   //win 在cmd上敲    mac 在命令行上敲

  

 1 package main
 2 
 3 import (
 4 "fmt"
 5 "github.com/alphazero/Go-Redis"
 6 )
 7 func main() {
 8 
 9     spec        := redis.DefaultSpec().Host("115.28.93.180").Db(0).Password("haonan123");
10   client, err := redis.NewSynchClientWithSpec (spec);
11   
12   if err != nil {
13       fmt.Println("Connect redis server fail");
14       return
15   }
16   dbkey := "test";
17     value :=[]byte("Hello world!");
18     client.Set(dbkey, value);
19     
20     getValue ,err:= client.Get(dbkey);
21     if err != nil {
22         fmt.Println("Get Key fail");
23         return
24     } else {
25         str := string(getValue);
26         fmt.Println(str);
27     }
28 }
原文地址:https://www.cnblogs.com/huanhang/p/6707315.html