Idea on subroutine reentrancy and database transaction

Michael Fung mike at 3open.org
Mon Apr 8 11:11:22 CEST 2013


Hi Marc,


I need to save some data using transaction protection. (Actually redis: 
watch , multi, exec ... )

[code]
# use an AnyEvent redis client

sub do_save_to_db {
   my $data = shift;

   # begin a db transaction to save $data to redis db

   # check for some criteria

   # commit if ok, else do rollback logic

}
[/code]


But I am afraid the transaction will be flawed by reentrancy. Any idea 
or pointers please?

I can only think of using a global variable to indicate we are running 
in this sub so please "wait a second and check again" using AE::timer. 
But this method seems lame X}

Thanks in advance.
Michael



More information about the anyevent mailing list