Experimental patch - ring buffers

Martijn van Zal mzal at brothersinart.com
Tue May 8 20:34:53 UTC 2007

The first use for this that springs to mind is an online member list. But
then there should be an possibility to save a key with the item, and a
function to remove an item from the list.

How do you handle it when an item on an rss feed is updated/republished and
you want it to appear on the top of list again?

I suspect the <exp> in the current ring command expires the entire ring,
maybe it would be cool to have a ring of variable length. Let's say I wan't
to store all members who visited the site during the last 5 minutes.
(Currently I'm doing queries on the user table in the database ordered by
lastVisitDate desc, there must me a better way of doing this)

While writing this I'm starting to doubt if memcached is the correct place
for this. It's quite an extension. How do other sites handle this? (online
member count, list of online members)

Martijn van Zal
Brothers in art

-----Original Message-----
From: memcached-bounces at lists.danga.com
[mailto:memcached-bounces at lists.danga.com] On Behalf Of Nathan Schmidt
Sent: zondag 6 mei 2007 11:00
To: memcached at lists.danga.com
Subject: Experimental patch - ring buffers

We've been kicking around the idea of ring buffers in memcached for a
week or two. The premise is that something like an RSS feed is
composed of some ordered list of n most recent items. Assembling this
via incr / multi_get wasn't providing the kind of interface we wanted,
and it's pretty easy to come up with some really interesting use cases
for memcache-style 'results are correct if they're not undef' using a
few new base commands.

Create a new ring
 ring <key> 0 <exp> <capacity>\r\n

Push a value onto the ring
 push <key> 0 <ignored> <length>\r\n<value\r\n

Get the empty-string-delimited concatenated values available on the ring
 rget <key>\r\n

These patches are basically a rough draft which pass my .t tests on
daemon and client side -- would love to hear feedback about the
operators and use cases other folks on the list can come up with.

(This was written at a Cinco De Mayo party
http://superhappydevhouse.org/SuperHappyDevHouse17, which may explain
the rough edges.)

Have fun,
-Nathan / PBwiki

More information about the memcached mailing list