Last active
September 5, 2017 12:57
-
-
Save ilyaglow/2777d02b590ae55712da9d57159c775a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* apk add hiredis | |
* gcc -o simple-lpush simple_lpush.c -lhiredis | |
* ./simple-lpush mylist value | |
* | |
* On the consumer side: | |
* while :; do redis-cli BLPOP mylist 0; done | |
*/ | |
#include <stdlib.h> | |
#include <hiredis/hiredis.h> | |
#define CHECK(X) if ( !X || X->type == REDIS_REPLY_ERROR ) { printf("Error\n"); exit(-1); } | |
int main (int argc, char *argv[]) { | |
redisContext *c; | |
redisReply *reply; | |
c = redisConnect("localhost", 6379); | |
if (c->err) { | |
printf("Connection error: %s\n", c->errstr); | |
exit(1); | |
} | |
reply = (redisReply *) redisCommand(c,"LPUSH %s %s", argv[1], argv[2]); | |
CHECK(reply); | |
freeReplyObject(reply); | |
redisFree(c); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment