I want to store an entire MYSQL result in memcached via libmemcached in C. Is this possible or do I have to store each row element in memcached separately?
-
I just want note that instead of using a serialization library I created my own abstraction layer so that the rest of the program uses that instead of memcache / sql specific data structures. This isn't exactly the easiest way of doing it but it caters well to my project. – Slava Markeyev Feb 27 '12 at 05:20
2 Answers
If your result set will always be smaller than 1mb then it's possible to save the entire result set. Otherwise (if your result might be greater than 1mb), you'll have to find another solution. If storing each row in memcache works for you, then that's probably a fine solution.
The 1mb limit for value size is a hard limit coded into memcache. The only way around it is to change the limit in the source code and recompile memcache.
See http://groups.google.com/group/memcached/browse_thread/thread/d32434ce77131e48 for some discussion.
(Note: this is all assuming it is possible to serialize your results into a string; if you can't do that, then you can't store individual rows either, because an array is not a limiting factor on serialization ability.)
Here's a post discussing how to Serialize Data Structures in C
-
I'm unsure of what function to use to store the entire result set since it seems the set functions in the library only takes char* as input. – Slava Markeyev Feb 18 '12 at 00:27
-
@SlavaMarkeyev, yes. You can only store the result set if it is serializable as as string. How you decide to serialize it is application-specific. – Ben Lee Feb 18 '12 at 00:28
-
@SlavaMarkeyev, I added a note about serialization to my answer. Anyway, if your individual rows can be serialized, then it's definitely possible for your entire result set to be serialized. – Ben Lee Feb 18 '12 at 00:29
-
@SlavaMarkeyev, but to my knowledge if the result set you have is coming from MySQL, then it definitely *is* serializable. – Ben Lee Feb 18 '12 at 00:32
-
@SlavaMarkeyev, I added a link in my answer to a post that might help you; it's about serialization libraries in C – Ben Lee Feb 18 '12 at 00:34
Definitely you can do it. You have to find a way to pack all the responses together. It doesn't come to me easily why you would want to do that, anyway.

- 28,636
- 4
- 59
- 87