我有类似的结构
type myStruct struct {
TotalCount int `json:"inventory_total_count"`
TotalPrice int `json:"inventory_total_price"`
GameList []string `json:"game_list"`
UserInfo UserInformation `json:"user_info"`
GameInventory map[string]InventoryGame `json:"inventory"`
}
type InventoryGame struct {
GameAssetsTotalCount int `json:"game_assets_total_count"`
GameAssetsTotalPrice int `json:"game_assets_total_price"`
GameID string `json:"gameid"`
Assets []InventoryAssets `json:"assets"`
}
type InventoryAssets struct {
ClassID string `json:"classid"`
InstanceID string `json:"instanceid"`
IconURL string `json:"icon_url"`
Name string `json:"name"`
MarketHashName string `json:"market_hash_name"`
AssetRarity string `json:"rarity"`
AssetBorderColor string `json:"border_color"`
AssetExterior string `json:"exterior"`
AssetQuality string `json:"asset_quality"`
AppID int `json:"appid"`
AssetPrice int `json:"asset_price"`
Marketable int `json:"marketable"`
AssetCount int `json:"item_count"`
AssetTotalCost int `json:"asset_total_price"`
}
创建后,我将其写入Redis存储,如下所示
err := client.Set(ctx, "key", myStruct, time.Minute)
// отработка err
然后我尝试得到这个结构如下
newStruct := myStruct{}
err := client.Get(ctx, "key").Scan(&newStruct)
// отработка err
结果,输出是一个空结构
{0 0 [] { } map[]}
附:注册了结构方法“MarshalBinary”和“UnmarshalBinary”。
我正在使用 go-redis/v9。
如何正确从 Redis 存储中检索结构?