2020-09-05 13:17:26 +03:00
|
|
|
package internal
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
"time"
|
2022-08-01 19:05:40 +03:00
|
|
|
|
|
|
|
"github.com/go-redis/redis/v9/internal/util"
|
2020-09-05 13:17:26 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func AppendArg(b []byte, v interface{}) []byte {
|
|
|
|
switch v := v.(type) {
|
|
|
|
case nil:
|
|
|
|
return append(b, "<nil>"...)
|
|
|
|
case string:
|
2022-08-01 19:05:40 +03:00
|
|
|
return appendUTF8String(b, util.StringToBytes(v))
|
2020-09-05 13:17:26 +03:00
|
|
|
case []byte:
|
|
|
|
return appendUTF8String(b, v)
|
|
|
|
case int:
|
|
|
|
return strconv.AppendInt(b, int64(v), 10)
|
|
|
|
case int8:
|
|
|
|
return strconv.AppendInt(b, int64(v), 10)
|
|
|
|
case int16:
|
|
|
|
return strconv.AppendInt(b, int64(v), 10)
|
|
|
|
case int32:
|
|
|
|
return strconv.AppendInt(b, int64(v), 10)
|
|
|
|
case int64:
|
|
|
|
return strconv.AppendInt(b, v, 10)
|
|
|
|
case uint:
|
|
|
|
return strconv.AppendUint(b, uint64(v), 10)
|
|
|
|
case uint8:
|
|
|
|
return strconv.AppendUint(b, uint64(v), 10)
|
|
|
|
case uint16:
|
|
|
|
return strconv.AppendUint(b, uint64(v), 10)
|
|
|
|
case uint32:
|
|
|
|
return strconv.AppendUint(b, uint64(v), 10)
|
|
|
|
case uint64:
|
|
|
|
return strconv.AppendUint(b, v, 10)
|
|
|
|
case float32:
|
|
|
|
return strconv.AppendFloat(b, float64(v), 'f', -1, 64)
|
|
|
|
case float64:
|
|
|
|
return strconv.AppendFloat(b, v, 'f', -1, 64)
|
|
|
|
case bool:
|
|
|
|
if v {
|
|
|
|
return append(b, "true"...)
|
|
|
|
}
|
|
|
|
return append(b, "false"...)
|
|
|
|
case time.Time:
|
|
|
|
return v.AppendFormat(b, time.RFC3339Nano)
|
|
|
|
default:
|
|
|
|
return append(b, fmt.Sprint(v)...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func appendUTF8String(dst []byte, src []byte) []byte {
|
2020-09-24 10:09:09 +03:00
|
|
|
dst = append(dst, src...)
|
2020-09-05 13:17:26 +03:00
|
|
|
return dst
|
|
|
|
}
|