forked from p53841790/wheat-cache
fix(structure-stringx): fix GetSet set init nil key
This commit is contained in:
parent
c0da22ef6f
commit
2a556a9db6
|
@ -147,19 +147,28 @@ func (d *Dao) GetRange(key *proto.BaseKey, start, end int32) (*proto.GetRangeRes
|
|||
|
||||
func (d *Dao) GetSet(key *proto.BaseKey, value string) (*proto.GetSetResponse, error) {
|
||||
val, ok := d.lru.Get(key)
|
||||
|
||||
var oldValue string
|
||||
|
||||
if !ok {
|
||||
return nil, errorx.NotKeyErr(key.Key)
|
||||
oldValue = ""
|
||||
strValue := stringx.NewStringSingle()
|
||||
strValue.Set(value)
|
||||
err := d.lru.Add(key, strValue)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
} else {
|
||||
strVal, ok := val.(structure.StringXInterface)
|
||||
if !ok {
|
||||
return nil, errorx.DaoTypeErr("stringx")
|
||||
}
|
||||
|
||||
oldValue := strVal.Get()
|
||||
|
||||
oldValue = strVal.Get()
|
||||
_, updateLength := strVal.Set(value)
|
||||
d.lru.UpdateLruSize(updateLength)
|
||||
}
|
||||
|
||||
return &proto.GetSetResponse{Result: oldValue}, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue