예제 #1
0
func ExampleSetMulti() {
	cacher.Flush()
	multi := map[string][]byte{
		"key1": []byte("value1"),
		"key2": []byte("value2"),
	}

	cacher.SetMulti(multi, 0)
	val1, _, _ := cacher.Get("key1")
	val2, _, _ := cacher.Get("key2")

	fmt.Println(string(val1))
	fmt.Println(string(val2))

	// Output:
	// value1
	// value2
}
예제 #2
0
func ExampleDeleteMulti() {
	cacher.Flush()
	keys := []string{"key1", "key2", "non-existing"}

	multi := map[string][]byte{
		"key1": []byte("value1"),
		"key2": []byte("value2"),
	}
	cacher.SetMulti(multi, 0)

	oks := cacher.DeleteMulti(keys)
	fmt.Println(oks["key1"])
	fmt.Println(oks["key2"])
	fmt.Println(oks["non-existing"])

	// Output:
	// <nil>
	// <nil>
	// Key `non-existing` was not found.
}
예제 #3
0
func ExampleGetMulti() {
	cacher.Flush()
	multi := map[string][]byte{
		"key1": []byte("value1"),
		"key2": []byte("value2"),
	}

	cacher.SetMulti(multi, 0)

	keys := []string{"key1", "key2"}

	values, tokens, bools := cacher.GetMulti(keys)
	fmt.Println(values["key1"], values["key2"])
	fmt.Println(tokens["key1"], tokens["key2"])
	fmt.Println(bools["key1"], bools["key2"])

	// Output:
	// [118 97 108 117 101 49] [118 97 108 117 101 50]
	// 9946687e5fa0dab5993ededddb398d2e f066ce9385512ee02afc6e14d627e9f2
	// <nil> <nil>
}
예제 #4
0
func ExampleFlush() {
	cacher.Flush()
	var errs map[string]error

	keys := []string{"key1", "key2"}
	multi := map[string][]byte{
		"key1": []byte("value1"),
		"key2": []byte("value2"),
	}
	cacher.SetMulti(multi, 0)

	_, _, errs = cacher.GetMulti(keys)
	fmt.Println(errs["key1"], errs["key2"])

	cacher.Flush()
	_, _, errs = cacher.GetMulti(keys)
	fmt.Println(errs["key1"], errs["key2"])

	// Output:
	// <nil> <nil>
	// Key `key1` does not exist. Key `key2` does not exist.
}