Skip to content

Commit

Permalink
Support of keyspace field for BATCH message
Browse files Browse the repository at this point in the history
  • Loading branch information
worryg0d committed Jul 15, 2024
1 parent 974fa12 commit 82b05d3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -1554,6 +1554,10 @@ func (c *Conn) executeBatch(ctx context.Context, batch *Batch) *Iter {
customPayload: batch.CustomPayload,
}

if c.version > protoVersion4 {
req.keyspace = c.currentKeyspace
}

stmts := make(map[string]string, len(batch.Entries))

for i := 0; i < n; i++ {
Expand Down
13 changes: 13 additions & 0 deletions frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,9 @@ type writeBatchFrame struct {

//v4+
customPayload map[string][]byte

//v5+
keyspace string
}

func (w *writeBatchFrame) buildFrame(framer *framer, streamID int) error {
Expand Down Expand Up @@ -1719,6 +1722,9 @@ func (f *framer) writeBatchFrame(streamID int, w *writeBatchFrame, customPayload
}

if f.proto > protoVersion4 {
if w.keyspace != "" {
flags |= flagWithKeyspace
}
f.writeUint(uint32(flags))
} else {
f.writeByte(flags)
Expand All @@ -1737,6 +1743,13 @@ func (f *framer) writeBatchFrame(streamID int, w *writeBatchFrame, customPayload
}
f.writeLong(ts)
}

if w.keyspace != "" {
if f.proto < protoVersion5 {
panic(fmt.Errorf("the keyspace can only be set with protocol 5 or higher"))
}
f.writeString(w.keyspace)
}
}

return f.finish()
Expand Down

0 comments on commit 82b05d3

Please sign in to comment.