diff --git a/storage/dao/stringx.go b/storage/dao/stringx.go index 21cadf9..87de94a 100644 --- a/storage/dao/stringx.go +++ b/storage/dao/stringx.go @@ -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() + _, updateLength := strVal.Set(value) + d.lru.UpdateLruSize(updateLength) } - strVal, ok := val.(structure.StringXInterface) - if !ok { - return nil, errorx.DaoTypeErr("stringx") - } - - oldValue := strVal.Get() - - _, updateLength := strVal.Set(value) - d.lru.UpdateLruSize(updateLength) return &proto.GetSetResponse{Result: oldValue}, nil }