Skip to content

Commit

Permalink
Handle reading keys where the original value sent to the server was a…
Browse files Browse the repository at this point in the history
… list. Resolves Issue #350
  • Loading branch information
khaf committed May 28, 2021
1 parent 049fe6c commit 2a68420
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Change History


## May 28 2021: v4.5.2
Minor fix release.

* **Fixes**

- Handle reading keys where the original value sent to the server was a list. Resolves Issue #350.

## May 27 2021: v4.5.1
Minor fix release.

Expand Down
29 changes: 29 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,35 @@ var _ = gg.Describe("Aerospike", func() {
}
})

gg.It("must send List key on Put operations", func() {
kval := []int{1, 2, 3}
key, err := as.NewKey(ns, set, kval)
gm.Expect(err).ToNot(gm.HaveOccurred())

ops1 := []*as.Operation{
as.PutOp(bin1),
as.PutOp(bin2),
as.GetOp(),
}

wpolicy := as.NewWritePolicy(0, 0)
wpolicy.SendKey = true
rec, err = client.Operate(wpolicy, key, ops1...)
gm.Expect(err).ToNot(gm.HaveOccurred())

recordset, err := client.ScanAll(nil, key.Namespace(), key.SetName())
gm.Expect(err).ToNot(gm.HaveOccurred())

// make sure the result is what we put in
for r := range recordset.Results() {
gm.Expect(r.Err).ToNot(gm.HaveOccurred())
if bytes.Equal(key.Digest(), r.Record.Key.Digest()) {
gm.Expect(r.Record.Key.Value()).To(gm.Equal(as.NewListValue([]interface{}{1, 2, 3})))
gm.Expect(r.Record.Bins).To(gm.Equal(rec.Bins))
}
}
})

gg.It("must send key on Touch operations", func() {
key, err := as.NewKey(ns, set, randString(50))
gm.Expect(err).ToNot(gm.HaveOccurred())
Expand Down
17 changes: 12 additions & 5 deletions value.go
Original file line number Diff line number Diff line change
Expand Up @@ -1178,23 +1178,30 @@ func bytesToParticle(ptype int, buf []byte, offset int, length int) (interface{}
return nil, nil
}

func bytesToKeyValue(pType int, buf []byte, offset int, len int) (Value, error) {
func bytesToKeyValue(pType int, buf []byte, offset int, length int) (Value, error) {

switch pType {
case ParticleType.STRING:
return NewStringValue(string(buf[offset : offset+len])), nil
return NewStringValue(string(buf[offset : offset+length])), nil

case ParticleType.INTEGER:
return NewLongValue(Buffer.VarBytesToInt64(buf, offset, len)), nil
return NewLongValue(Buffer.VarBytesToInt64(buf, offset, length)), nil

case ParticleType.FLOAT:
return NewFloatValue(Buffer.BytesToFloat64(buf, offset)), nil

case ParticleType.BLOB:
bytes := make([]byte, len)
copy(bytes, buf[offset:offset+len])
bytes := make([]byte, length)
copy(bytes, buf[offset:offset+length])
return NewBytesValue(bytes), nil

case ParticleType.LIST:
v, err := newUnpacker(buf, offset, length).UnpackList()
if err != nil {
return nil, err
}
return ListValue(v), nil

default:
return nil, types.NewAerospikeError(types.PARSE_ERROR, fmt.Sprintf("ParticleType %d not recognized. Please file a github issue.", pType))
}
Expand Down

0 comments on commit 2a68420

Please sign in to comment.