Tyler MacDonald

NAME

File::Lock::Multi::MySQL - Lock multiple strings in MySQL to emulate taking out multiple locks on a single string.

DESCRIPTION

This module uses MySQL's GET_LOCK() function on multiple strings to emulate taking out multiple locks on a single string.

It is very important that database handles are not used to take out any other locks, for your resource or for any other resource! From the MySQL documentation:

"If you have a lock obtained with GET_LOCK(), it is released when you execute RELEASE_LOCK(), execute a new GET_LOCK(), or your connection terminates (either normally or abnormally)."

See the dbh option below for more details.

OPTIONS

In addition to the standard File::Lock::Multi options, the following additional options are available when calling new():

format

A sprintf() format string used to come up with the individual lockfile names. sprintf() will be passed the file's path and the lock number as the first and second parameters. (Default: "%s.%i").

dbh

Either a database handle, or a "factory" (code reference which returns a new database handle each time it is invoked). Because each MySQL lock is unique to a database handle, and each database handle may only have one lock, you almost always need a fresh database handle to hold onto a lock. Example:

  my $lock = File::Lock::Multi::MySQL->new(
    file => "limited.resource", limit => 5,
    dbh => sub { DBI->connect("DBI:mysql:", $user, $password) }
  );

LICENSE

Copyright 2010 Tyler "Crackerjack" MacDonald <japh@crackerjack.net>

This is free software; You may distribute it under the same terms as perl itself.

SEE ALSO

File::Lock::Multi, "flock" in perlfunc