Daniel Rench

Web application development : Servers : Networks : E-Mail : DNS : Databases : Programming for hire

previous : contact : linkedin : code : links : pictures : facebook : twitter : next

Hash::Server: a (mostly) memcached-compatible network interface to Perl hashes

You can download Hash::Server here until I get it on the CPAN (after a decade with Perl as my primary programming language I've finally signed up for a PAUSE account, so it could happen). Maybe you'll find this useful.

April 29, 2009 update: this code is now on github.



SYNOPSIS

        use Hash::Server ();
        use DB_File (); # for example
        tie(my %db, 'DB_File', './hash.db') or die $!;
        Hash::Server->new({ hash => \%db, localport => 11211 })->Bind();


DESCRIPTION

While memcached's original purpose was as a networked Memoize, it's also a simple way to distribute key/value hashes. But the official memcached (as the name implies) stores its data in memory, and is temporary. Given there are so many memcached clients for so many languages, it seemed a shame that there were no other ``backing stores'' available.

This module allows you to distribute any Perl hash structure you like with the memcached protocol. Typical use would probably involve a tied hash (as in the DB_File example above); if you want to serve a straight untied hash, you might as well use the real memcached, especially given the limitations of this module...


CAVEATS

This module is not a complete implementation of the memcached protocol.

  • It ignores any expiration times you provide; values are always assumed permanent.
  • It ignores any incoming ``flag'' value you provide when storing, and returns 0 by (default) when getting. Changing $Hash::Server::DEFAULT_FLAG to another value may help you on the client-side to differentiate a nonexistent key due to a server outage, or a nonexistent key because the key just does not exist.
  • With standard memcached (flags field aside, which you can't get with the Perl clients anyway), there is no difference between a nonexistent key and a down server. For pure caching, that's fine, but your application may need to know the difference. You can set $Hash::Server::UNDEFINED_KEY to some value that makes sense to you, such as 0 or q{} (empty string) and test for that, knowing that if your client returns 'undef', it means it didn't get that answer from the server.
  • The ``stats'' command is unimplemented.


SEE ALSO

http://code.sixapart.com/svn/memcached/trunk/server/doc/protocol.txt


AUTHOR

Daniel Rench, <citric@cubicone.tmetic.com>


COPYRIGHT AND LICENSE

Copyright (C) 2007 by Daniel Rench

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.7 or, at your option, any later version of Perl 5 you may have available.

<< It might help somebody: Flash 9 with Firefox on a Mac | Home | Portfolio | Contact | EHANN: Javascript (and Perl and Ruby) Bloom Filters >>