Пример #1
0
func TestMain(t *testing.T) {

	server, err := redistest.NewServer(true, nil)
	if err != nil {
		t.Error(err)
	}
	defer server.Stop()

	host := server.Config["unixsocket"]

	opt := redis.Options{}
	opt.Addr = host
	opt.Network = "unix"

	client := redis.NewClient(&opt)
	defer client.Close()

	if strCmd := client.Set("foo2", "bar"); strCmd.Err() != nil {
		t.Errorf(strCmd.Err())
	}

	if strCmd := client.Get("foo2"); strCmd.Err() != nil {
		t.Errorf(strCmd.Err())
	} else {
		fmt.Println(strCmd.String())
	}
}
Пример #2
0
func example1() {

	var host string
	flag.StringVar(&host, "host", "localhost", "host name")
	flag.Parse()

	opt := redis.Options{}
	opt.Addr = strings.Join([]string{host, "6379"}, ":")
	opt.Network = "tcp"

	client := redis.NewClient(&opt)
	defer client.Close()

	client.Set("foo", "bar")

	strCmd := client.Get("foo")
	fmt.Println(strCmd.String())
}