I have a struct like that
type User struct {
Nickname *string `json:"nickname"`
Phone *string `json:"phone"`
}
Values are placed in redis with HMSET command. (values can be nil)
Now I'm trying to scan values into a structure:
values, err := redis.Values(Cache.Do("HMGET", "key", "nickname", "phone" )
var usr User
_, err := redis.Scan(values, &usr.Nickname, &usr.Phone)
But I get an error
redigo.Scan: cannot assign to dest 0: cannot convert from Redis bulk string to *string
Please tell me what I'm doing wrong?
The Scan documentation says:
The application passes a pointer to a
*stringto the function. A*stringis not one of the supported types.There are two approaches for fixing the problem. The first is to allocate
stringvalues and pass pointers to the allocatedstringvalues to Scan:The second approach is to change the type of the struct fields to
string: