Redis,GetStart on windows
2013-06-04 11:42
405 查看
redis 一个可扩展的高性能的nosql数据库,越来越多的产品在使用它,redis是目前只能在linux下编译,这么好的东西肯定会有人移植到window平台的,点击msopentech移植的版本.
这里先说一下测试环境
系统:window xp sp3
编译器:VC6
由于Redis是独立的进程,不需要嵌入到程序,所以不涉及到兼容性,这里直接使用Redis-server的win32移植版.
但是客户端是需要嵌入到其他的程序的,所以VC6能编译,那基本上msvc所有版本的都可以使用了.
客户端代码使用hiredis,编译的时候需要做一些修改.
将long long 修改成__int64
win32fixes.c 496行由
删除win32fixes.c 495,494,490三行
win32fixes.c 115行的intptr_t 改成 int
新建一个win32 console工程,然后将
hiredis 目录下面的代码都放进去,新建一个test.c将一下代码复制进去,将工程由Debug SingleThread 改成Debug MutliThread(Project->Settings->C/C++ Code Generation).
源码地址:test.rar
这里先说一下测试环境
系统:window xp sp3
编译器:VC6
由于Redis是独立的进程,不需要嵌入到程序,所以不涉及到兼容性,这里直接使用Redis-server的win32移植版.
但是客户端是需要嵌入到其他的程序的,所以VC6能编译,那基本上msvc所有版本的都可以使用了.
客户端代码使用hiredis,编译的时候需要做一些修改.
将long long 修改成__int64
win32fixes.c 496行由
d = _strtod_l(nptr, &leptr, clocale);改成
d = strtod(nptr, &leptr);
删除win32fixes.c 495,494,490三行
win32fixes.c 115行的intptr_t 改成 int
新建一个win32 console工程,然后将
hiredis 目录下面的代码都放进去,新建一个test.c将一下代码复制进去,将工程由Debug SingleThread 改成Debug MutliThread(Project->Settings->C/C++ Code Generation).
#include "win32fixes.h" #include "fmacros.h" #include "hiredis.h" #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #pragma comment(lib,"ws2_32.lib") int main() { unsigned int j; redisContext *c; redisReply *reply; WSADATA wsa; struct timeval t = { 1, 500000 }; // 1.5 seconds WSAStartup(MAKEWORD(2,2),&wsa); c = redisConnectWithTimeout("127.0.0.1",6379, t); if (c->err) { printf("Connection error: %s\n", c->errstr); exit(1); } /* PING server */ reply = redisCommand(c,"PING"); printf("PING: %s\n", reply->str); freeReplyObject(reply); /* Set a key */ reply = redisCommand(c,"SET %s %s", "foo", "hello world"); printf("SET: %s\n", reply->str); freeReplyObject(reply); /* Set a key using binary safe API */ reply = redisCommand(c,"SET %b %b", "bar", 3, "hello", 5); printf("SET (binary API): %s\n", reply->str); freeReplyObject(reply); /* Try a GET and two INCR */ reply = redisCommand(c,"GET foo"); printf("GET foo: %s\n", reply->str); freeReplyObject(reply); reply = redisCommand(c,"INCR counter"); printf("INCR counter: %lld\n", reply->integer); freeReplyObject(reply); /* again ... */ reply = redisCommand(c,"INCR counter"); printf("INCR counter: %lld\n", reply->integer); freeReplyObject(reply); /* Create a list of numbers, from 0 to 9 */ reply = redisCommand(c,"DEL mylist"); freeReplyObject(reply); for (j = 0; j < 10; j++) { char buf[64]; snprintf(buf,64,"%d",j); reply = redisCommand(c,"LPUSH mylist element-%s", buf); freeReplyObject(reply); } /* Let's check what we have inside the list */ reply = redisCommand(c,"LRANGE mylist 0 -1"); if (reply->type == REDIS_REPLY_ARRAY) { for (j = 0; j < reply->elements; j++) { printf("%u) %s\n", j, reply->element[j]->str); } } freeReplyObject(reply); WSACleanup(); return 0; }
源码地址:test.rar
相关文章推荐
- Torch - 1 -- Install and Get Start on Ubuntu 12
- Note on tensorflow(三)Get startd on Tensorboard
- Start with PJSIP on windows -----pjsip-2.2.1
- redis on windows
- .net中调试WindowsService的OnStart()(
- Get Familiar: Microsoft Bluetooth Stack on Windows Mobile(转)
- 调试windows service的OnStart事件及调试service的一些方法汇总
- Redis On Windows
- (二)Get start with Arduino for windows【The Arduino Platform and C Pro】
- Redis on Windows
- Getting start with boost on windows
- 10 steps to get Ruby on Rails running on Windows with IIS FastCGI- 摘自网络
- Get start with "Redis" —— by “EOF”
- How to Get Chrome OS Fonts on Windows and Google Chrome
- 解决 Redis on Windows Setup Wizard ended prematurely
- [原]Unable to start debugging on the web server.Debugging failes because integrated Windows authentication is not enabled.
- C#写的服务出现错误:Windows could not start the NLServices sercice on local Computer. Error 1083:The executable programe that thi
- 调试windows service的OnStart事件.
- Unable to start debugging on the web server. Debugging failed because integrated windows authentication is not enabled.
- Windows get into remote Ubuntu desktop based on FreeNX