修复redis hash设置不成功问题
This commit is contained in:
parent
8a697e8bfc
commit
063856395c
|
|
@ -61,8 +61,15 @@ func SetRedis(key string, value string) {
|
|||
// 设置hash
|
||||
func SetHash(key string, id int, name, email string) {
|
||||
ctx := context.Background() // 创建一个上下文
|
||||
fields := map[string]interface{}{
|
||||
"id": strconv.Itoa(id),
|
||||
"name": name,
|
||||
"email": email,
|
||||
}
|
||||
|
||||
// 设置哈希表的字段值, 0 表示不设置过期时间, 如果需要设置过期时间, 可以设置为 time.Second * 10 等
|
||||
err := redisClient.HSet(ctx, key, "id", id, "name", name, "email", email, time.Hour*12).Err()
|
||||
err := redisClient.HSet(ctx, key, fields).Err()
|
||||
err = redisClient.Expire(ctx, key, time.Hour*10).Err()
|
||||
if err != nil {
|
||||
log.Fatalf("Error setting key: %v", err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue