Skip to content

Instantly share code, notes, and snippets.

@lericson
Created December 14, 2009 13:15
Show Gist options
  • Save lericson/256037 to your computer and use it in GitHub Desktop.
Save lericson/256037 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <libmemcached/memcached.h>
/**
* Test to show that the expiry time of memcached_delete does nothing at all.
* gcc -o memcached_delete_test memcached_delete_test.c -lmemcached
*/
int main(int argc, char **argv) {
memcached_st *mc;
memcached_server_st *mc_svr;
memcached_return get_rc;
size_t valsz;
uint32_t flags;
char *val;
mc = memcached_create(NULL);
mc_svr = memcached_servers_parse("127.0.0.1");
memcached_server_push(mc, mc_svr);
printf("set = %d\n", memcached_set(mc, "foo", 3, "bar", 3, 0, 0));
val = memcached_get(mc, "foo", 3, &valsz, &flags, &get_rc);
if (get_rc == MEMCACHED_SUCCESS) {
printf("get (%u bytes, flags = %u) = %s\n", (unsigned int)valsz, flags, val);
} else {
printf("get failed, rc = %d\n", get_rc);
}
// an hour's expiration!
printf("delete = %d\n", memcached_delete(mc, "foo", 3, 3600));
// the key should still exist, amirite
val = memcached_get(mc, "foo", 3, &valsz, &flags, &get_rc);
if (get_rc == MEMCACHED_SUCCESS) {
printf("get (%u bytes, flags = %u) = %s\n", (unsigned int)valsz, flags, val);
} else {
printf("get failed, rc = %d\n", get_rc);
if (get_rc == MEMCACHED_NOTFOUND) {
printf(" -> not found\n");
}
}
memcached_free(mc);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment