Cache::Memcached::Queue - Create queues and save them on memcached!
Version 0.1.4
beta version
This works by taking advantage of Memcached infrastructure. In other words, the 'keys' will be strings that are names of indexes for some basic values that are sufficient to represent a queue structure. This basic values are: first, last, size and max_enq.
In order to have multiples queues in the same Memcached server, a prefix are added to every index on keys of Memcached. So, every key in memcached have the following struct on his name: <PREFIX>_<ID>_<INDEX_NUMBER OR NAME>
This module implements a simple scheme of a Queue.
use Cache::Memcached::Queue; my $q = Cache::Memcached::Queue->new( name => 'foo', #this is mandatory max_enq => 10, config_file => 'path_to_config/configfile.cfg', id => 1, serialize => 1, #if true, every value on enq will be serialized serializer => sub { return Data::Serializer->new( serializer => 'Storable', compress => 1, ) ); }, #RTFM Data::Serializer for more options... 'init' method is DEPRECATED! #loading queue $q->load();#load data from Memcached #common operations... $q->enq('duke'); #enqueue 'duke'. $q->enq('nuken'); #enqueue 'nuke' and this never expires on memcached $q->show; #show all items from queue. In this case: 'duke'(first element) and 'nuken'(last element). $q->deq; #deqeue 'duke'. $q->show; #show all items from queue. In this case: 'nuke'(first and last element from queue).
#alternative enq
$q->enq({ value => 'duke' }); #serialize just one value(serialize attribute must be false) $q->enq({ value => 'nuken' , serialize => 1});
Initialize object attributes and check attributes problems. If all is ok, returns the reference to object. Otherwise returns undef and trows an exception
Try to load the queue pointers from Memcached. If works, will return true. Otherwise will return false.
Try to make a 'enqueue' operation. That means tha 'last' index pointer will be readjusted to the next index. So the value can be recorded on Memcached.
The parameters are validated, and the valid parameters are:
Example: $enq({value => 'some_value'});
Example2: $enq({value => $some_object_or_structure, serialize => 1, });
If this work, the method will return true. Otherwise, will return false. You can change serialize parameters setting 'serializer' method.
Try to make a 'dequeue' operation on Queue. That means the first value of queue will be removed from queue, and the first index pointer from queue will be moved to the next index. If works, returns the 'dequeued' value, otherwise returns undef.
Try to show the content of queue(the data). This is made finding the 'first' and 'last' pointers, extracting the sequential index, and interate the queue with this indexes, making a 'get' operation from Memcached. If the value exists, it will be showed. If not, a exception will be thrown .
Dequeue everything! No parameters! Returns true, if it's all right! Otherwise, returns false/throws an exception
Try to save queue pointers on Memcached. The parameters came on arrayref, when each position of arrayref is a name of attribute that must be saved. This parameters are validated and then saved on memcached.
That makes the enqueuing process faster than save all parameters everytime, because the input operations on Memcached are reduced.
Ex: $q->save(['name','first']);
The valid parameters are:
If everything work well the method returns true. Otherwise returns false.
That method is a 'handler'. You can treat all values in another subroutine/static method, passing two parameters:
action: this parameter MUST be a CODE reference. Example:
#EX1: $q->iterate( sub { my ($index,$value,$params) = @_; #do something with this!!! } #EX2: $q->iterate( \&somesubroutine,$myparams) ; sub somesubroutine { my ($index,$value,$params) = @_; #do something cool! }
action_params: This can be a custom parameters. All yours! You need pass this as a ArrayRef!
So, by default, every index and values that are in your queue are passed together with your customized parameters. If you pass everything right, your 'action' will be performed! Otherwise, an exception will be throwed.
Andre Garcia Carneiro, <bang at cpan.org>
<bang at cpan.org>
Please report any bugs or feature requests to bug-cache-memcached-queue at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Cache-memcached-Queue. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-cache-memcached-queue at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Cache::Memcached::Queue
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Cache-memcached-Queue
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Cache-memcached-Queue
CPAN Ratings
http://cpanratings.perl.org/d/Cache-memcached-Queue
Search CPAN
http://search.cpan.org/dist/Cache-memcached-Queue/
Copyright 2013 Andre Garcia Carneiro.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install Cache::Memcached::Queue, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Cache::Memcached::Queue
CPAN shell
perl -MCPAN -e shell install Cache::Memcached::Queue
For more information on module installation, please visit the detailed CPAN module installation guide.