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, "XADD DAQ_key * data %b", packet.getBinaryPointer(), size);
if (r == nullptr || r->type == REDIS_REPLY_ERROR) {
std::cerr << "XADD command failed: " << r->str << std::endl;
return -1;
}
return size;
int RedisProvider::write(PacketLib::BasePacket &packet, std::string key) {
uint size = packet.getHeaderSize() + packet.getPayloadSize() + packet.getTailSize();
redisReply *r = (redisReply *) redisCommand(context, "XADD %s * data %b",key, packet.getBinaryPointer(), size);
if (r == nullptr || r->type == REDIS_REPLY_ERROR) {
std::cerr << "XADD command failed: " << r->str << std::endl;
return -1;
}
return size;
context = redisConnect(getIp().c_str(), getPort());
if (context == NULL || context->err) {
if (context) {
printf("Error: %s\n", context->errstr);
} else {
printf("Can't allocate Redis context\n");
RedisProvider::~RedisProvider(){
std::cout << "Deleting Redis stream" << std::endl;
}