Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a new function to support cas ttl #1198

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions rawkv/rawkv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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
Expand Down
Loading