Go Redis

    首先要下載redis開發包,詳情見:https://github.com/alphazero/Go-Redis git

  代碼以下: github

package main 

import (
	"redis"
	"log"
)	

func main() {
	//設置redis服務器地址
	spac := redis.DefaultSpec().Host("202.108.33.173")
	log.Print("spac:", spac)
	
	//建立一個異步的client
	Client, err := redis.NewAsynchClientWithSpec(spac)
	if err != nil {
		log.Fatal(err)
	}
	log.Println("Redis: ", Client)
	
	//get x
	k := "x"
	futureBytes, err := Client.Get(k)
	if err != nil {
		log.Panicln(err)
	}
	v, _ := futureBytes.Get();
	log.Println(k, "=", string(v))
	
		
	//set x
	v1 := "你好"
	futureBool,	e := Client.Set(k, []byte(v1))
	if e != nil {
		log.Print(e);
	}
	//get return value
	boolx , _ := futureBool.Get();
	log.Printf("set %s=>%B", k, boolx);
	
	
}
相關文章
相關標籤/搜索