Go Redis

    首先要下载redis开发包,详情见:https://github.com/alphazero/Go-Redis

  代码如下:

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);
	
	
}

你可能感兴趣的:(redis,Go)