//UserUpdate 更新用户 func UserUpdate(_db *db.DB, obj User) error {

jb, _ := json.Marshal(obj)
return _db.Hset("user", db.I2b(obj.ID), jb)

}

//UserGetByID 通过ID获取用户信息 func UserGetByID(_db *db.DB, uid uint64) (User, error) {

obj := User{}
rs := _db.Hget("user", db.I2b(uid))
if rs.State == "ok" {
    json.Unmarshal(rs.Data[0], &obj)
    return obj, nil
}
return obj, errors.New(rs.State)

}

//UserGetByName 通过name获取用户信息 func UserGetByName(_db *db.DB, name string) (User, error) {

obj := User{}
rs := _db.Hget("user_name2uid", []byte(name))
if rs.State == "ok" {
    rs2 := _db.Hget("user", rs.Data[0])
    if rs2.State == "ok" {
        json.Unmarshal(rs2.Data[0], &obj)
        return obj, nil
    }
    return obj, errors.New(rs2.State)
}
return obj, errors.New(rs.State)

}

//UserGetIDByName 通过name获取用户ID func UserGetIDByName(_db *db.DB, name string) string {

rs := _db.Hget("user_name2uid", []byte(name))
if rs.State == "ok" {
    return db.B2ds(rs.Data[0])
}
return ""

}

getkokomi at 2018-11-19 17:45
1
登录 后发表评论