<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>"Iteratable" keys in memcache?</TITLE>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2900.2668" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=671403515-02082005>Oh duh...are incr and decr operations atomic?
</SPAN></FONT></DIV><BR>
<BLOCKQUOTE dir=ltr
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px">
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> memcached-bounces@lists.danga.com
[mailto:memcached-bounces@lists.danga.com] <B>On Behalf Of </B>Christopher
Gillett<BR><B>Sent:</B> Tuesday, August 02, 2005 11:18 AM<BR><B>To:</B>
memcached@lists.danga.com<BR><B>Subject:</B> "Iteratable" keys in
memcache?<BR></FONT><BR></DIV>
<DIV></DIV><!-- Converted from text/rtf format --><BR>
<P><FONT face=Arial size=2>I'm building an application that needs to run
quickly. My plan is to use memcache to store state data…since the state
data can be recreated if needed, and since the application needs to run
quickly, I am planning on not using a database as a backing store. I'm
looking for some way to create unique keys that I can use to iterate over the
cache entries - much like a row number or an auto-increment id in a
database. Is there any functionality in memcache or elsewhere that I can
use to create guarenteed unique keys that of an iteratable form? I don't
see global or cache-entry specific lock()/unlock() in memcache, so I'm
wondering if there's a way to solve this within memcache.</FONT></P>
<P><FONT face=Arial size=2>There will be many resources trying to create cache
entries while my application is active, so I'm looking for sort of
guarenteed atomic operation. Something like:</FONT></P>
<P>
<FONT face=Arial size=2>value =
cache.get("the next row id")</FONT>
<BR>
<FONT face=Arial size=2>value
+=1</FONT> <BR>
<FONT face=Arial
size=2>cache.set("the next row id", value)</FONT> </P>
<P><FONT face=Arial size=2>won't work because another running instance could
produce the same value at the same time.</FONT> </P>
<P><FONT face=Arial size=2>If there's no support for something like this, is
there any interest in an "atomic increment" function for memcache? I'd
be willing to dig into it if there is a broader need.</FONT></P>
<P><FONT face=Arial size=2>Any thoughts?</FONT> </P>
<P><FONT face=Arial size=2>Thanks,</FONT> <BR><FONT face=Arial
size=2>Chris</FONT> </P>
<P><FONT face=Arial size=2>---</FONT> <BR><FONT face=Arial size=2>Christopher
Gillett</FONT> <BR><FONT face=Arial size=2>Compete, Inc.</FONT>
</P></BLOCKQUOTE></BODY></HTML>