Introduction to cross-platform C + + memcached client memcacheclient

Source: Internet
Author: User
Tags md5 memcached sha1
1. IntroductionC + + memcached client libmemcached, but it is not compatible with Windows VC + + compiler. In Google code's memcached wiki about Memcacheclient's profile "Memcacheclient--cross-platform, but primary focus on Windows (last U Pdated in 2008) ". The Memcacheclient project page found that the project was updated in 2012 and is worth trial.
2. Environment & Software PreparationMemcacheclient-2.0:http://code.jellycan.com/files/memcacheclient-2.0.zip
3. Installation && configuration
WindowsWindows, you know. Unzip, double-click SLn to build the solution. It's OK to see the MemCacheClient.lib generated under the Debug directory. VS configuration of VC directory can be.
LinuxLinux, decompression, make can. However, the original Makefile only generate memcacheclienttest such a strange thing, that is, to generate a test program, did not generate library files. You can replace the following Makefile to generate a static library file.
cc=g++
ar=ar
arflags=-rcs
cflags=-wall
cppflags=-wall

LIBS=-LRT MEMCACHECLIENT.O readwritebuffer.o socket.o matilda.o sha1.o objs=memcacheclienttest.o

READWRITEBUFFER.O SOCKET.O matilda.o sha1.o all

: $ (OBJS)
	$ (CC)-O memcacheclienttest $ (OBJS) $ (LIBS)
	$ (AR) $ (arflags) Libmemcacheclient.a $ (LIB_OBJS)
	mkdir Lib
	mv libmemcacheclient.a Lib clean 

:
	rm-rf Core *.O Lib Memcacheclienttest

install:
	@echo No install provided. Include the source files in your project.

Memcacheclienttest.o:memcacheclienttest.cpp
memcacheclient.o:memcacheclient.cpp MemCacheClient.h
Readwritebuffer.o:readwritebuffer.cpp ReadWriteBuffer.h
md5.o:md5.c md5.h
LIBMEMCACHECLIENT.A can be generated in the Lib directory. Configure the environment variables.
4, testing
MemcacheClientTest.cpp:
#include <iostream> #ifdef WIN32 # include <winsock2.h> # pragma comment (lib, "Ws2_32.lib") #endif #include  <MemCacheClient.h>//#include <ReadWriteBuffer.h> int main (int argc, char *argv[]) {#ifdef WIN32 wsadata
    Wsadata;
    int rc = WSAStartup (Makeword (2,0), &wsadata);
        if (RC!= 0) {std::cout << "Failed to start Winsock." << Std::endl;
    return 1;

    } #endif memcacheclient *pmemcacheclient = new Memcacheclient; try {if (Pmemcacheclient->addserver ("192.168.21.23:22133")) {std::cout << "Add
        Server 192.168.21.23:22133 successful! "<< Std::endl;
        } memcacheclient::memrequest csetreqtest;
        Csetreqtest.mkey = "Testset";
        CSetReqTest.mData.WriteBytes ("Testset", sizeof ("Testset")); if (Pmemcacheclient->set (csetreqtest) = = 1) {std::cout << "Set testset->testset Successful ! "<< STd::endl;
        } memcacheclient::memrequest cgetreqtest;
        Cgetreqtest.mkey = "Testset"; if (Pmemcacheclient->get (cgetreqtest) = = 1) {std::cout << "get testset->testset Successful
        ! "<< Std::endl;
        } std::string Sresult (CGetReqTest.mData.GetReadBuffer (), cGetReqTest.mData.GetReadSize ());
    Std::cout << "Get:" << sresult << Std::endl;
    catch (Std::exception &e) {std::cerr << "exception:" << e.what () << Std::endl;

    } Delete pmemcacheclient;
return 0;

 };

Makefile:
cc=g++
cppflags=-wall-i$ (memcacheclient_root)
ldflags=-l$ (memcacheclient_root)/LIB-LMEMCACHECLIENT-LRT

OBJS=MEMCACHECLIENTTEST.O All

: $ (OBJS)
	$ (CC)-O memcacheclienttest $ (OBJS) $ (ldflags)

Memcacheclienttest.o:memcacheclienttest.cpp
	$ (CC) $ (cppflags)-C MemcacheClientTest.cpp Clean

: 
	RM-RF * . O Memcacheclienttest
Complete test engineering documents, see Memcacheclienttest.zip
SummaryIt's really hard to find memcached clients that are more convenient than memcacheclient (or maybe I'm ignorant ^_^) under Windows. Its interface looks similar to the old version of the libmemcached, the interface is relatively simple. However, the use of people or less, not in-depth study of the source code, or not in the key projects to use (ladder, sin ah). Anyway I was encapsulating a layer, Windows based on the memcacheclient,linux under the libmemcached.

Edit Record v 1.0.1 add complete test project file Download Address v 1.0 First Draft

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.