first stab at a C API
21 Aug 2003 22:36:23 -0700
This is super-basic: only connects to localhost, only has get and set.
The plan is this:
- buffer reads (readline() should do a full read and scan for newlines)
- don't buffer writes (the kernel buffers it anyway / TCP_CORK)
I'm not sure how the functions should look. I'll attach my header.
I figure that eventually, we'd like something like get() to:
- support printf-style formatting: get("user:%d", userid)
- support hash keys: should these be ints or char* and len?
- support some sort of serialization/deserialization callbacks(?)
but that produces a Windowsean function with 10 arguments.
Also, I took a shot at allowing weighting without using an array of
buckets. Instead, we use the linked list of servers, but that means
this is O(n) * number of time we retry to find a live server.
If anyone wants to comment on my C code, I'd appreciate it.
You can read it at http://bunny.darktech.org/svn/memcache-c , and you
can check it out with this subversion command:
svn checkout http://bunny.darktech.org/svn/memcache-c mydestdir
Content-Disposition: attachment; filename=memcache.h
Content-Type: text/x-c-header; name=memcache.h; charset=UTF-8
#include <time.h> /* time_t */
typedef struct _MemCacheClient MemCacheClient;
void* memcachec_get(MemCacheClient *mc, char *key, int *rlen);
int memcachec_set(MemCacheClient *mc, char *key,
void *val, int len, time_t exp);
#endif /* MEMCACHE_H */