ShardedKV::Storage::MySQL - MySQL storage backend for ShardedKV
version 0.12
use ShardedKV; use ShardedKV::Storage::MySQL; ... create ShardedKV... my $storage = ShardedKV::Storage::MySQL->new( ); ... put storage into ShardedKV... # values are array references $skv->set("foo", ["bar"]); my $value_ref = $skv->get("foo");
A ShardedKV storage backend that DBI and DBD::mysql to store data in a MySQL table.
ShardedKV
DBI
DBD::mysql
Implements the ShardedKV::Storage role.
ShardedKV::Storage
Each shard (== ShardedKV::Storage::MySQL object) is represented by a single table in some schema on some database server.
ShardedKV::Storage::MySQL
A callback that must be supplied at object creation time. The storage object will invoke the callback whenever it needs to get a NEW mysql database handle. This means when:
- first connecting - "MySQL server has gone away" => reconnect
The callback allows users to hook into the connection logic to implement things such as connection caching. If you do use connection caching, then do assert that the dbh is alive (eg. using $dbh->ping() before returning a cached connection.
$dbh->ping()
The name of the table that represents this shard. Must be supplied at object creation.
The name of the column to be used for the key. If ShardedKV::Storage::MySQL creates the shard table for you, then this column is also used as the primary key unless auto_increment_col_name is set (see below).
auto_increment_col_name
There can only be one key column.
Defaults to 'keystr'.
The MySQL type of the key column.
Defaults to 'VARBINARY(16) NOT NULL'.
The name of the column to be used for the auto-increment pimrary key. This is a virtually unused (by ShardedKV) column that, IF DEFINED, will be used as an auto-increment primary key. It is not the column used to fetch rows by, but rather facilitates faster insertion of new records by allowing append instead of insertion at random order within the PK tree.
If ShardedKV::Storage::MySQL creates the shard table for you, then this column is also used as the primary key.
There can only be one auto-increment key column.
Defaults to 'id'.
The MySQL type of the auto increment column.
Defaults to 'BIGINT UNSIGNED NOT NULL AUTO_INCREMENT'.
An array reference containing the names of all value columns in the shard table. Needs to contain at least one value column.
Defaults to [qw(val last_change)].
[qw(val last_change)]
An array reference containing the MySQL types of each value column given in value_col_names.
value_col_names
Defaults to: ['MEDIUMBLOB NOT NULL', 'TIMESTAMP NOT NULL'].
['MEDIUMBLOB NOT NULL', 'TIMESTAMP NOT NULL']
A string that is included verbatim after the PRIMARY KEY line of the CREATE TABLE IF NOT EXISTS statement that this class generates. This can be used to add additional indexes to the shard tables, such as indexes on the last modification (for expiration from the database, not handled by ShardedKV).
The maximum number of reconnect attempts that the storage object should perform if the MySQL server has gone away. Reconnects are done with exponential back-off (see below).
Defaults to 5.
The base interval for reconnection attempts. Do note that exponential reconnect back-off is used, so if the base reconnect_interval is 1 second, then the first reconnect attempt is done immediately, the second after one second, the third after two seconds, the fourth after four seconds, and so on.
Default: 1 second
Can also be fractional seconds.
This is the private attribute holding a MySQL database handle (which was created using the mysql_master_connector). Do not supply this at object creation.
mysql_master_connector
Steffen Mueller <smueller@cpan.org>
Nick Perez <nperez@cpan.org>
This software is copyright (c) 2012 by Steffen Mueller.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install ShardedKV, copy and paste the appropriate command in to your terminal.
cpanm
cpanm ShardedKV
CPAN shell
perl -MCPAN -e shell install ShardedKV
For more information on module installation, please visit the detailed CPAN module installation guide.