[Go小技巧] 实现常用的KV缓存(有序且并发安全)
type KV struct { count int keys []string hash map[string]interface{} lock sync.RWMutex } // 添加kv键值对 func (this *KV) Set(k string, v interface{}) { this.lock.Lock() if _, ok := this.hash[k]; !ok { this.keys = append(this.keys, k) sort.Strings(this.keys) this.count++ } this.hash[k] = v this.lock.Unlock() } // 获取数据长度 func (this *KV) Count() int { this...阅读全文