Skip to content

Commit

Permalink
修改了ConcurrentDict的Get方法
Browse files Browse the repository at this point in the history
  • Loading branch information
wangxiao1024 committed Jul 23, 2024
1 parent c1dd65d commit e20e783
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions datastruct/dict/concurrent.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package dict

import (
"github.com/hdt3213/godis/lib/wildcard"
"math"
"math/rand"
"sort"
"sync"
"sync/atomic"
"time"

"github.com/hdt3213/godis/lib/wildcard"
)

// ConcurrentDict is thread safe map using sharding lock
Expand Down Expand Up @@ -89,8 +90,8 @@ func (dict *ConcurrentDict) Get(key string) (val interface{}, exists bool) {
hashCode := fnv32(key)
index := dict.spread(hashCode)
s := dict.getShard(index)
s.mutex.Lock()
defer s.mutex.Unlock()
s.mutex.RLock()
defer s.mutex.RUnlock()
val, exists = s.m[key]
return
}
Expand Down

0 comments on commit e20e783

Please sign in to comment.