dump datas from memcached to database

Steven Grimm sgrimm at facebook.com
Wed Feb 14 20:30:52 UTC 2007


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.

Also, your client will probably get confused if you have a key called 
"END" in your cache, but that's trivial to address.

-Steve


Randy Wigginton wrote:
> ... unless you want to add a few lines of code to your version of 
> memcached.
>
> 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.
>
>     if (strncmp(command, "keys", 4) == 0) {
>         extern item** getHashtable();
>         item **hashtable = getHashtable();
>         unsigned long i;
>         for (i=0; i<1<<16/*HASHPOWER*/; i++) {
>             item *it = hashtable[i];
> int outOfMem = 0;
>             while (it && !outOfMem) {
>                 char *key = ITEM_key(it);
>                 it = it->h_next;
> if (ntokens==3 && strstr(key, tokens[1].value)==NULL) {
> continue;
> }
> outOfMem = add_iov(c, key, strlen(key));
> outOfMem += add_iov(c, "\r\n", 2);
>             }
>         }
>         add_iov(c, "END\r\n", 5);
>
>
> conn_set_state(c, conn_write);
> c->write_and_go = conn_read;
> }
>
>
> On Feb 14, 2007, at 11:33 AM, Ask Bjørn Hansen wrote:
>
>>
>> On Feb 14, 2007, at 5:51 AM, Jm lists wrote:
>>
>>> Currently I want to use memcached as web's data cache.But I do need
>>> the cached datas.So I want to dump datas to mysql periodicly.Can you
>>> tell me how to dump all the datas stored in memcached?Thanks.
>>
>> You can't.
>>
>> http://www.socialtext.net/memcached/index.cgi?faq#can_i_iterate_the_items_of_the_memcached_server
>>
>>
>>  - ask
>>
>> -- 
>> http://develooper.com/ - http://askask.com/
>>
>>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.danga.com/pipermail/memcached/attachments/20070214/437c098c/attachment.html


More information about the memcached mailing list