...

Source file src/github.com/redis/go-redis/v9/internal/arg.go

Documentation: github.com/redis/go-redis/v9/internal

     1  package internal
     2  
     3  import (
     4  	"fmt"
     5  	"strconv"
     6  	"time"
     7  
     8  	"github.com/redis/go-redis/v9/internal/util"
     9  )
    10  
    11  func AppendArg(b []byte, v interface{}) []byte {
    12  	switch v := v.(type) {
    13  	case nil:
    14  		return append(b, "<nil>"...)
    15  	case string:
    16  		return appendUTF8String(b, util.StringToBytes(v))
    17  	case []byte:
    18  		return appendUTF8String(b, v)
    19  	case int:
    20  		return strconv.AppendInt(b, int64(v), 10)
    21  	case int8:
    22  		return strconv.AppendInt(b, int64(v), 10)
    23  	case int16:
    24  		return strconv.AppendInt(b, int64(v), 10)
    25  	case int32:
    26  		return strconv.AppendInt(b, int64(v), 10)
    27  	case int64:
    28  		return strconv.AppendInt(b, v, 10)
    29  	case uint:
    30  		return strconv.AppendUint(b, uint64(v), 10)
    31  	case uint8:
    32  		return strconv.AppendUint(b, uint64(v), 10)
    33  	case uint16:
    34  		return strconv.AppendUint(b, uint64(v), 10)
    35  	case uint32:
    36  		return strconv.AppendUint(b, uint64(v), 10)
    37  	case uint64:
    38  		return strconv.AppendUint(b, v, 10)
    39  	case float32:
    40  		return strconv.AppendFloat(b, float64(v), 'f', -1, 64)
    41  	case float64:
    42  		return strconv.AppendFloat(b, v, 'f', -1, 64)
    43  	case bool:
    44  		if v {
    45  			return append(b, "true"...)
    46  		}
    47  		return append(b, "false"...)
    48  	case time.Time:
    49  		return v.AppendFormat(b, time.RFC3339Nano)
    50  	default:
    51  		return append(b, fmt.Sprint(v)...)
    52  	}
    53  }
    54  
    55  func appendUTF8String(dst []byte, src []byte) []byte {
    56  	dst = append(dst, src...)
    57  	return dst
    58  }
    59  

View as plain text