- CLASS METHODS
- OBJECT METHODS
- BUGS AND LIMITATIONS
- LICENSE AND COPYRIGHT
- DISCLAIMER OF WARRANTY
MongoDBx::KeyValue - Use MongoDB as if it were a key-value store.
use MongoDBx::KeyValue; my $mkv = MongoDBx::KeyValue->new(kvdb => 'my_key_value_database', %opts); # 'kvdb' is required, other options are passed to MongoDB::Connection->new() $mkv->set('cache', 'index.html', '<html><head><title>Index</title></head><body>Index</body></html>'); my $index = $mkv->get('cache', 'index.html'); print $index; # prints '<html><head><title>Index</title></head><body>Index</body></html>'
MongoDBx::KeyValue is a very simple module for easy usage of MongoDB as a key-value store (similar to Redis, Riak or Memcached).
The interface is very simple: you set the values of keys and get the values of keys. Every key-value pair is stored in a bucket, which is really just a MongoDB collection (the "bucket" terminology is used merely for resemblance with other key-value stores), so the same key can exist, with possibly different values, in multiple buckets.
To get the value of a key, just pass the
get() method the name of the bucket and the key. If it is not found,
undef is returned. To set the value for a key, just provide the
set() method with the name of the bucket, the key and the value. If the key already exists in the bucket, its value will be replaced.
The value for a key can be anything that MongoDB supports, including simple scalars (strings, numbers, etc.), hash or array references, and whatever else MongoDB natively supports such as DateTime objects. While no checking is made for keys, you probably should only use scalars for them.
Every key-value pair is stored in the database as a document with two attributes: "_id", which holds the key; and "value", which holds the value.
Creates a new instance of this module and connects to the MongoDB server. The only required option is 'kvdb', which should hold the name of the database to use for the key-value store. All other options will be passed to
MongoDB::Connection->new(), so take a look at "ATTRIBUTES" in MongoDB::Connection for a list of all supported options.
Attempts to find the value for the key
$key in the bucket named
undef if not found.
Sets the value for the key named
$key inside the bucket named
$bucket. If the key already exists, its value will be replaced with the new one.
Returns the MongoDB::Database object of the key-value store.
All this really does is return a MongoDB::Collection object for the collection named
$bucket_name. Use it if you need MongoDB collection objects for some reason.
This module generates the following errors:
"You must provide the name of the key-value database to use (as parameter 'kvdb')."
This error will be issued by the
new()method if you don't provide it with the 'kvdb' parameter, which should hold the name of the database to use as the key-value store.
This module only depends on MongoDB.
No bugs have been reported.
Please report any bugs or feature requests to
bug-MongoDBx-KeyValue@rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MongoDBx-KeyValue.
Ido Perlmuter <ido at ido50 dot net>
Copyright (c) 2011, Ido Perlmuter
ido at ido50 dot net.
The full text of the license can be found in the LICENSE file included with this module.
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.