Newer
Older
RedisProvider::RedisProvider(std::string ip, int port, std::string key) {
int RedisProvider::write(PacketLib::BasePacket &packet) {
uint size = packet.getHeaderSize() + packet.getPayloadSize() + packet.getTailSize();
redisReply *r = (redisReply *) redisCommand(context, "LPUSH %s %b", this->key.c_str(), (char*) packet.getBinaryPointer(), size);
if (r == NULL) {
// Error executing Redis command
return -1;
}
// Check the type of the Redis reply
if (r->type == REDIS_REPLY_ERROR) {
// Error executing Redis command
std::cout << r->str << std::endl;
freeReplyObject(r);
return -1;
}
freeReplyObject(r);
int RedisProvider::write(PacketLib::BasePacket &packet, std::string key) {
uint size = packet.getHeaderSize() + packet.getPayloadSize() + packet.getTailSize();
redisReply *r = (redisReply *) redisCommand(context, "LPUSH %s %b", key.c_str(), (char*) packet.getBinaryPointer(), size);
if (r == NULL) {
// Error executing Redis command
return -1;
}
// Check the type of the Redis reply
if (r->type == REDIS_REPLY_ERROR) {
// Error executing Redis command
std::cout << r->str << std::endl;
freeReplyObject(r);
return -1;
}
freeReplyObject(r);
context = redisConnect(getIp().c_str(), getPort());
if (context == NULL || context->err) {
if (context) {
printf("Can't allocate Redis context\n");
RedisProvider::~RedisProvider(){
std::cout << "Deleting Redis stream" << std::endl;
}