int redis_pull(redisContext* rctx, char *redisqueuename, void *buf, int maxload, size_t obj_size, int *numloaded, const char* cmd) { assert(rctx); long elems_in_redis = redis_get_sizeof_list(rctx, redisqueuename); long num_to_add = MIN(elems_in_redis, maxload); log_debug("redis", "redis load called on %s. Transferring %li of %li elements " "to in-memory queue.", redisqueuename, num_to_add, elems_in_redis); for (int i = 0; i < num_to_add; i++) { redisAppendCommand(rctx, "%s %s", cmd, redisqueuename); } for (int i = 0; i < num_to_add; i++) { redisReply *reply = NULL; int rc = redisGetReply(rctx, (void **) &reply); if (chkerr(rctx, reply)) { return ZMAP_REDIS_ERROR; } if (rc != REDIS_OK || reply == NULL) { log_error("redis", "unknown error, could not get reply"); if (reply) { freeReplyObject(reply); } return ZMAP_REDIS_ERROR; } if (reply->type != REDIS_REPLY_STRING) { log_error("redis", "unxpected reply type from redis"); freeReplyObject(reply); return ZMAP_REDIS_ERROR; } if ((size_t) reply->len != obj_size) { freeReplyObject(reply); log_error("redis", "response object length mismatch"); return ZMAP_REDIS_ERROR; } memcpy((void*)((intptr_t)buf+i*obj_size), reply->str, obj_size); freeReplyObject(reply); *numloaded = i + 1; } return ZMAP_REDIS_SUCCESS; }
int redis_pull(char *redisqueuename, void *buf, int maxload, size_t obj_size, int *numloaded, const char* cmd) { assert(rctx); long elems_in_redis = redis_get_sizeof_list(redisqueuename); long num_to_add = MIN(elems_in_redis, maxload); log_info("redis", "INFO: redis load called on %s. Transfering %li " "of %li elements to in-memory queue.", redisqueuename, num_to_add, elems_in_redis); for(int i=0; i < num_to_add; i++) { redisAppendCommand(rctx, "%s %s", cmd, redisqueuename); } for(int i=0; i < num_to_add; i++) { redisReply *reply; int rc = redisGetReply(rctx, (void**) &reply); if (rc != REDIS_OK) { log_fatal("redis", "response from redis != REDIS_OK"); return -1; } if (!reply) { log_fatal("redis", "no reply provided by redis."); return -1; } if (reply->type != REDIS_REPLY_STRING) { log_fatal("redis", "unxpected reply type from redis."); return -1; } if ((size_t)reply->len != obj_size) { log_fatal("redis", "ERROR: unexpected lengthed " "object provided by redis.\n"); return -1; } memcpy((void*)((intptr_t)buf+i*obj_size), reply->str, obj_size); freeReplyObject(reply); } *numloaded = num_to_add; return 0; }