<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Be careful with that patch. No other client requests can be serviced
while that loop is running (which may be a long time if your cache is
large), but more critically, it doesn't lock down any of the cache
entries. While the results are getting streamed out to the client,
other clients can come in and change the cache, leading to garbage
output; for example, if a long key gets overwritten by a short one
before it's written, your list of "keys" will include the short key's
terminating null and the start of its data.<br>
<br>
Also, your client will probably get confused if you have a key called
"END" in your cache, but that's trivial to address.<br>
<br>
-Steve<br>
<br>
<br>
Randy Wigginton wrote:
<blockquote cite="midCC4C99DE-BCB0-4297-863C-E749FD8ED018@nobugz.com"
type="cite">... unless you want to add a few lines of code to your
version of memcached.
<div><br class="khtml-block-placeholder">
</div>
<div>Add this in, and send the command "keys <str>" and you
will get a list of all keys containing that string,or just send "keys"
and you'll get all.</div>
<div><br class="khtml-block-placeholder">
</div>
<div style="margin: 0px;"><font class="Apple-style-span" face="Monaco"
size="2"><span class="Apple-style-span" style="font-size: 10px;"> </span></font><font
class="Apple-style-span" color="#760f50" face="Monaco" size="2"><span
class="Apple-style-span" style="font-size: 10px;">if</span></font><font
class="Apple-style-span" face="Monaco" size="2"><span
class="Apple-style-span" style="font-size: 10px;"> (strncmp(command, </span></font><font
class="Apple-style-span" color="#891315" face="Monaco" size="2"><span
class="Apple-style-span" style="font-size: 10px;">"keys"</span></font><font
class="Apple-style-span" face="Monaco" size="2"><span
class="Apple-style-span" style="font-size: 10px;">, </span></font><font
class="Apple-style-span" color="#0000ff" face="Monaco" size="2"><span
class="Apple-style-span" style="font-size: 10px;">4</span></font><font
class="Apple-style-span" face="Monaco" size="2"><span
class="Apple-style-span" style="font-size: 10px;">) == </span></font><font
class="Apple-style-span" color="#0000ff" face="Monaco" size="2"><span
class="Apple-style-span" style="font-size: 10px;">0</span></font><font
class="Apple-style-span" face="Monaco" size="2"><span
class="Apple-style-span" style="font-size: 10px;">) {</span></font></div>
<div style="margin: 0px;"><font class="Apple-style-span" face="Monaco"
size="2"><span class="Apple-style-span" style="font-size: 10px;">
</span></font><font class="Apple-style-span" color="#760f50"
face="Monaco" size="2"><span class="Apple-style-span"
style="font-size: 10px;">extern</span></font><font
class="Apple-style-span" face="Monaco" size="2"><span
class="Apple-style-span" style="font-size: 10px;"> item**
getHashtable();</span></font></div>
<div style="margin: 0px;"><font class="Apple-style-span" face="Monaco"
size="2"><span class="Apple-style-span" style="font-size: 10px;">
</span></font><font class="Apple-style-span" face="Monaco" size="2"><span
class="Apple-style-span" style="font-size: 10px;">item **hashtable =
getHashtable();</span></font></div>
<div style="margin: 0px;"><font class="Apple-style-span" face="Monaco"
size="2"><span class="Apple-style-span" style="font-size: 10px;">
</span></font><font class="Apple-style-span" color="#760f50"
face="Monaco" size="2"><span class="Apple-style-span"
style="font-size: 10px;">unsigned</span></font><font
class="Apple-style-span" face="Monaco" size="2"><span
class="Apple-style-span" style="font-size: 10px;"> </span></font><font
class="Apple-style-span" color="#760f50" face="Monaco" size="2"><span
class="Apple-style-span" style="font-size: 10px;">long</span></font><font
class="Apple-style-span" face="Monaco" size="2"><span
class="Apple-style-span" style="font-size: 10px;"> i;</span></font></div>
<div style="margin: 0px;"><font class="Apple-style-span" face="Monaco"
size="2"><span class="Apple-style-span" style="font-size: 10px;">
</span></font><font class="Apple-style-span" color="#760f50"
face="Monaco" size="2"><span class="Apple-style-span"
style="font-size: 10px;">for</span></font><font
class="Apple-style-span" face="Monaco" size="2"><span
class="Apple-style-span" style="font-size: 10px;"> (i=</span></font><font
class="Apple-style-span" color="#0000ff" face="Monaco" size="2"><span
class="Apple-style-span" style="font-size: 10px;">0</span></font><font
class="Apple-style-span" face="Monaco" size="2"><span
class="Apple-style-span" style="font-size: 10px;">; i<</span></font><font
class="Apple-style-span" color="#0000ff" face="Monaco" size="2"><span
class="Apple-style-span" style="font-size: 10px;">1</span></font><font
class="Apple-style-span" face="Monaco" size="2"><span
class="Apple-style-span" style="font-size: 10px;"><<</span></font><font
class="Apple-style-span" color="#0000ff" face="Monaco" size="2"><span
class="Apple-style-span" style="font-size: 10px;">16</span></font><font
class="Apple-style-span" color="#236e25" face="Monaco" size="2"><span
class="Apple-style-span" style="font-size: 10px;">/*HASHPOWER*/</span></font><font
class="Apple-style-span" face="Monaco" size="2"><span
class="Apple-style-span" style="font-size: 10px;">; i++) {</span></font></div>
<div style="margin: 0px;"><font class="Apple-style-span" face="Monaco"
size="2"><span class="Apple-style-span" style="font-size: 10px;">
</span></font><font class="Apple-style-span" face="Monaco"
size="2"><span class="Apple-style-span" style="font-size: 10px;">item
*it = hashtable[i];</span></font></div>
<div style="margin: 0px;"><span class="Apple-tab-span"
style="white-space: pre;"> </span><span class="Apple-tab-span"
style="white-space: pre;"> </span><span class="Apple-tab-span"
style="white-space: pre;"> </span><font class="Apple-style-span"
color="#760f50" face="Monaco" size="2"><span class="Apple-style-span"
style="font-size: 10px;">int</span></font><font
class="Apple-style-span" face="Monaco" size="2"><span
class="Apple-style-span" style="font-size: 10px;"> outOfMem = </span></font><font
class="Apple-style-span" color="#0000ff" face="Monaco" size="2"><span
class="Apple-style-span" style="font-size: 10px;">0</span></font><font
class="Apple-style-span" face="Monaco" size="2"><span
class="Apple-style-span" style="font-size: 10px;">;</span></font></div>
<div style="margin: 0px;"><font class="Apple-style-span" face="Monaco"
size="2"><span class="Apple-style-span" style="font-size: 10px;">
</span></font><font class="Apple-style-span" color="#760f50"
face="Monaco" size="2"><span class="Apple-style-span"
style="font-size: 10px;">while</span></font><font
class="Apple-style-span" face="Monaco" size="2"><span
class="Apple-style-span" style="font-size: 10px;"> (it &&
!outOfMem) {</span></font></div>
<div style="margin: 0px;"><font class="Apple-style-span" face="Monaco"
size="2"><span class="Apple-style-span" style="font-size: 10px;">
</span></font><font class="Apple-style-span" color="#760f50"
face="Monaco" size="2"><span class="Apple-style-span"
style="font-size: 10px;">char</span></font><font
class="Apple-style-span" face="Monaco" size="2"><span
class="Apple-style-span" style="font-size: 10px;"> *key = ITEM_key(it);</span></font></div>
<div style="margin: 0px;"><font class="Apple-style-span" face="Monaco"
size="2"><span class="Apple-style-span" style="font-size: 10px;">
</span></font><font class="Apple-style-span" face="Monaco"
size="2"><span class="Apple-style-span" style="font-size: 10px;">it =
it->h_next;</span></font></div>
<div style="margin: 0px;"><span class="Apple-tab-span"
style="white-space: pre;"> </span><span class="Apple-tab-span"
style="white-space: pre;"> </span><span class="Apple-tab-span"
style="white-space: pre;"> </span><span class="Apple-tab-span"
style="white-space: pre;"> </span><font class="Apple-style-span"
color="#760f50" face="Monaco" size="2"><span class="Apple-style-span"
style="font-size: 10px;">if</span></font><font class="Apple-style-span"
face="Monaco" size="2"><span class="Apple-style-span"
style="font-size: 10px;"> (ntokens==</span></font><font
class="Apple-style-span" color="#0000ff" face="Monaco" size="2"><span
class="Apple-style-span" style="font-size: 10px;">3</span></font><font
class="Apple-style-span" face="Monaco" size="2"><span
class="Apple-style-span" style="font-size: 10px;"> &&
strstr(key, tokens[</span></font><font class="Apple-style-span"
color="#0000ff" face="Monaco" size="2"><span class="Apple-style-span"
style="font-size: 10px;">1</span></font><font class="Apple-style-span"
face="Monaco" size="2"><span class="Apple-style-span"
style="font-size: 10px;">].value)==</span></font><font
class="Apple-style-span" color="#760f50" face="Monaco" size="2"><span
class="Apple-style-span" style="font-size: 10px;">NULL</span></font><font
class="Apple-style-span" face="Monaco" size="2"><span
class="Apple-style-span" style="font-size: 10px;">) {</span></font></div>
<div style="margin: 0px;"><span class="Apple-tab-span"
style="white-space: pre;"> </span><span class="Apple-tab-span"
style="white-space: pre;"> </span><span class="Apple-tab-span"
style="white-space: pre;"> </span><span class="Apple-tab-span"
style="white-space: pre;"> </span><span class="Apple-tab-span"
style="white-space: pre;"> </span><font class="Apple-style-span"
color="#760f50" face="Monaco" size="2"><span class="Apple-style-span"
style="font-size: 10px;">continue</span></font><font
class="Apple-style-span" face="Monaco" size="2"><span
class="Apple-style-span" style="font-size: 10px;">;</span></font></div>
<div style="margin: 0px;"><span class="Apple-tab-span"
style="white-space: pre;"> </span><span class="Apple-tab-span"
style="white-space: pre;"> </span><span class="Apple-tab-span"
style="white-space: pre;"> </span><span class="Apple-tab-span"
style="white-space: pre;"> </span><font class="Apple-style-span"
face="Monaco" size="2"><span class="Apple-style-span"
style="font-size: 10px;">}</span></font></div>
<div style="margin: 0px;"><span class="Apple-tab-span"
style="white-space: pre;"> </span><span class="Apple-tab-span"
style="white-space: pre;"> </span><span class="Apple-tab-span"
style="white-space: pre;"> </span><span class="Apple-tab-span"
style="white-space: pre;"> </span><font class="Apple-style-span"
face="Monaco" size="2"><span class="Apple-style-span"
style="font-size: 10px;">outOfMem = add_iov(c, key, strlen(key));</span></font></div>
<div style="margin: 0px;"><span class="Apple-tab-span"
style="white-space: pre;"> </span><span class="Apple-tab-span"
style="white-space: pre;"> </span><span class="Apple-tab-span"
style="white-space: pre;"> </span><span class="Apple-tab-span"
style="white-space: pre;"> </span><font class="Apple-style-span"
face="Monaco" size="2"><span class="Apple-style-span"
style="font-size: 10px;">outOfMem += add_iov(c, </span></font><font
class="Apple-style-span" color="#891315" face="Monaco" size="2"><span
class="Apple-style-span" style="font-size: 10px;">"\r\n"</span></font><font
class="Apple-style-span" face="Monaco" size="2"><span
class="Apple-style-span" style="font-size: 10px;">, </span></font><font
class="Apple-style-span" color="#0000ff" face="Monaco" size="2"><span
class="Apple-style-span" style="font-size: 10px;">2</span></font><font
class="Apple-style-span" face="Monaco" size="2"><span
class="Apple-style-span" style="font-size: 10px;">);</span></font></div>
<div style="margin: 0px;"><font class="Apple-style-span" face="Monaco"
size="2"><span class="Apple-style-span" style="font-size: 10px;">
</span></font><font class="Apple-style-span" face="Monaco"
size="2"><span class="Apple-style-span" style="font-size: 10px;">}</span></font></div>
<div style="margin: 0px;"><font class="Apple-style-span" face="Monaco"
size="2"><span class="Apple-style-span" style="font-size: 10px;">
</span></font><font class="Apple-style-span" face="Monaco" size="2"><span
class="Apple-style-span" style="font-size: 10px;">}</span></font></div>
<div style="margin: 0px;"><font class="Apple-style-span" face="Monaco"
size="2"><span class="Apple-style-span" style="font-size: 10px;">
</span></font><font class="Apple-style-span" face="Monaco" size="2"><span
class="Apple-style-span" style="font-size: 10px;">add_iov(c, </span></font><font
class="Apple-style-span" color="#891315" face="Monaco" size="2"><span
class="Apple-style-span" style="font-size: 10px;">"END\r\n"</span></font><font
class="Apple-style-span" face="Monaco" size="2"><span
class="Apple-style-span" style="font-size: 10px;">, </span></font><font
class="Apple-style-span" color="#0000ff" face="Monaco" size="2"><span
class="Apple-style-span" style="font-size: 10px;">5</span></font><font
class="Apple-style-span" face="Monaco" size="2"><span
class="Apple-style-span" style="font-size: 10px;">);</span></font></div>
<p style="margin: 0px; min-height: 14px;"><span class="Apple-tab-span"
style="white-space: pre;"> </span><span class="Apple-tab-span"
style="white-space: pre;"> </span><br class="khtml-block-placeholder">
</p>
<div style="margin: 0px;"><span class="Apple-tab-span"
style="white-space: pre;"> </span><span class="Apple-tab-span"
style="white-space: pre;"> </span><font class="Apple-style-span"
face="Monaco" size="2"><span class="Apple-style-span"
style="font-size: 10px;">conn_set_state(c, conn_write);</span></font></div>
<div style="margin: 0px;"><span class="Apple-tab-span"
style="white-space: pre;"> </span><span class="Apple-tab-span"
style="white-space: pre;"> </span><font class="Apple-style-span"
face="Monaco" size="2"><span class="Apple-style-span"
style="font-size: 10px;">c->write_and_go = conn_read;</span></font></div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div><br class="khtml-block-placeholder">
</div>
<div><br>
<div>
<div>On Feb 14, 2007, at 11:33 AM, Ask Bjørn Hansen wrote:</div>
<br class="Apple-interchange-newline">
<blockquote type="cite">
<div style="margin: 0px; min-height: 14px;"><br>
</div>
<div style="margin: 0px;">On Feb 14, 2007, at 5:51 AM, Jm lists
wrote:</div>
<div style="margin: 0px; min-height: 14px;"><br>
</div>
<blockquote type="cite">
<div style="margin: 0px;">Currently I want to use memcached as
web's data cache.But I do need</div>
<div style="margin: 0px;">the cached datas.So I want to dump
datas to mysql periodicly.Can you</div>
<div style="margin: 0px;">tell me how to dump all the datas
stored in memcached?Thanks.</div>
</blockquote>
<div style="margin: 0px; min-height: 14px;"><br>
</div>
<div style="margin: 0px;">You can't.</div>
<div style="margin: 0px; min-height: 14px;"><br>
</div>
<div style="margin: 0px;"><a
href="http://www.socialtext.net/memcached/index.cgi?faq#can_i_iterate_the_items_of_the_memcached_server">http://www.socialtext.net/memcached/index.cgi?faq#can_i_iterate_the_items_of_the_memcached_server</a></div>
<div style="margin: 0px; min-height: 14px;"><br>
</div>
<div style="margin: 0px; min-height: 14px;"><br>
</div>
<div style="margin: 0px;"><span class="Apple-converted-space"> </span>-
ask</div>
<div style="margin: 0px; min-height: 14px;"><br>
</div>
<div style="margin: 0px;">--<span class="Apple-converted-space"> </span></div>
<div style="margin: 0px;"><a href="http://develooper.com">http://develooper.com</a>/
- <a href="http://askask.com">http://askask.com</a>/</div>
<div style="margin: 0px; min-height: 14px;"><br>
</div>
<div style="margin: 0px; min-height: 14px;"><br>
</div>
</blockquote>
</div>
<br>
</div>
</blockquote>
<br>
</body>
</html>