1 回答
TA贡献1828条经验 获得超4个赞
由于您要来回整理代码,我建议使用 @ Not_a_Golfer的解决方案。
以下是您可以执行的操作的示例:
package main
import (
"encoding/json"
"fmt"
)
type Emotions struct {
Sad bool
Happy Happy
Confused int
}
type Happy struct {
Money int
Moral bool
Health bool
}
func main() {
emo := &Emotions{Sad: true}
// retain readability with json
serialized, err := json.Marshal(emo)
if err == nil {
fmt.Println("serialized data: ", string(serialized))
//serialized data: {"Sad":true,"Happy":{"Money":0,"Moral":false,"Health":false},"Confused":0}
//do redis transactions...
}
//retriving whatever value stored in your redis instance...
var deserialized Emotions
err = json.Unmarshal(serialized, &deserialized)
if err == nil {
fmt.Println("deserialized data: ", deserialized.Sad)
//deserialized data: true
}
}
现在关于如何在 redis 上存储内容,这在很大程度上取决于您的数据。
- 1 回答
- 0 关注
- 138 浏览
添加回答
举报