@@ -13,7 +13,7 @@ use pyo3::{
1313 Bound , Py , PyAny , PyRef , Python ,
1414 types:: { PyBytes , PyDateTime } ,
1515} ;
16- use tokio:: sync:: { Mutex , RwLock } ;
16+ use tokio:: sync:: Mutex ;
1717
1818use crate :: {
1919 exceptions:: rust_err:: { NatsrpyError , NatsrpyResult } ,
@@ -229,20 +229,19 @@ pub struct KeyValue {
229229 put_prefix : Option < String > ,
230230 #[ pyo3( get) ]
231231 use_jetstream_prefix : bool ,
232- store : Arc < RwLock < async_nats:: jetstream:: kv:: Store > > ,
232+ store : Arc < async_nats:: jetstream:: kv:: Store > ,
233233}
234234
235235impl KeyValue {
236236 #[ must_use]
237237 pub fn new ( store : async_nats:: jetstream:: kv:: Store ) -> Self {
238- // store.
239238 Self {
240239 name : store. name . clone ( ) ,
241240 stream_name : store. stream_name . clone ( ) ,
242241 prefix : store. prefix . clone ( ) ,
243242 put_prefix : store. put_prefix . clone ( ) ,
244243 use_jetstream_prefix : store. use_jetstream_prefix ,
245- store : Arc :: new ( RwLock :: new ( store) ) ,
244+ store : Arc :: new ( store) ,
246245 }
247246 }
248247}
@@ -253,8 +252,6 @@ impl KeyValue {
253252 let store = self . store . clone ( ) ;
254253 natsrpy_future ( py, async move {
255254 Ok ( store
256- . read ( )
257- . await
258255 . get ( key)
259256 . await ?
260257 . map ( |data| Python :: attach ( move |gil| PyBytes :: new ( gil, & data) . unbind ( ) ) ) )
@@ -274,12 +271,10 @@ impl KeyValue {
274271 natsrpy_future ( py, async move {
275272 if let Some ( ttl) = ttl {
276273 Ok ( store
277- . read ( )
278- . await
279274 . create_with_ttl ( key, data, ttl. into ( ) )
280275 . await ?)
281276 } else {
282- Ok ( store. read ( ) . await . create ( key, data) . await ?)
277+ Ok ( store. create ( key, data) . await ?)
283278 }
284279 } )
285280 }
@@ -300,14 +295,10 @@ impl KeyValue {
300295 natsrpy_future ( py, async move {
301296 match ( ttl, expect_revision) {
302297 ( None , _) => Ok ( store
303- . read ( )
304- . await
305298 . purge_expect_revision ( key, expect_revision)
306299 . await ?) ,
307- ( Some ( ttl) , None ) => Ok ( store. read ( ) . await . purge_with_ttl ( key, ttl. into ( ) ) . await ?) ,
300+ ( Some ( ttl) , None ) => Ok ( store. purge_with_ttl ( key, ttl. into ( ) ) . await ?) ,
308301 ( Some ( ttl) , Some ( revision) ) => Ok ( store
309- . read ( )
310- . await
311302 . purge_expect_revision_with_ttl ( key, revision, ttl. into ( ) )
312303 . await ?) ,
313304 }
@@ -324,7 +315,7 @@ impl KeyValue {
324315 let data = value. into ( ) ;
325316 natsrpy_future (
326317 py,
327- async move { Ok ( store. read ( ) . await . put ( key, data) . await ?) } ,
318+ async move { Ok ( store. put ( key, data) . await ?) } ,
328319 )
329320 }
330321
@@ -341,8 +332,6 @@ impl KeyValue {
341332 let store = self . store . clone ( ) ;
342333 natsrpy_future ( py, async move {
343334 Ok ( store
344- . read ( )
345- . await
346335 . delete_expect_revision ( key, expect_revision)
347336 . await ?)
348337 } )
@@ -358,8 +347,6 @@ impl KeyValue {
358347 let store = self . store . clone ( ) ;
359348 natsrpy_future ( py, async move {
360349 Ok ( store
361- . read ( )
362- . await
363350 . update ( key, value. into ( ) , revision)
364351 . await ?)
365352 } )
@@ -369,7 +356,7 @@ impl KeyValue {
369356 let store = self . store . clone ( ) ;
370357 natsrpy_future ( py, async move {
371358 Ok ( KVEntryIterator :: new ( Streamer :: new (
372- store. read ( ) . await . history ( key) . await ?,
359+ store. history ( key) . await ?,
373360 ) ) )
374361 } )
375362 }
@@ -383,9 +370,9 @@ impl KeyValue {
383370 let store = self . store . clone ( ) ;
384371 natsrpy_future ( py, async move {
385372 let watch = if let Some ( rev) = from_revision {
386- store. read ( ) . await . watch_all_from_revision ( rev) . await ?
373+ store. watch_all_from_revision ( rev) . await ?
387374 } else {
388- store. read ( ) . await . watch_all ( ) . await ?
375+ store. watch_all ( ) . await ?
389376 } ;
390377 Ok ( KVEntryIterator :: new ( Streamer :: new ( watch) ) )
391378 } )
@@ -401,9 +388,9 @@ impl KeyValue {
401388 let store = self . store . clone ( ) ;
402389 natsrpy_future ( py, async move {
403390 let watch = if let Some ( rev) = from_revision {
404- store. read ( ) . await . watch_from_revision ( key, rev) . await ?
391+ store. watch_from_revision ( key, rev) . await ?
405392 } else {
406- store. read ( ) . await . watch ( key) . await ?
393+ store. watch ( key) . await ?
407394 } ;
408395 Ok ( KVEntryIterator :: new ( Streamer :: new ( watch) ) )
409396 } )
@@ -417,7 +404,7 @@ impl KeyValue {
417404 let store = self . store . clone ( ) ;
418405 natsrpy_future ( py, async move {
419406 Ok ( KVEntryIterator :: new ( Streamer :: new (
420- store. read ( ) . await . watch_with_history ( key) . await ?,
407+ store. watch_with_history ( key) . await ?,
421408 ) ) )
422409 } )
423410 }
@@ -430,7 +417,7 @@ impl KeyValue {
430417 let store = self . store . clone ( ) ;
431418 natsrpy_future ( py, async move {
432419 Ok ( KVEntryIterator :: new ( Streamer :: new (
433- store. read ( ) . await . watch_many ( keys) . await ?,
420+ store. watch_many ( keys) . await ?,
434421 ) ) )
435422 } )
436423 }
@@ -443,7 +430,7 @@ impl KeyValue {
443430 let store = self . store . clone ( ) ;
444431 natsrpy_future ( py, async move {
445432 Ok ( KVEntryIterator :: new ( Streamer :: new (
446- store. read ( ) . await . watch_many_with_history ( keys) . await ?,
433+ store. watch_many_with_history ( keys) . await ?,
447434 ) ) )
448435 } )
449436 }
@@ -462,16 +449,12 @@ impl KeyValue {
462449 natsrpy_future ( py, async move {
463450 let entry = if let Some ( rev) = revision {
464451 store
465- . read ( )
466- . await
467452 . entry_for_revision ( key, rev)
468453 . await ?
469454 . map ( KVEntry :: try_from)
470455 . transpose ( ) ?
471456 } else {
472457 store
473- . read ( )
474- . await
475458 . entry ( key)
476459 . await ?
477460 . map ( KVEntry :: try_from)
@@ -484,15 +467,15 @@ impl KeyValue {
484467 pub fn status < ' py > ( & self , py : Python < ' py > ) -> NatsrpyResult < Bound < ' py , PyAny > > {
485468 let store = self . store . clone ( ) ;
486469 natsrpy_future ( py, async move {
487- KVStatus :: try_from ( store. read ( ) . await . status ( ) . await ?)
470+ KVStatus :: try_from ( store. status ( ) . await ?)
488471 } )
489472 }
490473
491474 pub fn keys < ' py > ( & self , py : Python < ' py > ) -> NatsrpyResult < Bound < ' py , PyAny > > {
492475 let store = self . store . clone ( ) ;
493476 natsrpy_future ( py, async move {
494477 Ok ( KeysIterator :: new ( Streamer :: new (
495- store. read ( ) . await . keys ( ) . await ?,
478+ store. keys ( ) . await ?,
496479 ) ) )
497480 } )
498481 }
0 commit comments