-
Notifications
You must be signed in to change notification settings - Fork 0
/
adapter.go
66 lines (53 loc) · 1.55 KB
/
adapter.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package redis
import (
"context"
"github.com/gomodule/redigo/redis"
"time"
)
type RedisAdapter struct {
Pool *redis.Pool
}
func NewRedisAdapterByConfig(c Config) (*RedisAdapter, error) {
pool, err := NewRedisPoolByConfig(c)
if err != nil {
return nil, err
}
return &RedisAdapter{pool}, nil
}
func NewRedisAdapter(redisUrl string) (*RedisAdapter, error) {
pool, err := NewRedisPool(redisUrl)
if err != nil {
return nil, err
}
return &RedisAdapter{pool}, nil
}
func (c *RedisAdapter) Put(ctx context.Context, key string, obj interface{}, timeToLive time.Duration) error {
return Set(c.Pool, key, obj, timeToLive)
}
func (c *RedisAdapter) Expire(ctx context.Context, key string, timeToLive time.Duration) (bool, error) {
return Expire(c.Pool, key, timeToLive)
}
func (c *RedisAdapter) Get(ctx context.Context, key string) (string, error) {
return Get(c.Pool, key)
}
func (c *RedisAdapter) ContainsKey(ctx context.Context, key string) (bool, error) {
return Exists(c.Pool, key)
}
func (c *RedisAdapter) Remove(ctx context.Context, key string) (bool, error) {
return Delete(c.Pool, key)
}
func (c *RedisAdapter) Clear(ctx context.Context) error {
return Clear(c.Pool)
}
func (c *RedisAdapter) GetMany(keys []string) (map[string]string, []string, error) {
return GetMany(c.Pool, keys)
}
func (c *RedisAdapter) Keys(ctx context.Context) ([]string, error) {
return Keys(c.Pool)
}
func (c *RedisAdapter) Count(ctx context.Context) (int64, error) {
return Count(c.Pool)
}
func (c *RedisAdapter) Size(ctx context.Context) (int64, error) {
return Size(c.Pool)
}