Exemple #1
0
func (c *RedisCache) Get(key string) (string, error) {
	conn := c.getConn()
	defer conn.Close()

	val, err := redis.String(conn.Do("GET", key))
	if err != nil {
		return "", fmt.Errorf("can't get redis key %q: %s", key, err)
	}

	return val, nil
}
Exemple #2
0
func (c *RedisCache) Set(key string, data string, expiration time.Duration) (string, error) {
	conn := c.getConn()
	defer conn.Close()

	val, err := redis.String(conn.Do("SET", key, data, "EX", int(expiration.Seconds())))
	if err != nil {
		return "", fmt.Errorf("can't set redis key %q: %s", key, err)
	}

	return val, nil

}
Exemple #3
0
func ExampleString() {
	c, err := dial()
	if err != nil {
		panic(err)
	}
	defer c.Close()

	c.Do("SET", "hello", "world")
	s, err := redis.String(c.Do("GET", "hello"))
	fmt.Printf("%#v\n", s)
	// Output:
	// "world"
}