Example #1
0
func TestQuit(t *testing.T) {
	client, e := redis.NewClient(url)
	if e != nil {
		t.Errorf("Quit: %s", e.Error())
	}
	defer client.Close()

	rsp, err := client.Quit()
	if err != nil {
		t.Errorf("Quit does not work properly. R:%s", err.Error())
	} else if rsp != "OK" {
		t.Errorf("Quit does not work properly. E:%s,R:%s", "OK", rsp)
	}
}
Example #2
0
func main() {
	hostnamePtr := flag.String("h", "127.0.0.1", "Server hostname (default: 127.0.0.1).")
	portPtr := flag.Int("p", 6379, "Server port (default: 6379).")
	flag.Parse()
	network := "tcp"
	address := *hostnamePtr + ":" + strconv.Itoa(*portPtr)
	urlstring := network + "://" + address
	client, err := redis.NewClient(urlstring)
	if err != nil {
		fmt.Println(err)
		return
	}
	defer func() {
		client.Close()
	}()

	reader := bufio.NewReader(os.Stdin)
	for {
		fmt.Printf("%s>", address)

		raw, _ := reader.ReadString('\n')
		raw = strings.Trim(raw, "\r\n ")
		if len(raw) == 0 {
			continue
		}
		if strings.ToLower(raw) == "quit" || strings.ToLower(raw) == "exit" {
			break
		}
		s := strings.Split(raw, " ")
		args := make([]interface{}, len(s[1:]))
		for i := 0; i < len(args); i++ {
			args[i] = s[1+i]
		}
		rsp, e := client.Send(s[0], args...)
		if e == nil {
			print(rsp)
		} else {
			fmt.Printf("%v\n", e.Error())
		}
	}
}
Example #3
0
func setup() error {
	var err error
	client, err = redis.NewClient(url)
	return err
}