Skip to content
Snippets Groups Projects
Commit 0bc311f5 authored by Dmitriy A. Gerasimov's avatar Dmitriy A. Gerasimov
Browse files
parents f47cc638 e243e0e3
No related branches found
No related tags found
No related merge requests found
......@@ -21,7 +21,7 @@ file(GLOB CORE_SERVER_HEADERS *.h)
add_library(${PROJECT_NAME} STATIC ${CORE_SERVER_SOURCES} ${CORE_SERVER_HEADERS})
target_link_libraries(${PROJECT_NAME} pthread ev dap_crypto)
target_link_libraries(${PROJECT_NAME} pthread ev memcached dap_crypto)
target_include_directories(${PROJECT_NAME} INTERFACE .)
set(${PROJECT_NAME}_DEFINITIONS CACHE INTERNAL "${PROJECT_NAME}: Definitions" FORCE)
......
#include "dap_memcached.h"
#include <libmemcached/memcached.h>
static memcached_st *_memc;
static time_t _expiration;
static bool _is_module_enable = false;
int dap_memcached_init(const char *server_host, uint16_t port, time_t expiration)
{
_expiration = expiration;
memcached_return rc;
memcached_server_st *servers = NULL;
char *test_key = "test_key";
char *test_value = "test_value";
_memc = memcached_create(NULL);
servers= memcached_server_list_append(servers, server_host, port, &rc);
rc= memcached_server_push(_memc, servers);
if (rc != MEMCACHED_SUCCESS) {
log_it(L_ERROR, "Couldn't add server: %s", memcached_strerror(_memc, rc));
return -1;
}
if(dap_memcache_put(test_key, test_value, strlen(test_value)) != true) {
return -2;
}
if(_expiration == 0) {
log_it(L_WARNING, "Init memcached module without expiration value");
}
_is_module_enable = true;
return 0;
}
bool dap_memcache_is_enable()
{
return _is_module_enable;
}
bool dap_memcache_put(const char* key, void *value, size_t value_size)
{
memcached_return rc;
rc = memcached_set(_memc, key, strlen(key), value, value_size, _expiration, (uint32_t)0);
if (rc != MEMCACHED_SUCCESS) {
log_it(L_ERROR, "%s", memcached_strerror(_memc, rc));
return false;
}
return true;
}
bool dap_memcache_get(const char* key, size_t * value_size, void ** result)
{
memcached_return rc;
*result = memcached_get(_memc, key, strlen(key), value_size, NULL, &rc);
return rc == MEMCACHED_SUCCESS;
}
/**
* @brief dap_memcached_deinit
*/
void dap_memcached_deinit()
{
_is_module_enable = false;
}
#pragma once
#undef LOG_TAG
#define LOG_TAG "dap_memcached"
#include <stdint.h>
#include <stdbool.h>
#include "dap_common.h"
/**
* @brief dap_memcached_init
* @param server_host
* @param port
* @param expiration key value in mamcached store. If zero - expiration disable
* @return
*/
int dap_memcached_init(const char *server_host, uint16_t port, time_t expiration);
/**
* @brief is_dap_memcache_enable
* @return
*/
bool dap_memcache_is_enable(void);
/**
* @brief dap_memcached_deinit
*/
void dap_memcached_deinit(void);
/**
* @brief dap_memcache_put
* @param key
* @param value
* @param value_size
* @return
*/
bool dap_memcache_put(const char* key, void *value, size_t value_size);
/**
* @brief dap_memcache_get
* @param key
* @return true if key found
*/
bool dap_memcache_get(const char* key, size_t * value_size, void ** result);
Subproject commit c30973bfe5a3d2eb4201af535cc559b326e8b175
Subproject commit 0255887bbca085979fcd26e70a8b5131a428c36d
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment