...
1
2 package redis
3
4 import (
5 "github.com/gomodule/redigo/redis"
6 "github.com/gregjones/httpcache"
7 )
8
9
10
11 type cache struct {
12 redis.Conn
13 }
14
15
16
17 func cacheKey(key string) string {
18 return "rediscache:" + key
19 }
20
21
22 func (c cache) Get(key string) (resp []byte, ok bool) {
23 item, err := redis.Bytes(c.Do("GET", cacheKey(key)))
24 if err != nil {
25 return nil, false
26 }
27 return item, true
28 }
29
30
31 func (c cache) Set(key string, resp []byte) {
32 c.Do("SET", cacheKey(key), resp)
33 }
34
35
36 func (c cache) Delete(key string) {
37 c.Do("DEL", cacheKey(key))
38 }
39
40
41 func NewWithClient(client redis.Conn) httpcache.Cache {
42 return cache{client}
43 }
44
View as plain text