Skip to content

Commit 82b05d3

Browse files
committed
Support of keyspace field for BATCH message
1 parent 974fa12 commit 82b05d3

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

conn.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,6 +1554,10 @@ func (c *Conn) executeBatch(ctx context.Context, batch *Batch) *Iter {
15541554
customPayload: batch.CustomPayload,
15551555
}
15561556

1557+
if c.version > protoVersion4 {
1558+
req.keyspace = c.currentKeyspace
1559+
}
1560+
15571561
stmts := make(map[string]string, len(batch.Entries))
15581562

15591563
for i := 0; i < n; i++ {

frame.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,6 +1659,9 @@ type writeBatchFrame struct {
16591659

16601660
//v4+
16611661
customPayload map[string][]byte
1662+
1663+
//v5+
1664+
keyspace string
16621665
}
16631666

16641667
func (w *writeBatchFrame) buildFrame(framer *framer, streamID int) error {
@@ -1719,6 +1722,9 @@ func (f *framer) writeBatchFrame(streamID int, w *writeBatchFrame, customPayload
17191722
}
17201723

17211724
if f.proto > protoVersion4 {
1725+
if w.keyspace != "" {
1726+
flags |= flagWithKeyspace
1727+
}
17221728
f.writeUint(uint32(flags))
17231729
} else {
17241730
f.writeByte(flags)
@@ -1737,6 +1743,13 @@ func (f *framer) writeBatchFrame(streamID int, w *writeBatchFrame, customPayload
17371743
}
17381744
f.writeLong(ts)
17391745
}
1746+
1747+
if w.keyspace != "" {
1748+
if f.proto < protoVersion5 {
1749+
panic(fmt.Errorf("the keyspace can only be set with protocol 5 or higher"))
1750+
}
1751+
f.writeString(w.keyspace)
1752+
}
17401753
}
17411754

17421755
return f.finish()

0 commit comments

Comments
 (0)