Fixed fields not persisting

This commit fixes a regression in 1.30.0, where an existing
object which has fields will lose those fields when the object
geometry is overwritten using a SET or JSET and no new fields
are provided.

fixes #668
This commit is contained in:
tidwall 2022-12-29 11:43:24 -07:00
parent 44396072a5
commit 4e67d1497c
2 changed files with 13 additions and 10 deletions

View File

@ -746,16 +746,11 @@ func (s *Server) cmdSET(msg *Message) (resp.Value, commandDetails, error) {
}
var flist field.List
if len(fields) > 0 {
old := col.Get(id)
if old != nil {
flist = old.Fields()
}
for _, f := range fields {
flist = flist.Set(f)
}
} else {
flist = field.MakeList(fields)
if old := col.Get(id); old != nil {
flist = old.Fields()
}
for _, f := range fields {
flist = flist.Set(f)
}
obj := object.New(id, oobj, ex, flist)
old := col.Set(obj)

View File

@ -180,7 +180,15 @@ func keys_FSET_test(mc *mockServer) error {
Do("GET", "mykey", "myid2").Str("<nil>"),
Do("DEL", "mykey", "myid").Str("1"),
Do("GET", "mykey", "myid").Str("<nil>"),
Do("SET", "mykey", "myid", "POINT", 1, 2).OK(),
Do("GET", "mykey", "myid", "WITHFIELDS").JSON().Str(`{"ok":true,"object":{"type":"Point","coordinates":[2,1]}}`),
Do("FSET", "mykey", "myid", "f2", 1).JSON().OK(),
Do("GET", "mykey", "myid", "WITHFIELDS").JSON().Str(`{"ok":true,"object":{"type":"Point","coordinates":[2,1]},"fields":{"f2":1}}`),
Do("SET", "mykey", "myid", "POINT", 3, 4).OK(),
Do("GET", "mykey", "myid", "WITHFIELDS").JSON().Str(`{"ok":true,"object":{"type":"Point","coordinates":[4,3]},"fields":{"f2":1}}`),
Do("SET", "mykey", "myid", "HASH", "9my5xp7").OK(),
Do("DEL", "mykey", "myid").Str("1"),
Do("GET", "mykey", "myid").Str("<nil>"),
Do("CONFIG", "SET", "maxmemory", "1").OK(),
Do("FSET", "mykey", "myid", "xx", "f1", 1.1, "f2", 2.2).Err(`OOM command not allowed when used memory > 'maxmemory'`),
Do("CONFIG", "SET", "maxmemory", "0").OK(),