2121import java .util .List ;
2222import java .util .Map ;
2323import java .util .Optional ;
24+ import java .util .concurrent .TimeUnit ;
2425import org .tikv .common .TiSession ;
2526import org .tikv .common .util .Pair ;
2627import org .tikv .common .util .ScanOption ;
2728import org .tikv .kvproto .Kvrpcpb ;
2829
2930public interface RawKVClientBase extends AutoCloseable {
31+
3032 // https://www.github.com/pingcap/tidb/blob/master/store/tikv/rawkv.go
3133 int MAX_RAW_SCAN_LIMIT = 10240 ;
3234 int MAX_RAW_BATCH_LIMIT = 1024 ;
@@ -51,6 +53,20 @@ public interface RawKVClientBase extends AutoCloseable {
5153 */
5254 void put (ByteString key , ByteString value , long ttl );
5355
56+ /**
57+ * Put a raw key-value pair to TiKV
58+ *
59+ * @see #put(ByteString, ByteString, long)
60+ * @param key raw key
61+ * @param value raw value
62+ * @param duration the duration of the key, 0 means the key will never be outdated
63+ * @param timeUnit the time unit of duration
64+ */
65+ default void put (ByteString key , ByteString value , long duration , TimeUnit timeUnit ) {
66+ Long seconds = timeUnit .toSeconds (duration );
67+ put (key , value , seconds );
68+ }
69+
5470 /**
5571 * Put a key-value pair if it does not exist. This API is atomic.
5672 *
@@ -76,6 +92,25 @@ public interface RawKVClientBase extends AutoCloseable {
7692 */
7793 Optional <ByteString > putIfAbsent (ByteString key , ByteString value , long ttl );
7894
95+ /**
96+ * Put a key-value pair with TTL if it does not exist. This API is atomic.
97+ *
98+ * <p>To use this API, please enable `tikv.enable_atomic_for_cas`.
99+ *
100+ * @see #putIfAbsent(ByteString, ByteString, long)
101+ * @param key key
102+ * @param value value
103+ * @param duration duration of key, 0 means the key will never be outdated.
104+ * @param timeUnit the time unit of duration
105+ * @return a ByteString. returns Optional.EMPTY if the value is written successfully. returns the
106+ * previous key if the value already exists, and does not write to TiKV.
107+ */
108+ default Optional <ByteString > putIfAbsent (
109+ ByteString key , ByteString value , long duration , TimeUnit timeUnit ) {
110+ Long seconds = timeUnit .toSeconds (duration );
111+ return putIfAbsent (key , value , seconds );
112+ }
113+
79114 /**
80115 * Put a key-value pair if the prevValue matched the value in TiKV. This API is atomic.
81116 *
@@ -97,6 +132,27 @@ public interface RawKVClientBase extends AutoCloseable {
97132 */
98133 void compareAndSet (ByteString key , Optional <ByteString > prevValue , ByteString value , long ttl );
99134
135+ /**
136+ * pair if the prevValue matched the value in TiKV. This API is atomic.
137+ *
138+ * <p>To use this API, please enable `tikv.enable_atomic_for_cas`.
139+ *
140+ * @see #compareAndSet(ByteString, Optional, ByteString, long)
141+ * @param key key
142+ * @param value value
143+ * @param duration duration of key , 0 means the key will never be outdated.
144+ * @param timeUnit time unit of duration
145+ */
146+ default void compareAndSet (
147+ ByteString key ,
148+ Optional <ByteString > prevValue ,
149+ ByteString value ,
150+ long duration ,
151+ TimeUnit timeUnit ) {
152+ long seconds = timeUnit .toSeconds (duration );
153+ compareAndSet (key , prevValue , value , seconds );
154+ }
155+
100156 /**
101157 * Put a set of raw key-value pair to TiKV.
102158 *
@@ -112,6 +168,19 @@ public interface RawKVClientBase extends AutoCloseable {
112168 */
113169 void batchPut (Map <ByteString , ByteString > kvPairs , long ttl );
114170
171+ /**
172+ * Put a set of raw key-value pair to TiKV.
173+ *
174+ * @see #batchPut(Map, long)
175+ * @param kvPairs kvPairs
176+ * @param duration the duration of keys to be put, 0 means the keys will never be outdated
177+ * @param timeUnit time unit of duration
178+ */
179+ default void batchPut (Map <ByteString , ByteString > kvPairs , long duration , TimeUnit timeUnit ) {
180+ long seconds = timeUnit .toSeconds (duration );
181+ batchPut (kvPairs , seconds );
182+ }
183+
115184 /**
116185 * Get a raw key-value pair from TiKV if key exists
117186 *
0 commit comments