build-redis-from-scratch icon indicating copy to clipboard operation
build-redis-from-scratch copied to clipboard

May there is a concurrent problem in hgetall function?

Open yly97 opened this issue 1 year ago • 0 comments

Code

here

HSETsMu.RLock()
value, ok := HSETs[hash]
HSETsMu.RUnlock()

if !ok {
return Value{typ: "null"}
}

values := []Value{}
for k, v := range value {
values = append(values, Value{typ: "bulk", bulk: k})
values = append(values, Value{typ: "bulk", bulk: v})
}

Description

I think the value can't be handle out the locker, the write goroutine will affect the read operation. It doesn't a deep copy

yly97 avatar Feb 03 '24 14:02 yly97