Skip to content

Instantly share code, notes, and snippets.

@ilyaglow
Last active September 5, 2017 12:57
Show Gist options
  • Save ilyaglow/2777d02b590ae55712da9d57159c775a to your computer and use it in GitHub Desktop.
Save ilyaglow/2777d02b590ae55712da9d57159c775a to your computer and use it in GitHub Desktop.
/*
* 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