在go中往redis的hash写数据的时候遇到了结构体数组写入时无法写入,看了看写入数据要求是map[string]interface,而我的是struct。因此,无法写入的。
那么就是转格式呗
type order struct{
Id int64 `json:"id"`
orderSn int64 `json:"order_sn"`
}
orders:=order{
Id:2022032034566
OrderSn:20220320122444
}
jsonData,_:=json.Marshal(orders)
var redisData map[string]interface{}
json.Unmarshal([]byte(jsonData),&redisData)
log.Info(redisData)
以上就是转化过程。

