fix: []byte nil resp

This commit is contained in:
weedge 2023-06-13 13:07:49 +08:00
parent 9f71787fcd
commit 77c37f99e0
1 changed files with 18 additions and 13 deletions

31
resp.go
View File

@ -556,18 +556,19 @@ type Marshaler interface {
} }
// AppendAny appends any type to valid Redis type. // AppendAny appends any type to valid Redis type.
// nil -> null //
// error -> error (adds "ERR " when first word is not uppercase) // nil -> null
// string -> bulk-string // error -> error (adds "ERR " when first word is not uppercase)
// numbers -> bulk-string // string -> bulk-string
// []byte -> bulk-string // numbers -> bulk-string
// bool -> bulk-string ("0" or "1") // []byte -> bulk-string
// slice -> array // bool -> bulk-string ("0" or "1")
// map -> array with key/value pairs // slice -> array
// SimpleString -> string // map -> array with key/value pairs
// SimpleInt -> integer // SimpleString -> string
// Marshaler -> raw bytes // SimpleInt -> integer
// everything-else -> bulk-string representation using fmt.Sprint() // Marshaler -> raw bytes
// everything-else -> bulk-string representation using fmt.Sprint()
func AppendAny(b []byte, v interface{}) []byte { func AppendAny(b []byte, v interface{}) []byte {
switch v := v.(type) { switch v := v.(type) {
case SimpleString: case SimpleString:
@ -583,7 +584,11 @@ func AppendAny(b []byte, v interface{}) []byte {
case string: case string:
b = AppendBulkString(b, v) b = AppendBulkString(b, v)
case []byte: case []byte:
b = AppendBulk(b, v) if v == nil {
b = AppendNull(b)
} else {
b = AppendBulk(b, v)
}
case bool: case bool:
if v { if v {
b = AppendBulkString(b, "1") b = AppendBulkString(b, "1")