1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
#include "apr_memcache.h"
#define PORT 11211
#define HOST "localhost"
#define out(funa) fprintf(stdout, funa " : %d %s\n", rv, apr_strerror(rv, buf, sizeof buf));
int main( int argc, char**argv )
{
apr_pool_t *p;
char buf[120];
apr_status_t rv;
apr_memcache_t *memcache;
apr_memcache_server_t *server;
apr_memcache_stats_t* stats;
apr_size_t len;
char *result;
apr_uint32_t new;
apr_uint32_t until = 600;
apr_initialize();
atexit(apr_terminate);
apr_pool_create(&p, NULL);
rv = apr_memcache_create(p, 10, 0, &memcache);
out("_create")
rv = apr_memcache_server_create(p, HOST, PORT, 0, 1, 1, 60, &server);
out("_create_server")
rv = apr_memcache_add_server(memcache, server);
out("_add_server")
rv = apr_memcache_version(server, p, &result);
out("_server_version")
printf("\tresult: '%s'\n", result);
rv = apr_memcache_stats(server, p, &stats);
out("_server_stats")
printf("\tpid '%d' version: '%s'\n", stats->pid, stats->version);
rv = apr_memcache_set(memcache, "foo", "bar123", sizeof("bar123")-1, until, 0);
out("_set")
rv = apr_memcache_getp(memcache, p, "foo", &result, &len, NULL);
out("_get")
printf("\tresult: '%s' len: %d\n", result, len);
rv = apr_memcache_delete(memcache, "foo", 100);
out("_delete")
/* the next three should fail, since foo was just deleted */
rv = apr_memcache_getp(memcache, p, "foo", &result, &len, NULL);
out("_get_empty")
rv = apr_memcache_replace(memcache, "foo", "bar123", sizeof("bar123")-1, until, 0);
out("_replace_non_exist")
rv = apr_memcache_getp(memcache, p, "foo", &result, &len, NULL);
out("_get_was_not_replaced")
rv = apr_memcache_set(memcache, "foo", "1", sizeof("1")-1, until, 0);
out("_set")
rv = apr_memcache_getp(memcache, p, "foo", &result, &len, NULL);
out("_get")
printf("\tresult: '%s' len: %d\n", result, len);
rv = apr_memcache_incr(memcache, "foo", 5, NULL);
out("_incr")
rv = apr_memcache_getp(memcache, p, "foo", &result, &len, NULL);
out("_get")
printf("\tresult: '%s' len: %d\n", result, len);
rv = apr_memcache_decr(memcache, "foo", 2, NULL);
out("_decr")
rv = apr_memcache_getp(memcache, p, "foo", &result, &len, NULL);
out("_get")
printf("\tresult: '%s' len: %d\n", result, len);
rv = apr_memcache_incr(memcache, "foo", -2, &new);
out("_incr")
rv = apr_memcache_getp(memcache, p, "foo", &result, &len, NULL);
out("_get")
printf("\tresult: '%s'='%d' len: %d\n", result, new, len);
return rv;
}
|