1
0
mirror of https://github.com/fluencelabs/redis synced 2025-06-25 23:11:33 +00:00
Files
.github
deps
hiredis
adapters
examples
CMakeLists.txt
example-ae.c
example-glib.c
example-ivykis.c
example-libev.c
example-libevent-ssl.c
example-libevent.c
example-libuv.c
example-macosx.c
example-qt.cpp
example-qt.h
example-ssl.c
example.c
.gitignore
.travis.yml
CHANGELOG.md
CMakeLists.txt
COPYING
Makefile
README.md
appveyor.yml
async.c
async.h
async_private.h
dict.c
dict.h
fmacros.h
hiredis.c
hiredis.h
hiredis.pc.in
hiredis_ssl.h
hiredis_ssl.pc.in
net.c
net.h
read.c
read.h
sds.c
sds.h
sdsalloc.h
sockcompat.c
sockcompat.h
ssl.c
test.c
test.sh
win32.h
jemalloc
linenoise
lua
Makefile
README.md
update-jemalloc.sh
src
tests
utils
.gitignore
00-RELEASENOTES
BUGS
CONTRIBUTING
COPYING
INSTALL
MANIFESTO
Makefile
README.md
TLS.md
redis.conf
runtest
runtest-cluster
runtest-moduleapi
runtest-sentinel
sentinel.conf
redis/deps/hiredis/examples/example-libev.c

53 lines
1.4 KiB
C
Raw Normal View History

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <hiredis.h>
#include <async.h>
#include <adapters/libev.h>
void getCallback(redisAsyncContext *c, void *r, void *privdata) {
redisReply *reply = r;
if (reply == NULL) return;
printf("argv[%s]: %s\n", (char*)privdata, reply->str);
/* Disconnect after receiving the reply to GET */
redisAsyncDisconnect(c);
}
void connectCallback(const redisAsyncContext *c, int status) {
if (status != REDIS_OK) {
printf("Error: %s\n", c->errstr);
return;
}
printf("Connected...\n");
2010-12-16 23:32:02 +01:00
}
void disconnectCallback(const redisAsyncContext *c, int status) {
if (status != REDIS_OK) {
printf("Error: %s\n", c->errstr);
return;
}
printf("Disconnected...\n");
}
int main (int argc, char **argv) {
signal(SIGPIPE, SIG_IGN);
redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379);
if (c->err) {
/* Let *c leak for now... */
printf("Error: %s\n", c->errstr);
return 1;
}
2010-12-16 23:32:02 +01:00
redisLibevAttach(EV_DEFAULT_ c);
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");
2010-12-16 23:32:02 +01:00
ev_loop(EV_DEFAULT_ 0);
return 0;
}