func (c Cache) Expire(key string, seconds time.Duration) error {
	r := c.pool.Get()
	defer r.Close()
	if _, err := r.Do("expire", key, seconds); err != nil {
		return err
	}
	return nil
}
Expire sets the time for a key to expire in seconds.
package cache
import (
	"encoding/json"
	"errors"
	"time"
	"github.com/garyburd/redigo/redis"
)
const (
	lockScript = `
		return redis.call('SET', KEYS[1], ARGV[1], 'NX', 'PX', ARGV[2])
	`
	unlockScript = `
		if redis.call("get",KEYS[1]) == ARGV[1] then
		    return redis.call("del",KEYS[1])
		else
		    return 0
		end
	`
)
var (
	ErrCantUnlock = errors.New("failed to unlock")
)
type Cacher interface {
	PutString(key string, value string) (interface{}, error)
	GetString(key string) (string, error)
	PutMarshaled(key string, value interface{}) (interface{}, error)
	GetMarshaled(key string, v interface{}) error
	Delete(key string) error
	Expire(key string, seconds time.Duration) error
	Lock(key, value string, timeoutMs int) (bool, error)
	Unlock(key, value string) error
}
type Cache struct {
	pool *redis.Pool
}
func New(host string) *Cache {
	return &Cache{
		pool: &redis.Pool{
			MaxIdle:   5,
			MaxActive: 100,
			Dial: func() (redis.Conn, error) {
				return redis.Dial("tcp", host)
			},
		},
	}
}
func (c Cache) PutString(key string, value string) (interface{}, error) {
	r := c.pool.Get()
	defer r.Close()
	return r.Do("set", key, value)
}
func (c Cache) GetString(key string) (string, error) {
	r := c.pool.Get()
	defer r.Close()
	return redis.String(r.Do("get", key))
}
func (c Cache) PutMarshaled(key string, value interface{}) (interface{}, error) {
	bytes, err := json.Marshal(value)
	if err != nil {
		return nil, err
	}
	return c.PutString(key, string(bytes[:]))
}
func (c Cache) GetMarshaled(key string, v interface{}) error {
	cached, err := c.GetString(key)
	if err != nil {
		return err
	}
	if len(cached) > 0 {
		if err := json.Unmarshal([]byte(cached), v); err != nil {
			return err
		}
	}
	return nil
}
func (c Cache) Delete(key string) error {
	r := c.pool.Get()
	defer r.Close()
	if _, err := r.Do("del", key); err != nil {
		return err
	}
	return nil
}