Data::RecordStore - Simple store for text and byte data
use Data::RecordStore; $store = Data::RecordStore->init_store( DIRECTORY => $directory, MAX_FILE_SIZE => 20_000_000_000 ); $data = "TEXT OR BYTES"; # the first record id is 1 my $id = $store->stow( $data ); my $val = $store->fetch( $some_id ); my $count = $store->entry_count; $store->lock( qw( FEE FIE FOE FUM ) ); # lock blocks, may not be called until unlock. $store->unlock; # unlocks all $store->delete_record( $id_to_remove ); #deletes the old record $reopened_store = Data::RecordStore->open_store( $directory );
Data::RecordStore is a simple way to store serialized text or byte data. It is written entirely in perl with no non-core dependencies. It is designed to be both easy to set up and easy to use.
It adheres to a RecordStore interface so other implementations exist using other technologies rather than simple binary file storage.
Transactions (see below) can be created that stow records. They come with the standard commit and rollback methods. If a process dies in the middle of a commit or rollback, the operation can be reattempted. Incomplete transactions are obtained by the store's 'list_transactions' method.
Data::RecordStore operates directly and instantly on the file system. It is not a daemon or server and is not thread safe. It can be used in a thread safe manner if the controlling program uses locking mechanisms, including the locks that the store provides.
Constructs a data store according to the options.
Options
Opens the existing store in the given directory.
Returns the record associated with the ID. If the ID has no record associated with it, undef is returned.
This saves the text or byte data to the record store. If an id is passed in, this saves the data to the record for that id, overwriting what was there. If an id is not passed in, it creates a new record store.
Returns the id of the record written to.
This sets up a new empty record and returns the id for it.
Removes the entry with the given id from the store, freeing up its space. It does not reuse the id.
Adds an advisory (flock) lock for each of the unique names given. This may not be called twice in a row without an unlock in between and will die if that happens.
Unlocks all names locked by this thread
Returns the current transaction. If there is no current transaction, it creates one and returns it.
Commits the current transaction, if any.
Rolls back the current transaction, if any.
Returns how many record ids exist.
Returns the index silo for this store. This method is not part of the record store interface.
Returns the max file size of any silo in bytes. This method is not part of the record store interface.
Returns a list of data silo objects where the data silo record size is 2**index position. This means that the beginning of the list will have undefs as there is a minimum silo size. This method is not part of the record store interface.
Returns the transaction silo for this store. This method is not part of the record store interface.
Returns how many record ids exist that have silo entries. This method is not part of the record store interface.
Returns the number of entries in the data silos.
Tries to detect the version of the Data::RecordStore in the given directory, if any.
Copyright (c) 2015-2019 Eric Wolf. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
1 POD Error
The following errors were encountered while parsing the POD:
You forgot a '=back' before '=head2'
To install Data::RecordStore, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::RecordStore
CPAN shell
perl -MCPAN -e shell install Data::RecordStore
For more information on module installation, please visit the detailed CPAN module installation guide.