forked from mirror/redcon
Added convenience functions
This commit is contained in:
parent
768b712a98
commit
428ef2271a
19
resp.go
19
resp.go
|
@ -20,7 +20,6 @@ const (
|
||||||
Error = '-'
|
Error = '-'
|
||||||
)
|
)
|
||||||
|
|
||||||
// RESP ...
|
|
||||||
type RESP struct {
|
type RESP struct {
|
||||||
Type Type
|
Type Type
|
||||||
Raw []byte
|
Raw []byte
|
||||||
|
@ -40,6 +39,24 @@ func (r *RESP) ForEach(iter func(resp RESP) bool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *RESP) Bytes() []byte {
|
||||||
|
return r.Data
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *RESP) String() string {
|
||||||
|
return string(r.Data)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *RESP) Int() int64 {
|
||||||
|
x, _ := strconv.ParseInt(r.String(), 10, 64)
|
||||||
|
return x
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *RESP) Float() float64 {
|
||||||
|
x, _ := strconv.ParseFloat(r.String(), 10)
|
||||||
|
return x
|
||||||
|
}
|
||||||
|
|
||||||
// ReadNextRESP returns the next resp in b and returns the number of bytes the
|
// ReadNextRESP returns the next resp in b and returns the number of bytes the
|
||||||
// took up the result.
|
// took up the result.
|
||||||
func ReadNextRESP(b []byte) (n int, resp RESP) {
|
func ReadNextRESP(b []byte) (n int, resp RESP) {
|
||||||
|
|
Loading…
Reference in New Issue