专家您好,我正在使用此库将 K/V 存储在缓存中
"github.com/bluele/gcache"
我存储的值就是这个数据结构
type LatestBlockhashCacheResult struct {
Blockhash string `json:"blockhash"`
LastValidBlockHeight uint64 `json:"lastValidBlockHeight"` // Slot.
CommitmentType string `json:"commitmentType"`
}
lbhr := LatestBlockhashCacheResult{
Blockhash: lbh.Value.Blockhash.String(),
LastValidBlockHeight: lbh.Value.LastValidBlockHeight,
CommitmentType: string(commitmentType),
}
gc.SetWithExpire(lbh.Value.LastValidBlockHeight, lbhr, time.Hour*10)
我对检索缓存没有问题,但无法对其进行类型转换
c, _ := gc.Get(rf.LastValidBlockHeight)
fmt.Printf("%T\n", c)
所以当我尝试这个
var c = LatestBlockhashCacheResult{}
c, _ = gc.Get(rf.LastValidBlockHeight)
这引发了我的错误
cannot assign interface {} to c (type LatestBlockhashCacheResult) in multiple assignment: need type assertion
MYYA
相关分类