尝试在Windows 上使用hiredis,构建一个正常的c ++应用程序来读取和写入redis.问题是hiredis没有正式支持在Windows上构建.如何用c ++构建一个利用hiredis的应用程序?
我正在使用hiredis C库连接到redis服务器.订阅新邮件后,我无法弄清楚如何等待新邮件.
我的代码看起来像:
signal(SIGPIPE, SIG_IGN );
struct event_base *base = event_base_new();
redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379);
if (c->err) {
/* Let *c leak for now... */
printf("Error: %s\n", c->errstr);
return 1;
}
redisLibeventAttach(c, base);
redisAsyncSetConnectCallback(c, connectCallback);
redisAsyncSetDisconnectCallback(c, disconnectCallback);
redisAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc - 1],
strlen(argv[argc - 1]));
redisAsyncCommand(c, getCallback, (char*) "end-1", "GET key");
redisAsyncCommand(c, getCallback, (char*) "end-1", "SUBSCRIBE foo");
Run Code Online (Sandbox Code Playgroud)
现在如何告诉hiredis在频道上等待消息?
我已经阅读了 redis 配置文档,但找不到这样的选项。
我搜索并发现“默认情况下,密钥将永远存在”。我想急切地改变这种默认行为。
Normally Redis keys are created without an associated time to live. The key will simply live forever, unless it is removed by the user in an explicit way, for instance using the DEL command.
The EXPIRE family of commands is able to associate an expire to a given key, at the cost of some additional memory used by the key. When a key has an expire set, Redis will make sure to remove the …Run Code Online (Sandbox Code Playgroud) 我正处于编写后端使用 redis 的 C 程序的 alpha 阶段。
我试过构建/安装hiredis(make && sudo make install)并运行测试(大部分通过)但是在尝试构建example.c程序时我收到一个错误,无法找到hiredis.h。
在命令行上构建: gcc -v example.c -lhiredis -I /usr/local/include/hiredis/
我尝试过的事情:
一切都没有运气。
我猜我没有为 gcc 正确链接程序,但文档没有任何构建示例。
我做错了什么,不允许我使用hiredis 构建此代码(或任何代码)?
确切的输出是...
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl …Run Code Online (Sandbox Code Playgroud) 我想在C中编译客户端以进行Redis。我已经下载并安装了libevent库和hiredis文件。我使用了以下命令:
gcc -I/home/tasos/Dropbox/lists/hiredis example-libevent.c -levent
Run Code Online (Sandbox Code Playgroud)
但我得到这些错误:
/tmp/ccxoerYJ.o: In function `redisLibeventReadEvent':
example-libevent.c:(.text+0x28): undefined reference to `redisAsyncHandleRead'
/tmp/ccxoerYJ.o: In function `redisLibeventWriteEvent':
example-libevent.c:(.text+0x56): undefined reference to `redisAsyncHandleWrite'
/tmp/ccxoerYJ.o: In function `getCallback':
example-libevent.c:(.text+0x2d2): undefined reference to `redisAsyncDisconnect'
/tmp/ccxoerYJ.o: In function `main':
example-libevent.c:(.text+0x393): undefined reference to `redisAsyncConnect'
example-libevent.c:(.text+0x3f3): undefined reference to `redisAsyncSetConnectCallback'
example-libevent.c:(.text+0x404): undefined reference to `redisAsyncSetDisconnectCallback'
example-libevent.c:(.text+0x45d): undefined reference to `redisAsyncCommand'
example-libevent.c:(.text+0x47d): undefined reference to `redisAsyncCommand'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
为什么这不起作用?