@@ -10,6 +10,7 @@ use crate::{
1010 request:: { Collect , Plan } ,
1111 BoundRange , ColumnFamily , Key , KvPair , Result , Value ,
1212} ;
13+ use futures:: executor:: block_on;
1314use log:: debug;
1415use std:: { sync:: Arc , u32} ;
1516
@@ -159,6 +160,10 @@ impl Client {
159160 plan. execute ( ) . await
160161 }
161162
163+ pub fn get_sync ( & self , key : impl Into < Key > ) -> Result < Option < Value > > {
164+ block_on ( self . get ( key) )
165+ }
166+
162167 /// Create a new 'batch get' request.
163168 ///
164169 /// Once resolved this request will result in the fetching of the values associated with the
@@ -193,6 +198,13 @@ impl Client {
193198 . map ( |r| r. into_iter ( ) . map ( Into :: into) . collect ( ) )
194199 }
195200
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+
196208 /// Create a new 'put' request.
197209 ///
198210 /// Once resolved this request will result in the setting of the value associated with the given key.
@@ -222,6 +234,10 @@ impl Client {
222234 Ok ( ( ) )
223235 }
224236
237+ pub fn put_sync ( & self , key : impl Into < Key > , value : impl Into < Value > ) -> Result < ( ) > {
238+ block_on ( self . put ( key, value) )
239+ }
240+
225241 /// Create a new 'batch put' request.
226242 ///
227243 /// Once resolved this request will result in the setting of the values associated with the given keys.
@@ -258,6 +274,13 @@ impl Client {
258274 Ok ( ( ) )
259275 }
260276
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+
261284 /// Create a new 'delete' request.
262285 ///
263286 /// Once resolved this request will result in the deletion of the given key.
@@ -288,6 +311,10 @@ impl Client {
288311 Ok ( ( ) )
289312 }
290313
314+ pub fn delete_sync ( & self , key : impl Into < Key > ) -> Result < ( ) > {
315+ block_on ( self . delete ( key) )
316+ }
317+
291318 /// Create a new 'batch delete' request.
292319 ///
293320 /// Once resolved this request will result in the deletion of the given keys.
@@ -319,6 +346,10 @@ impl Client {
319346 Ok ( ( ) )
320347 }
321348
349+ pub fn batch_delete_sync ( & self , keys : impl IntoIterator < Item = impl Into < Key > > ) -> Result < ( ) > {
350+ block_on ( self . batch_delete ( keys) )
351+ }
352+
322353 /// Create a new 'delete range' request.
323354 ///
324355 /// Once resolved this request will result in the deletion of all keys lying in the given range.
@@ -347,6 +378,10 @@ impl Client {
347378 Ok ( ( ) )
348379 }
349380
381+ pub fn delete_range_sync ( & self , range : impl Into < BoundRange > ) -> Result < ( ) > {
382+ block_on ( self . delete_range ( range) )
383+ }
384+
350385 /// Create a new 'scan' request.
351386 ///
352387 /// 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 {
371406 self . scan_inner ( range. into ( ) , limit, false ) . await
372407 }
373408
409+ pub fn scan_sync ( & self , range : impl Into < BoundRange > , limit : u32 ) -> Result < Vec < KvPair > > {
410+ block_on ( self . scan ( range, limit) )
411+ }
412+
374413 /// Create a new 'scan' request that only returns the keys.
375414 ///
376415 /// Once resolved this request will result in a `Vec` of keys that lies in the specified range.
@@ -400,6 +439,10 @@ impl Client {
400439 . collect ( ) )
401440 }
402441
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+
403446 /// Create a new 'batch scan' request.
404447 ///
405448 /// Once resolved this request will result in a set of scanners over the given keys.
@@ -432,6 +475,14 @@ impl Client {
432475 self . batch_scan_inner ( ranges, each_limit, false ) . await
433476 }
434477
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+
435486 /// Create a new 'batch scan' request that only returns the keys.
436487 ///
437488 /// Once resolved this request will result in a set of scanners over the given keys.
@@ -468,6 +519,14 @@ impl Client {
468519 . collect ( ) )
469520 }
470521
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+
471530 /// Create a new *atomic* 'compare and set' request.
472531 ///
473532 /// Once resolved this request will result in an atomic `compare and set'
@@ -502,6 +561,15 @@ impl Client {
502561 plan. execute ( ) . await
503562 }
504563
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+
505573 async fn scan_inner (
506574 & self ,
507575 range : impl Into < BoundRange > ,
0 commit comments