决定用redis做为cache服务器,要求其服务端和客户端都支持跨平台win和linux
但我发现redis(/做者)对windows态度极差,不考虑,不支持
微软公司的闲人们主动靠过去,推出win版。这么一来,redis的
服务端linux版和win版都有了,我就在个人win7上部署了一个win版的redis服务器作调试用,余不累赘,之后另起课题讨论
客户端用hiredis,其
win版(/日后简称winV)在
https://github.com/texnician/hiredis-win32
原版master(日后简称masterV)在
https://github.com/redis/hiredislinux
下载来之,解开,对比它两:
一、winV的examples.h/c直接和核心代码混在根目录上,组织乱
二、winV全面用预编译宏_WIN32来区分平台代码,另辟代码分别实现各个接口,网络方面的改动最大
三、winV除了新辟的代码,其它的
3.1 winV删除了keepalive的接口
3.2 其它的跟masterV区别不大,有些许改动git
确保能编译winV
一、新建目录examples,把examples.h/c全赶进去
二、先无论winV其新辟的代码,把其它的改动,从masterV merge到 winV里
三、创建vc工程hiredis4win.vcxproj/sln(/下载包里没有),把除了test/example以外的全部代码文件加入进去
四、编译hiredis4win.vcxproj,发现一堆问题:
4.1 微软的c编译器(/c89)不支持c99,而hiredis直接在c99标准上作的,这引发n多的问题:
4.1.1 结构体的初始化的点语法
4.1.2 c89不支持关键字bool
4.1.3 c89的变量声明必须置于做用域的最前头
4.1.4 c89不支持inline
4.2 linux和win的平台差别
4.2.1 win下没有函数
va_copy
gettimeofday
4.2.2 linux以下函数
snprintf
strtoll(x,y,z)
strtoull(x,y,z)
vsnprintf
strcasecmp
strncasecmp
在win下相应有一样签名函数
_snprintf
_strtoi64(x,y,z)
_strtoui64(x,y,z)
_vsnprintf
_stricmp
strnicmp
4.4.3 ...github
确保能连接hiredis的test
一、创建hiredis_test.vcxproj/sln,把test.c加入该工程
二、确保hiredis_test.vcxproj能编译连接redis
运行调试hiredis_test
一、在本地机上运行redis的win版
二、运行过程当中,shift+F5中断之,结果下次运行的时候,总是报错:
"Database #9 is not empty, test can not continue\n"
打开redis服务器控制台,把db#9清空就行了
三、测试进行到
Testing against TCP connection
的时候,发生死锁。问题因由:
winV函数redisContextSetTimeout的实现,用错setsockopt。强制类型转换是原罪!windows
运行hiredis_test的release版
一、死锁
二、因由:test.c用的assert,在vc的release下是被discard的服务器
让hiredis支持异步调用
一、hiredis的异步支持,其adapter有三个选择
ae
libev
libevnet
我选择libevent;livevent的编译介绍在 http://my.oschina.net/jacobin/blog/146567
二、把adapters/libevent.h分拆开声明和实现,实如今libevent.c(/新建)里。除了redisLibeventAttach,其它函数都是内部函数static网络