|
1 |
| -# redis-java |
| 1 | +# RediSolar for Java |
| 2 | + |
| 3 | +Introduction |
| 4 | +--- |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | +This is the sample application codebase for RU102J, [Redis for Java Developers](https://university.redis.com/courses/ru102j/) at [Redis University](https://university.redis.com). |
| 9 | + |
| 10 | +Solutions to the course programming challenges can be found on the `solutions` branch. |
| 11 | + |
| 12 | +Prerequisites |
| 13 | +--- |
| 14 | + |
| 15 | +In order to start and run this application, you will need: |
| 16 | + |
| 17 | +* Java 8 JDK or higher |
| 18 | +* [Maven](https://maven.apache.org/) |
| 19 | +* Access to a local or remote installation of [Redis Stack](https://redis.io/docs/stack/get-started/install/) (local preferred, Docker is a good option - see instructions below) |
| 20 | +* Optional: [Docker](https://www.docker.com/get-started/) |
| 21 | +* Optional but recommended: [RedisInsight](https://redis.com/redis-enterprise/redis-insight/) to visualize the data in Redis. This is a graphical alternative to the `redis-cli` command |
| 22 | + |
| 23 | +Running Redis Stack with Docker |
| 24 | +--- |
| 25 | + |
| 26 | +We've provided a Docker Compose file as part of this repo, so to start Redis Stack, use the following command: |
| 27 | + |
| 28 | +```bash |
| 29 | +docker-compose up -d |
| 30 | +``` |
| 31 | + |
| 32 | +This will start a Redis Stack container with Redis exposed on localhost port 6379 with no password. You should see output similar to the following: |
| 33 | + |
| 34 | +``` |
| 35 | +Creating network "ru102j_default" with the default driver |
| 36 | +Creating redis_ru102j ... done |
| 37 | +``` |
| 38 | + |
| 39 | +Connect to Redis using either RedisInsight, or the `redis-cli` command. When using `redis-cli` you can invoke it from the Docker container like this: |
| 40 | + |
| 41 | +```bash |
| 42 | +docker exec -it redis_ru102j redis-cli |
| 43 | +``` |
| 44 | + |
| 45 | +When you see this prompt: |
| 46 | + |
| 47 | +``` |
| 48 | +127.0.0.1:6379> |
| 49 | +``` |
| 50 | + |
| 51 | +you are connected to Redis. Type `quit` to exit the Redis CLI. |
| 52 | + |
| 53 | +When you are finished working with Redis, shut down the server like so: |
| 54 | + |
| 55 | +```bash |
| 56 | +docker-compose down |
| 57 | +``` |
| 58 | + |
| 59 | +Redis saves your data in an append only file in the `redisdata` folder, and will re-load it next time you start the container. |
| 60 | + |
| 61 | +How to Start the RediSolar Application |
| 62 | +--- |
| 63 | + |
| 64 | +### When using Redis on localhost, port 6379 with no password: |
| 65 | + |
| 66 | +1. Run `mvn package` to build your application. |
| 67 | +2. Load the sample data: `java -jar target/redisolar-1.0.jar load`. If you want to erase everything in Redis before loading the data, use `java -jar target/redisolar-1.0.jar load --flush true`, but be aware that this will delete ALL keys in your Redis database. Note that loading the data may take a few minutes. |
| 68 | +3. Start the application with `java -jar target/redisolar-1.0.jar server config.yml` |
| 69 | +4. To check that your application is running enter url `http://localhost:8081`, substituting `localhost` for the hostname that you're running the application on if necessary. |
| 70 | + |
| 71 | +### When using Redis on another host, port or with a password: |
| 72 | + |
| 73 | +1. Edit `config.yml`, setting the values for your Redis host, port and password if needed. |
| 74 | +2. Edit `src/test/java/com/redislabs/university/RU102J/HostPort.java`, setting the values for your Redis host, port, and password if needed. |
| 75 | +3. Run `mvn package` to build your application. |
| 76 | +4. Load the sample data with `java -jar target/redisolar-1.0.jar load --host <hostname> --port <port> --password <password>`. |
| 77 | +5. Start application with `java -jar target/redisolar-1.0.jar server config.yml`. |
| 78 | +6. To check that your application is running enter url `http://localhost:8081`, substituting `localhost` for the hostname that you're running the application on if necessary. |
| 79 | + |
| 80 | +Tests |
| 81 | +--- |
| 82 | + |
| 83 | +To run all tests: |
| 84 | + |
| 85 | +``` |
| 86 | +mvn test |
| 87 | +``` |
| 88 | + |
| 89 | +To run a specific test: |
| 90 | + |
| 91 | +``` |
| 92 | +mvn test -Dtest=JedisBasicsTest |
| 93 | +``` |
| 94 | + |
| 95 | +Building |
| 96 | +--- |
| 97 | + |
| 98 | +To rebuild the application: |
| 99 | + |
| 100 | +``` |
| 101 | +mvn package |
| 102 | +``` |
| 103 | + |
| 104 | +To rebuild the application without running the tests: |
| 105 | + |
| 106 | +``` |
| 107 | +mvn package -DskipTests |
| 108 | +``` |
| 109 | + |
| 110 | +Optional (but Recommended): RedisInsight |
| 111 | +--- |
| 112 | + |
| 113 | +RedisInsight is a graphical tool for viewing data in Redis and managing Redis server instances. You don't need to install it to be successful with this course, but we recommend it as a good way of viewing data stored in Redis. |
| 114 | + |
| 115 | +To use RedisInsight, you'll need to [download it](https://redis.io/docs/ui/insight/) then point it at your Redis instance. |
| 116 | + |
| 117 | +If you're using the Docker Compose file provided with this course to run Redis Stack, you can optionally choose to access a web-based version of Redis Stack at `http://localhost:8001` whenever the container is running. |
| 118 | + |
| 119 | +Need Help / Join our Community |
| 120 | +--- |
| 121 | + |
| 122 | +If you need help with the course or want to chat to your fellow students and the wider Redis community, please [join us on our Discord server](https://discord.gg/jucCB8h). |
| 123 | + |
| 124 | +Subscribe to our YouTube Channel / Follow us on Twitch |
| 125 | +--- |
| 126 | + |
| 127 | +We'd love for you to [check out our YouTube channel](https://youtube.com/redisinc), and subscribe if you want to see more Redis videos! We also stream regularly on our [Twitch.tv channel](https://www.twitch.tv/redisinc) - follow us to be notified when we're live or check out our [streaming schedule](https://developer.redis.com/redis-live). |
0 commit comments