1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-31 05:04:23 +03:00

Fix/issue 1384 (#1529)

Add support for scanning time.TIme
This commit is contained in:
Roman Suvorov
2020-10-13 09:13:43 +03:00
committed by GitHub
parent 36223c9349
commit f169894120
2 changed files with 41 additions and 3 deletions

View File

@ -4,10 +4,13 @@ import (
"encoding"
"fmt"
"reflect"
"time"
"github.com/go-redis/redis/v8/internal/util"
)
// Scan parses bytes `b` to `v` with appropriate type.
// nolint: gocyclo
func Scan(b []byte, v interface{}) error {
switch v := v.(type) {
case nil:
@ -99,6 +102,10 @@ func Scan(b []byte, v interface{}) error {
case *bool:
*v = len(b) == 1 && b[0] == '1'
return nil
case *time.Time:
var err error
*v, err = time.Parse(time.RFC3339Nano, util.BytesToString(b))
return err
case encoding.BinaryUnmarshaler:
return v.UnmarshalBinary(b)
default: