forked from nitishm/go-rejson
/
set_client.go
36 lines (31 loc) · 1.06 KB
/
set_client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package rejson
import (
goredis "github.com/go-redis/redis"
redigo "github.com/gomodule/redigo/redis"
"github.com/nitishm/go-rejson/clients"
"github.com/nitishm/go-rejson/rjs"
)
// RedisClient provides interface for Client handling in the ReJSON Handler
type RedisClient interface {
SetClientInactive()
SetRedigoClient(redigo.Conn)
SetGoRedisClient(conn *goredis.Client)
}
// SetClientInactive resets the handler and unset any client, set to the handler
func (r *Handler) SetClientInactive() {
_t := &Handler{clientName: rjs.ClientInactive}
r.clientName = _t.clientName
r.implementation = _t.implementation
}
// SetRedigoClient sets Redigo (https://github.com/gomodule/redigo/redis) client
// to the handler
func (r *Handler) SetRedigoClient(conn redigo.Conn) {
r.clientName = "redigo"
r.implementation = &clients.Redigo{Conn: conn}
}
// SetGoRedisClient sets Go-Redis (https://github.com/go-redis/redis) client to
// the handler
func (r *Handler) SetGoRedisClient(conn *goredis.Client) {
r.clientName = "goredis"
r.implementation = &clients.GoRedis{Conn: conn}
}