From 6c08f8e1d10a7fac17e1d65bd00c604684bf84f0 Mon Sep 17 00:00:00 2001 From: Smityz Date: Thu, 29 Feb 2024 19:44:13 +0800 Subject: [PATCH 1/2] support ttl in cas Signed-off-by: Smityz --- rawkv/rawkv.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/rawkv/rawkv.go b/rawkv/rawkv.go index 00412987f4..cf1a961236 100644 --- a/rawkv/rawkv.go +++ b/rawkv/rawkv.go @@ -648,6 +648,10 @@ func (c *Client) Checksum(ctx context.Context, startKey, endKey []byte, options // with the normal write operation in rawkv mode. If multiple clients exist, it's up to the clients the sync the atomic mode flag. // If some clients write in atomic mode but the other don't, the linearizability of TiKV will be violated. func (c *Client) CompareAndSwap(ctx context.Context, key, previousValue, newValue []byte, options ...RawOption) ([]byte, bool, error) { + return c.CompareAndSwapTTL(ctx, key, previousValue, newValue, 0, options...) +} + +func (c *Client) CompareAndSwapTTL(ctx context.Context, key, previousValue, newValue []byte, ttl uint64, options ...RawOption) ([]byte, bool, error) { if !c.atomic { return nil, false, errors.New("using CompareAndSwap without enable atomic mode") } @@ -657,6 +661,7 @@ func (c *Client) CompareAndSwap(ctx context.Context, key, previousValue, newValu Key: key, Value: newValue, Cf: c.getColumnFamily(opts), + Ttl: ttl, } if previousValue == nil { reqArgs.PreviousNotExist = true From a3cdb373d466d50fc7298b9e3eeb83a64ecbcc76 Mon Sep 17 00:00:00 2001 From: Smityz Date: Thu, 21 Mar 2024 16:05:45 +0800 Subject: [PATCH 2/2] lint Signed-off-by: Smityz --- rawkv/rawkv.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rawkv/rawkv.go b/rawkv/rawkv.go index cf1a961236..fe3dd5c4d9 100644 --- a/rawkv/rawkv.go +++ b/rawkv/rawkv.go @@ -661,7 +661,7 @@ func (c *Client) CompareAndSwapTTL(ctx context.Context, key, previousValue, newV Key: key, Value: newValue, Cf: c.getColumnFamily(opts), - Ttl: ttl, + Ttl: ttl, } if previousValue == nil { reqArgs.PreviousNotExist = true