@@ -10,6 +10,7 @@ use crate::{
10
10
request:: { Collect , Plan } ,
11
11
BoundRange , ColumnFamily , Key , KvPair , Result , Value ,
12
12
} ;
13
+ use futures:: executor:: block_on;
13
14
use log:: debug;
14
15
use std:: { sync:: Arc , u32} ;
15
16
@@ -159,6 +160,10 @@ impl Client {
159
160
plan. execute ( ) . await
160
161
}
161
162
163
+ pub fn get_sync ( & self , key : impl Into < Key > ) -> Result < Option < Value > > {
164
+ block_on ( self . get ( key) )
165
+ }
166
+
162
167
/// Create a new 'batch get' request.
163
168
///
164
169
/// Once resolved this request will result in the fetching of the values associated with the
@@ -193,6 +198,13 @@ impl Client {
193
198
. map ( |r| r. into_iter ( ) . map ( Into :: into) . collect ( ) )
194
199
}
195
200
201
+ pub fn batch_get_sync (
202
+ & self ,
203
+ keys : impl IntoIterator < Item = impl Into < Key > > ,
204
+ ) -> Result < Vec < KvPair > > {
205
+ block_on ( self . batch_get ( keys) )
206
+ }
207
+
196
208
/// Create a new 'put' request.
197
209
///
198
210
/// Once resolved this request will result in the setting of the value associated with the given key.
@@ -222,6 +234,10 @@ impl Client {
222
234
Ok ( ( ) )
223
235
}
224
236
237
+ pub fn put_sync ( & self , key : impl Into < Key > , value : impl Into < Value > ) -> Result < ( ) > {
238
+ block_on ( self . put ( key, value) )
239
+ }
240
+
225
241
/// Create a new 'batch put' request.
226
242
///
227
243
/// Once resolved this request will result in the setting of the values associated with the given keys.
@@ -258,6 +274,10 @@ impl Client {
258
274
Ok ( ( ) )
259
275
}
260
276
277
+ pub fn batch_put_sync ( & self , pairs : impl IntoIterator < Item = impl Into < KvPair > > ) -> Result < ( ) > {
278
+ block_on ( self . batch_put ( pairs) )
279
+ }
280
+
261
281
/// Create a new 'delete' request.
262
282
///
263
283
/// Once resolved this request will result in the deletion of the given key.
@@ -288,6 +308,10 @@ impl Client {
288
308
Ok ( ( ) )
289
309
}
290
310
311
+ pub fn delete_sync ( & self , key : impl Into < Key > ) -> Result < ( ) > {
312
+ block_on ( self . delete ( key) )
313
+ }
314
+
291
315
/// Create a new 'batch delete' request.
292
316
///
293
317
/// Once resolved this request will result in the deletion of the given keys.
@@ -319,6 +343,10 @@ impl Client {
319
343
Ok ( ( ) )
320
344
}
321
345
346
+ pub fn batch_delete_sync ( & self , keys : impl IntoIterator < Item = impl Into < Key > > ) -> Result < ( ) > {
347
+ block_on ( self . batch_delete ( keys) )
348
+ }
349
+
322
350
/// Create a new 'delete range' request.
323
351
///
324
352
/// Once resolved this request will result in the deletion of all keys lying in the given range.
@@ -347,6 +375,10 @@ impl Client {
347
375
Ok ( ( ) )
348
376
}
349
377
378
+ pub fn delete_range_sync ( & self , range : impl Into < BoundRange > ) -> Result < ( ) > {
379
+ block_on ( self . delete_range ( range) )
380
+ }
381
+
350
382
/// Create a new 'scan' request.
351
383
///
352
384
/// Once resolved this request will result in a `Vec` of key-value pairs that lies in the specified range.
@@ -371,6 +403,10 @@ impl Client {
371
403
self . scan_inner ( range. into ( ) , limit, false ) . await
372
404
}
373
405
406
+ pub fn scan_sync ( & self , range : impl Into < BoundRange > , limit : u32 ) -> Result < Vec < KvPair > > {
407
+ block_on ( self . scan ( range, limit) )
408
+ }
409
+
374
410
/// Create a new 'scan' request that only returns the keys.
375
411
///
376
412
/// Once resolved this request will result in a `Vec` of keys that lies in the specified range.
@@ -400,6 +436,10 @@ impl Client {
400
436
. collect ( ) )
401
437
}
402
438
439
+ pub fn scan_keys_sync ( & self , range : impl Into < BoundRange > , limit : u32 ) -> Result < Vec < Key > > {
440
+ block_on ( self . scan_keys ( range, limit) )
441
+ }
442
+
403
443
/// Create a new 'batch scan' request.
404
444
///
405
445
/// Once resolved this request will result in a set of scanners over the given keys.
@@ -432,6 +472,14 @@ impl Client {
432
472
self . batch_scan_inner ( ranges, each_limit, false ) . await
433
473
}
434
474
475
+ pub fn batch_scan_sync (
476
+ & self ,
477
+ ranges : impl IntoIterator < Item = impl Into < BoundRange > > ,
478
+ each_limit : u32 ,
479
+ ) -> Result < Vec < KvPair > > {
480
+ block_on ( self . batch_scan ( ranges, each_limit) )
481
+ }
482
+
435
483
/// Create a new 'batch scan' request that only returns the keys.
436
484
///
437
485
/// Once resolved this request will result in a set of scanners over the given keys.
@@ -468,6 +516,14 @@ impl Client {
468
516
. collect ( ) )
469
517
}
470
518
519
+ pub fn batch_scan_keys_sync (
520
+ & self ,
521
+ ranges : impl IntoIterator < Item = impl Into < BoundRange > > ,
522
+ each_limit : u32 ,
523
+ ) -> Result < Vec < Key > > {
524
+ block_on ( self . batch_scan_keys ( ranges, each_limit) )
525
+ }
526
+
471
527
/// Create a new *atomic* 'compare and set' request.
472
528
///
473
529
/// Once resolved this request will result in an atomic `compare and set'
@@ -502,6 +558,15 @@ impl Client {
502
558
plan. execute ( ) . await
503
559
}
504
560
561
+ pub async fn compare_and_swap_sync (
562
+ & self ,
563
+ key : impl Into < Key > ,
564
+ previous_value : impl Into < Option < Value > > ,
565
+ new_value : impl Into < Value > ,
566
+ ) -> Result < ( Option < Value > , bool ) > {
567
+ block_on ( self . compare_and_swap ( key, previous_value, new_value) )
568
+ }
569
+
505
570
async fn scan_inner (
506
571
& self ,
507
572
range : impl Into < BoundRange > ,
0 commit comments