Open dagenius007 opened 9 months ago
I don't find error ?
package main
import (
"context"
"fmt"
"github.com/redis/go-redis/v9"
)
type UserTempSignup struct {
Email string `redis:"email" json:"email"`
Code string `redis:"code" json:"code"`
Password string `redis:"password" json:"password"`
}
func main() {
ctx := context.Background()
rdb := redis.NewClient(&redis.Options{
Addr: ":6379",
})
_ = rdb.FlushDB(ctx).Err()
uid := "uid:1"
u1 := UserTempSignup{
Email: "haha@gmail.com",
Code: "s1002",
Password: "hello",
}
err := rdb.HSet(ctx, uid, u1).Err()
fmt.Println("hset", err)
temp := new(UserTempSignup)
cmd := rdb.HGetAll(ctx, uid)
fmt.Println("hgetall", cmd.Err())
cmd.Scan(temp)
fmt.Printf("dump object => %+v\n", temp)
fmt.Printf("dump mapper => %+v", cmd.Val())
}
hset <nil>
hgetall <nil>
dump object => &{Email:haha@gmail.com Code:s1002 Password:hello}
dump mapper => map[code:s1002 email:haha@gmail.com password:hello]
I am trying to get map value from a dynamic key but it keeps returning empty value
Detailed Description
temp_brand is empty but it returns a value if I pass a static key e.g "key"