/
reply.go
120 lines (96 loc) · 2.71 KB
/
reply.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package redis
import (
"encoding/json"
"github.com/gomodule/redigo/redis"
)
// refer redis.Int.
func Int(reply interface{}, err error) (int, error) {
rep, err := redis.Int(reply, err)
return rep, decorError(err)
}
// refer redis.Int64.
func Int64(reply interface{}, err error) (int64, error) {
rep, err := redis.Int64(reply, err)
return rep, decorError(err)
}
// refer redis.Uint64.
func Uint64(reply interface{}, err error) (uint64, error) {
rep, err := redis.Uint64(reply, err)
return rep, decorError(err)
}
// refer redis.Float64.
func Float64(reply interface{}, err error) (float64, error) {
rep, err := redis.Float64(reply, err)
return rep, decorError(err)
}
// refer redis.String.
func String(reply interface{}, err error) (string, error) {
rep, err := redis.String(reply, err)
return rep, decorError(err)
}
// refer redis.Bytes.
func Bytes(reply interface{}, err error) ([]byte, error) {
rep, err := redis.Bytes(reply, err)
return rep, decorError(err)
}
// refer redis.Bool.
func Bool(reply interface{}, err error) (bool, error) {
rep, err := redis.Bool(reply, err)
return rep, decorError(err)
}
// refer redis.Values.
func Values(reply interface{}, err error) ([]interface{}, error) {
rep, err := redis.Values(reply, err)
return rep, decorError(err)
}
// refer redis.Float64s.
func Float64s(reply interface{}, err error) ([]float64, error) {
return redis.Float64s(reply, err)
}
// refer redis.Strings.
func Strings(reply interface{}, err error) ([]string, error) {
return redis.Strings(reply, err)
}
// refer redis.ByteSlices.
func ByteSlices(reply interface{}, err error) ([][]byte, error) {
return redis.ByteSlices(reply, err)
}
// refer redis.Int64s.
func Int64s(reply interface{}, err error) ([]int64, error) {
return redis.Int64s(reply, err)
}
// refer redis.Ints.
func Ints(reply interface{}, err error) ([]int, error) {
return redis.Ints(reply, err)
}
// refer redis.StringMap.
func StringMap(result interface{}, err error) (map[string]string, error) {
return redis.StringMap(result, err)
}
// refer redis.IntMap.
func IntMap(result interface{}, err error) (map[string]int, error) {
return redis.IntMap(result, err)
}
// refer redis.IntMap.
func Int64Map(result interface{}, err error) (map[string]int64, error) {
return redis.Int64Map(result, err)
}
// refer redis.Positions.
func Positions(result interface{}, err error) ([]*[2]float64, error) {
return redis.Positions(result, err)
}
func Struct(result interface{}, err error, v ...interface{}) error {
bytes, err := redis.Bytes(result, err)
if err != nil {
return err
}
err = json.Unmarshal(bytes, &v)
return err
}
// decorError implement decoration redis.ErrNil.
func decorError(err error) error {
if err == redis.ErrNil {
err = nil
}
return err
}