@@ -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,13 @@ impl Client {
258
274
Ok ( ( ) )
259
275
}
260
276
277
+ pub fn batch_put_sync (
278
+ & self ,
279
+ pairs : impl IntoIterator < Item = impl Into < KvPair > > ,
280
+ ) -> Result < ( ) > {
281
+ block_on ( self . batch_put ( pairs) )
282
+ }
283
+
261
284
/// Create a new 'delete' request.
262
285
///
263
286
/// Once resolved this request will result in the deletion of the given key.
@@ -288,6 +311,10 @@ impl Client {
288
311
Ok ( ( ) )
289
312
}
290
313
314
+ pub fn delete_sync ( & self , key : impl Into < Key > ) -> Result < ( ) > {
315
+ block_on ( self . delete ( key) )
316
+ }
317
+
291
318
/// Create a new 'batch delete' request.
292
319
///
293
320
/// Once resolved this request will result in the deletion of the given keys.
@@ -319,6 +346,10 @@ impl Client {
319
346
Ok ( ( ) )
320
347
}
321
348
349
+ pub fn batch_delete_sync ( & self , keys : impl IntoIterator < Item = impl Into < Key > > ) -> Result < ( ) > {
350
+ block_on ( self . batch_delete ( keys) )
351
+ }
352
+
322
353
/// Create a new 'delete range' request.
323
354
///
324
355
/// Once resolved this request will result in the deletion of all keys lying in the given range.
@@ -347,6 +378,10 @@ impl Client {
347
378
Ok ( ( ) )
348
379
}
349
380
381
+ pub fn delete_range_sync ( & self , range : impl Into < BoundRange > ) -> Result < ( ) > {
382
+ block_on ( self . delete_range ( range) )
383
+ }
384
+
350
385
/// Create a new 'scan' request.
351
386
///
352
387
/// Once resolved this request will result in a `Vec` of key-value pairs that lies in the specified range.
@@ -371,6 +406,10 @@ impl Client {
371
406
self . scan_inner ( range. into ( ) , limit, false ) . await
372
407
}
373
408
409
+ pub fn scan_sync ( & self , range : impl Into < BoundRange > , limit : u32 ) -> Result < Vec < KvPair > > {
410
+ block_on ( self . scan ( range, limit) )
411
+ }
412
+
374
413
/// Create a new 'scan' request that only returns the keys.
375
414
///
376
415
/// Once resolved this request will result in a `Vec` of keys that lies in the specified range.
@@ -400,6 +439,10 @@ impl Client {
400
439
. collect ( ) )
401
440
}
402
441
442
+ pub fn scan_keys_sync ( & self , range : impl Into < BoundRange > , limit : u32 ) -> Result < Vec < Key > > {
443
+ block_on ( self . scan_keys ( range, limit) )
444
+ }
445
+
403
446
/// Create a new 'batch scan' request.
404
447
///
405
448
/// Once resolved this request will result in a set of scanners over the given keys.
@@ -432,6 +475,14 @@ impl Client {
432
475
self . batch_scan_inner ( ranges, each_limit, false ) . await
433
476
}
434
477
478
+ pub fn batch_scan_sync (
479
+ & self ,
480
+ ranges : impl IntoIterator < Item = impl Into < BoundRange > > ,
481
+ each_limit : u32 ,
482
+ ) -> Result < Vec < KvPair > > {
483
+ block_on ( self . batch_scan ( ranges, each_limit) )
484
+ }
485
+
435
486
/// Create a new 'batch scan' request that only returns the keys.
436
487
///
437
488
/// Once resolved this request will result in a set of scanners over the given keys.
@@ -468,6 +519,14 @@ impl Client {
468
519
. collect ( ) )
469
520
}
470
521
522
+ pub fn batch_scan_keys_sync (
523
+ & self ,
524
+ ranges : impl IntoIterator < Item = impl Into < BoundRange > > ,
525
+ each_limit : u32 ,
526
+ ) -> Result < Vec < Key > > {
527
+ block_on ( self . batch_scan_keys ( ranges, each_limit) )
528
+ }
529
+
471
530
/// Create a new *atomic* 'compare and set' request.
472
531
///
473
532
/// Once resolved this request will result in an atomic `compare and set'
@@ -502,6 +561,15 @@ impl Client {
502
561
plan. execute ( ) . await
503
562
}
504
563
564
+ pub async fn compare_and_swap_sync (
565
+ & self ,
566
+ key : impl Into < Key > ,
567
+ previous_value : impl Into < Option < Value > > ,
568
+ new_value : impl Into < Value > ,
569
+ ) -> Result < ( Option < Value > , bool ) > {
570
+ block_on ( self . compare_and_swap ( key, previous_value, new_value) )
571
+ }
572
+
505
573
async fn scan_inner (
506
574
& self ,
507
575
range : impl Into < BoundRange > ,
0 commit comments