Created
August 23, 2017 11:26
-
-
Save egroeper/fd998c8089ffd2ba863c75f503418dcb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include <unistd.h> | |
//#include <libmemcached/memcached.h> | |
#include <libmemcached-1.0/memcached.h> | |
#include <libmemcachedutil-1.0/pool.h> | |
int main() { | |
const char *config_string= "--SERVER=192.168.1.2 --SERVER=192.168.1.3 --POOL-MIN=10 --POOL-MAX=100 --DISTRIBUTION=consistent --HASH=MD5 --REMOVE-FAILED-SERVERS=1"; | |
char *key= "de.hu-berlin.cms_our_test_key"; | |
char *value= "foobar"; | |
char *result; | |
size_t res_len; | |
uint32_t flags; | |
memcached_return_t rc; | |
memcached_st *memc; | |
memcached_pool_st* pool= memcached_pool(config_string, strlen(config_string)); | |
memcached_pool_behavior_set(pool, MEMCACHED_BEHAVIOR_KETAMA, 1); | |
memcached_pool_behavior_set(pool, MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS, 1); | |
memcached_pool_behavior_set(pool, MEMCACHED_BEHAVIOR_DEAD_TIMEOUT, 0); | |
while (true) { | |
memc= memcached_pool_fetch(pool, 0, &rc); | |
rc= memcached_set(memc, key, strlen(key), value, strlen(value), (time_t)0, (uint32_t)0); | |
if (rc != MEMCACHED_SUCCESS) { | |
printf("set error: %d, %s\n", rc, memcached_last_error_message(memc)); | |
} | |
result = memcached_get(memc, key, strlen(key), &res_len, &flags, &rc); | |
if (rc != MEMCACHED_SUCCESS) { | |
printf("get error: %d, %s\n", rc, memcached_last_error_message(memc)); | |
} else { | |
printf("get success\n"); | |
} | |
free(result); | |
/* | |
Release the memc_ptr that was pulled from the pool | |
*/ | |
memcached_pool_release(pool, memc); | |
sleep(1); | |
} | |
/* | |
Destroy the pool. | |
*/ | |
memcached_pool_destroy(pool); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment