fix golint issues in core/stores (#527)

This commit is contained in:
Kevin Wan
2021-02-28 23:02:49 +08:00
committed by GitHub
parent 490241d639
commit c566b5ff82
35 changed files with 348 additions and 82 deletions

View File

@@ -12,13 +12,16 @@ var (
)
type (
// Map is an alias of map[string]string.
Map map[string]string
// A ScriptCache is a cache that stores a script with its sha key.
ScriptCache struct {
atomic.Value
}
)
// GetScriptCache returns a ScriptCache.
func GetScriptCache() *ScriptCache {
once.Do(func() {
instance = &ScriptCache{}
@@ -28,12 +31,14 @@ func GetScriptCache() *ScriptCache {
return instance
}
// GetSha returns the sha string of given script.
func (sc *ScriptCache) GetSha(script string) (string, bool) {
cache := sc.Load().(Map)
ret, ok := cache[script]
return ret, ok
}
// SetSha sets script with sha into the ScriptCache.
func (sc *ScriptCache) SetSha(script, sha string) {
lock.Lock()
defer lock.Unlock()