Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
42 lines (32 sloc) 725 Bytes
package redis
import (
"time"
r "gopkg.in/redis.v5"
)
var preffix = "_PAGE_CACHE_"
//Storage mecanism for caching strings in memory
type Storage struct {
client *r.Client
}
//NewStorage creates a new redis storage
func NewStorage(url string) (*Storage, error) {
var (
opts *r.Options
err error
)
if opts, err = r.ParseURL(url); err != nil {
return nil, err
}
return &Storage{
client: r.NewClient(opts),
}, nil
}
//Get a cached content by key
func (s Storage) Get(key string) []byte {
val, _ := s.client.Get(preffix + key).Bytes()
return val
}
//Set a cached content by key
func (s Storage) Set(key string, content []byte, duration time.Duration) {
s.client.Set(preffix+key, content, duration)
}