fbpx

Lesson in Pushing Redis to its limits

(Last Updated On: September 11, 2015)

Lesson in Pushing Ā Redis to its limits

I really pushed it but this sounds reasonable

C Code below

Join my FREE newsletter to see how Ā proceed with Redis for automated tradingĀ 

 

//github.com/redis/hiredis/blob/master/examples/example.c
//Note: loop 28233Connection error: Cannot assign requested address
//reasonable exception with github.com/redis/hiredis/issues/58

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include “hiredis.h”

void redisTest(int argc, char **argv) {
unsigned int j;
redisContext *c;
redisReply *reply;
const char *hostname = (argc > 1) ? argv[1] : “127.0.0.1”;
int port = (argc > 2) ? atoi(argv[2]) : 6379;

struct timeval timeout = { 1, 500000 }; // 1.5 seconds
c = redisConnectWithTimeout(hostname, port, timeout);
if (c == NULL || c->err) {
if (c) {
printf(“Connection error: %s\n”, c->errstr);
redisFree(c);
} else {
printf(“Connection error: can’t allocate redis context\n”);
}
exit(1);
}

/* 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);

/* Disconnects and frees the context */
redisFree(c);

}
void main(int argc, char **argv) {
int i = 0;

for(;;) {
printf(“\n loop %d”, i++);
redisTest(argc, argv);
}
}

 

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Subscribe For Latest Updates

Sign up to best of business news, informed analysis and opinions on what matters to you.
Invalid email address
We promise not to spam you. You can unsubscribe at any time.
Scroll to Top