… | |
… | |
3 | BDB - Asynchronous Berkeley DB access |
3 | BDB - Asynchronous Berkeley DB access |
4 | |
4 | |
5 | =head1 SYNOPSIS |
5 | =head1 SYNOPSIS |
6 | |
6 | |
7 | use BDB; |
7 | use BDB; |
|
|
8 | |
|
|
9 | my $env = db_env_create; |
|
|
10 | |
|
|
11 | mkdir "bdtest", 0700; |
|
|
12 | db_env_open |
|
|
13 | $env, |
|
|
14 | "bdtest", |
|
|
15 | BDB::INIT_LOCK | BDB::INIT_LOG | BDB::INIT_MPOOL |
|
|
16 | | BDB::INIT_TXN | BDB::RECOVER | BDB::USE_ENVIRON | BDB::CREATE, |
|
|
17 | 0600; |
|
|
18 | |
|
|
19 | $env->set_flags (BDB::AUTO_COMMIT | BDB::TXN_NOSYNC, 1); |
|
|
20 | |
|
|
21 | my $db = db_create $env; |
|
|
22 | db_open $db, undef, "table", undef, BDB::BTREE, BDB::AUTO_COMMIT | BDB::CREATE |
|
|
23 | | BDB::READ_UNCOMMITTED, 0600; |
|
|
24 | db_put $db, undef, "key", "data", 0, sub { |
|
|
25 | db_del $db, undef, "key"; |
|
|
26 | }; |
|
|
27 | db_sync $db; |
|
|
28 | |
|
|
29 | # automatic result processing with AnyEvent: |
|
|
30 | our $FH; open $FH, "<&=" . BDB::poll_fileno; |
|
|
31 | our $WATCHER = AnyEvent->io (fh => $FH, poll => 'r', cb => \&BDB::poll_cb); |
|
|
32 | |
|
|
33 | # automatic result processing with EV: |
|
|
34 | my $WATCHER = EV::io BDB::poll_fileno, EV::READ, \&BDB::poll_cb; |
|
|
35 | |
|
|
36 | # with Glib: |
|
|
37 | add_watch Glib::IO BDB::poll_fileno, |
|
|
38 | in => sub { BDB::poll_cb; 1 }; |
|
|
39 | |
|
|
40 | # or simply flush manually |
|
|
41 | BDB::flush; |
|
|
42 | |
8 | |
43 | |
9 | =head1 DESCRIPTION |
44 | =head1 DESCRIPTION |
10 | |
45 | |
11 | See the BerkeleyDB documentation (L<http://www.oracle.com/technology/documentation/berkeley-db/db/index.html>). |
46 | See the BerkeleyDB documentation (L<http://www.oracle.com/technology/documentation/berkeley-db/db/index.html>). |
12 | The BDB API is very similar to the C API (the translation has been very faithful). |
47 | The BDB API is very similar to the C API (the translation has been very faithful). |