func ExampleSet() {
	cacher.Flush()
	ok1 := cacher.Set("key1", []byte("value1"), 0)
	val1, _, _ := cacher.Get("key1")
	fmt.Println(string(val1), ok1)

	ok2 := cacher.Set("key1", []byte("value2"), 0)
	val2, _, _ := cacher.Get("key1")
	fmt.Println(string(val2), ok2)

	// Output:
	// value1 <nil>
	// value2 <nil>
}
func ExampleAdd() {
	cacher.Flush()
	ok1 := cacher.Add("key1", []byte("value1"), 0)
	val1, _, _ := cacher.Get("key1")
	fmt.Println(string(val1), ok1)

	ok2 := cacher.Add("key1", []byte("value2"), 0)
	val2, _, _ := cacher.Get("key1")
	fmt.Println(string(val2), ok2)

	// Output:
	// value1 <nil>
	// value1 Key `key1` already exists.
}
func ExampleGet() {
	cacher.Flush()
	var value []byte
	var token string
	var err error

	value, token, err = cacher.Get("non-existing")
	fmt.Println(string(value), token, err)

	cacher.Set("key1", []byte("Hello world!"), 0)
	value, token, err = cacher.Get("key1")
	fmt.Println(string(value), token, err)

	// Output:
	// Key `non-existing` does not exist.
	// Hello world! 86fb269d190d2c85f6e0468ceca42a20 <nil>
}
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
}
func ExampleDecrement() {
	cacher.Flush()
	cacher.Decrement("key1", 10, 1, 0)
	cacher.Decrement("key1", 10, 3, 0)
	v, _, _ := cacher.Get("key1")

	num, _ := encoding.BytesInt64(v)
	fmt.Println(num)

	cacher.Set("key2", []byte("string value, not decrementable"), 0)
	ok := cacher.Decrement("key2", 0, 5, 0)
	v2, _, _ := cacher.Get("key2")
	fmt.Println(ok, string(v2))

	// Output:
	// 7
	// Value for key `key2` could not be encoded. string value, not decrementable
}
func ExampleCompareAndReplace() {
	cacher.Flush()
	cacher.Set("key1", []byte("hello world"), 0)
	_, token, _ := cacher.Get("key1")

	var err error
	var val []byte
	err = cacher.CompareAndReplace(token+"FALSE", "key1", []byte("replacement1"), 0)
	val, _, _ = cacher.Get("key1")
	fmt.Println(err, string(val))

	err = cacher.CompareAndReplace(token, "key1", []byte("replacement2"), 0)
	val, _, _ = cacher.Get("key1")
	fmt.Println(err, string(val))

	// Output:
	// Key `key1` does not exist. hello world
	// <nil> replacement2
}