-
Notifications
You must be signed in to change notification settings - Fork 0
0726DAO的含义
ziyouzy edited this page Jul 26, 2020
·
1 revision
type UserDao struct {
pool *redis.Pool
}
func (this *UserDao) getUserById(conn redis.Conn, id int) (user *User, err error) {
//通过给定id 去 redis查询这个用户
res, err := redis.String(conn.Do("HGet", "users", id))
if err != nil {
//错误!
if err == redis.ErrNil { //表示在 users 哈希中,没有找到对应id
err = ERROR_USER_NOTEXISTS
}
return
}
user = &User{}
//这里我们需要把res 反序列化成User实例
err = json.Unmarshal([]byte(res), user)
if err != nil {
fmt.Println("json.Unmarshal err=", err)
return
}
return
}