Skip to content

Instantly share code, notes, and snippets.

@m-x-k
Created February 22, 2018 13:35
Show Gist options
  • Save m-x-k/3c21ebbc68f05eb8623376eb1220e2c5 to your computer and use it in GitHub Desktop.
Save m-x-k/3c21ebbc68f05eb8623376eb1220e2c5 to your computer and use it in GitHub Desktop.
Java Redis CSV Upload Example
import redis.clients.jedis.Jedis;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import static java.lang.System.getenv;
public class JavaRedisCSVUploadExample {
/*
* ENV: REDIS_UPLOAD_HOST
* ARGS: ./file.csv
*/
public static void main(String[] args) throws Exception {
String host = getenv("REDIS_UPLOAD_HOST");
Jedis jedis = new Jedis(host);
System.out.println(jedis.ping());
Application application = new Application();
if (args == null || args.length < 0)
throw new RuntimeException("Missing required arguments");
Path csvFilePath = application.getCSVFilePath(args[0]);
jedis.lpush("CSV_DATA", new String(Files.readAllBytes(csvFilePath)));
jedis.close();
}
private Path getCSVFilePath(String file) {
Path filePath = Paths.get(file);
if (!Files.exists(filePath)) {
throw new RuntimeException("Missing required csv file");
}
return filePath;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment