all repos — navani @ 908ef018724da58d7fead02856d4ba5fe4404f69

forlater's primary mail processing service

cache/redis.go (view raw)

 1package cache
 2
 3import (
 4	"github.com/gomodule/redigo/redis"
 5)
 6
 7type conn struct {
 8	redis.Conn
 9}
10
11// Returns a new redis connection.
12func NewConn() (conn, error) {
13	c, err := redis.Dial("tcp", ":6379")
14	if err != nil {
15		c.Close()
16		return conn{}, err
17	}
18	return conn{c}, nil
19}
20
21// SET command.
22func (c *conn) Set(args ...interface{}) (interface{}, error) {
23	cmd := "SET"
24	reply, err := c.Do(cmd, args...)
25	if err != nil {
26		return nil, err
27	}
28	return reply, nil
29}
30
31// GET command. We stringify the response.
32func (c *conn) Get(args ...interface{}) (string, error) {
33	cmd := "GET"
34	reply, err := redis.String(c.Do(cmd, args...))
35	if err != nil {
36		return "", err
37	}
38	return reply, nil
39}