-
-
24 Feb 2011 14:33:50 UTC
- Distribution: Memcached-Client
- Source (raw)
- Browse (raw)
- Changes
- How to Contribute
- Issues (4)
- Testers (2510 / 304 / 0)
- Kwalitee
Bus factor: 0- 49.41% Coverage
- License: perl_5
- Activity
24 month- Tools
- Download (36.53KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
How it all fits together
Memcached::Client
is the central hubDuring the loading of the
Memcached::Client::Request
module, we insert a bunch of methods into theMemcached::Client
namespace that are really just curried functions that create instances of the variousRequest
classes.When you make a request, things go like this (using
get
as an example):$client->get
calls the anonymous subroutine that was returned whenM::C::Request::Get->generate
(which, due to inheritance, isM::C::Request->generate
) was called.The anonymous sub expects the
Memcached::Client
object as its first parameter, and uses the remainder as arguments for its command. The command that was curried in when the subroutine was created is used to construct a hashref that will become the request object.The last argument to the subroutine is examined. If it was something we can use as a callback (either a
CODE
reference or anAnyEvent::CondVar
, it is stored, and we assume that somewhere else in the calling program there is a statement waiting on anAnyEvent::CondVar
---so we will not be obliged to do so ourselves in order for the request to get processed.Otherwise we create the aforementioned
AnyEvent::CondVar
and mark ourselves as needing to wait.We then hand the rest of our arguments to the
process
routine, which is supposed to verify the object's arguments and returns one or moreRequest
objects to be submitted to the appropriate server(s). If it does not return any objects, it is assumed that there was a problem with the submission, and an empty result is returned.The
__submit
routine in theMemcached::Client
module is handed the request objects to process.__submit
iterates through the objects, looking at whether they include akey
member. If they do, the key is processed to determine what server it should be directed at, checked for validity, and if it's OK, it is submitted to the appropriate server's queue using the connection'senqueue
method.If the object doesn't have a
key
, it is assumed to be a broadcast message destined for all servers, and__submit
uses the object'sserver
factory to create subrequests for each server.The connection object works its way through its queue (if there's nothing else in the queue when you add a new request, it will be handled immediately, but that's just an optimization) and comes to your request object.
It gets the name of the protocol function from your request object, and invokes that method on the protocol object, passing it a reference to itself and your request.
The protocol method constructs the command from the data members of the request object and submits it to the connection object.
When the response to the request has been recieved the protocol object decodes it and sends the result back to the request object using its
result
method, and notifies the connection that it's done with the request by callingcomplete
.Module Install Instructions
To install Memcached::Client, copy and paste the appropriate command in to your terminal.
cpanm Memcached::Client
perl -MCPAN -e shell install Memcached::Client
For more information on module installation, please visit the detailed CPAN module installation guide.