Skip to content

Commit 81e4014

Browse files
committed
redis examples
1 parent 2e1b346 commit 81e4014

File tree

123 files changed

+6536
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+6536
-0
lines changed

redis-labs/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# redisolar
2+
3+
How to start the redisolar application
4+
---
5+
6+
1. Run `mvn package` to build your application
7+
2. Start application with `java -jar target/redisolar-1.0.jar server config.yml`
8+
3. To check that your application is running enter url `http://[HOST]:8081`. If you're
9+
running on localhost, HOST will be "localhost".
10+
11+
Tests
12+
---
13+
14+
To run all tests:
15+
16+
```
17+
mvn test
18+
```
19+
20+
To run a specific test:
21+
22+
```
23+
mvn test -Dtest=JedisBasicsTest
24+
```
25+
26+
Health Check
27+
---
28+
29+
To see your applications health enter url `http://localhost:8084/healthcheck`

redis-labs/config.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
logging:
2+
level: INFO
3+
loggers:
4+
com.redislabs.university: DEBUG
5+
defaultName: "RediSolar"
6+
redis:
7+
host: localhost
8+
port: 6379
9+
server:
10+
rootPath: /api
11+
applicationConnectors:
12+
- type: http
13+
port: 8081
14+
adminConnectors:
15+
- type: http
16+
port: 8084
17+

redis-labs/load-data.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# The sample application includes a data loader. You should run this after completing each programming challenge. Often, you'll be writing code that inserts data into the application. Running the data loader will ensure that this data is always up to date.
2+
java -jar target/redisolar-1.0.jar load

redis-labs/pom.xml

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project
3+
xmlns="http://maven.apache.org/POM/4.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
6+
7+
<modelVersion>4.0.0</modelVersion>
8+
<prerequisites>
9+
<maven>3.0.0</maven>
10+
</prerequisites>
11+
12+
<groupId>com.redislabs.university</groupId>
13+
<artifactId>redisolar</artifactId>
14+
<version>1.0</version>
15+
<packaging>jar</packaging>
16+
17+
<name>redisolar</name>
18+
19+
<properties>
20+
<redis.host>localhost</redis.host>
21+
<redis.port>6379</redis.port>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24+
<dropwizard.version>1.3.8</dropwizard.version>
25+
<mainClass>com.redislabs.university.RU102J.RediSolarApplication</mainClass>
26+
</properties>
27+
28+
<dependencyManagement>
29+
<dependencies>
30+
<dependency>
31+
<groupId>io.dropwizard</groupId>
32+
<artifactId>dropwizard-bom</artifactId>
33+
<version>${dropwizard.version}</version>
34+
<type>pom</type>
35+
<scope>import</scope>
36+
</dependency>
37+
</dependencies>
38+
</dependencyManagement>
39+
40+
<dependencies>
41+
<dependency>
42+
<groupId>com.google.inject</groupId>
43+
<artifactId>guice</artifactId>
44+
<version>4.2.2</version>
45+
</dependency>
46+
<dependency>
47+
<groupId>io.dropwizard</groupId>
48+
<artifactId>dropwizard-core</artifactId>
49+
</dependency>
50+
<dependency>
51+
<groupId>io.dropwizard</groupId>
52+
<artifactId>dropwizard-assets</artifactId>
53+
</dependency>
54+
<dependency>
55+
<groupId>io.dropwizard</groupId>
56+
<artifactId>dropwizard-testing</artifactId>
57+
</dependency>
58+
<dependency>
59+
<groupId>redis.clients</groupId>
60+
<artifactId>jedis</artifactId>
61+
<version>3.1.0-m3</version>
62+
</dependency>
63+
<dependency>
64+
<groupId>com.redislabs</groupId>
65+
<artifactId>jredistimeseries</artifactId>
66+
<version>0.9.0</version>
67+
</dependency>
68+
<dependency>
69+
<groupId>javax.xml.bind</groupId>
70+
<artifactId>jaxb-api</artifactId>
71+
<version>2.2.11</version>
72+
</dependency>
73+
<dependency>
74+
<groupId>com.sun.xml.bind</groupId>
75+
<artifactId>jaxb-core</artifactId>
76+
<version>2.2.11</version>
77+
</dependency>
78+
<dependency>
79+
<groupId>com.sun.xml.bind</groupId>
80+
<artifactId>jaxb-impl</artifactId>
81+
<version>2.2.11</version>
82+
</dependency>
83+
<dependency>
84+
<groupId>javax.activation</groupId>
85+
<artifactId>activation</artifactId>
86+
<version>1.1.1</version>
87+
</dependency>
88+
<dependency>
89+
<groupId>junit</groupId>
90+
<artifactId>junit</artifactId>
91+
<version>4.12</version>
92+
<scope>test</scope>
93+
</dependency>
94+
<dependency>
95+
<groupId>org.hamcrest</groupId>
96+
<artifactId>hamcrest-all</artifactId>
97+
<version>1.3</version>
98+
<scope>test</scope>
99+
</dependency>
100+
<dependency>
101+
<groupId>org.mockito</groupId>
102+
<artifactId>mockito-all</artifactId>
103+
<version>1.9.5</version>
104+
<scope>test</scope>
105+
</dependency>
106+
</dependencies>
107+
108+
<build>
109+
<plugins>
110+
<plugin>
111+
<groupId>org.codehaus.mojo</groupId>
112+
<artifactId>properties-maven-plugin</artifactId>
113+
<version>1.0.0</version>
114+
<executions>
115+
<execution>
116+
<phase>initialize</phase>
117+
<goals>
118+
<goal>read-project-properties</goal>
119+
</goals>
120+
<configuration>
121+
<files>
122+
<file>pom.xml</file>
123+
</files>
124+
</configuration>
125+
</execution>
126+
</executions>
127+
</plugin>
128+
<plugin>
129+
<artifactId>maven-shade-plugin</artifactId>
130+
<version>2.4.1</version>
131+
<configuration>
132+
<createDependencyReducedPom>false</createDependencyReducedPom>
133+
<transformers>
134+
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
135+
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
136+
<mainClass>${mainClass}</mainClass>
137+
</transformer>
138+
</transformers>
139+
<!-- exclude signed Manifests -->
140+
<filters>
141+
<filter>
142+
<artifact>*:*</artifact>
143+
<excludes>
144+
<exclude>META-INF/*.SF</exclude>
145+
<exclude>META-INF/*.DSA</exclude>
146+
<exclude>META-INF/*.RSA</exclude>
147+
</excludes>
148+
</filter>
149+
</filters>
150+
</configuration>
151+
<executions>
152+
<execution>
153+
<phase>package</phase>
154+
<goals>
155+
<goal>shade</goal>
156+
</goals>
157+
</execution>
158+
</executions>
159+
</plugin>
160+
<plugin>
161+
<artifactId>maven-jar-plugin</artifactId>
162+
<version>3.0.2</version>
163+
<configuration>
164+
<archive>
165+
<manifest>
166+
<addClasspath>true</addClasspath>
167+
<mainClass>${mainClass}</mainClass>
168+
</manifest>
169+
</archive>
170+
</configuration>
171+
</plugin>
172+
<plugin>
173+
<artifactId>maven-compiler-plugin</artifactId>
174+
<version>3.6.1</version>
175+
<configuration>
176+
<source>1.8</source>
177+
<target>1.8</target>
178+
</configuration>
179+
</plugin>
180+
<plugin>
181+
<artifactId>maven-source-plugin</artifactId>
182+
<version>3.0.1</version>
183+
<executions>
184+
<execution>
185+
<id>attach-sources</id>
186+
<goals>
187+
<goal>jar</goal>
188+
</goals>
189+
</execution>
190+
</executions>
191+
</plugin>
192+
</plugins>
193+
</build>
194+
195+
<reporting>
196+
<plugins>
197+
<plugin>
198+
<artifactId>maven-project-info-reports-plugin</artifactId>
199+
<version>2.8.1</version>
200+
<configuration>
201+
<dependencyLocationsEnabled>false</dependencyLocationsEnabled>
202+
<dependencyDetailsEnabled>false</dependencyDetailsEnabled>
203+
</configuration>
204+
</plugin>
205+
<plugin>
206+
<artifactId>maven-javadoc-plugin</artifactId>
207+
<version>2.10.3</version>
208+
</plugin>
209+
</plugins>
210+
</reporting>
211+
</project>

redis-labs/requests.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
insert records
2+
3+
POST: http://localhost:8081/api/meterReadings
4+
-H "Content-Type:application/json"
5+
```json
6+
[
7+
{
8+
"siteId": 1,
9+
"dateTime": "2020-01-01T00:00Z[UTC]",
10+
"whUsed": 2.5,
11+
"whGenerated": 3.0,
12+
"tempC": 22.5
13+
},
14+
{
15+
"siteId": 1,
16+
"dateTime": "2020-01-01T00:01Z[UTC]",
17+
"whUsed": 2.4,
18+
"whGenerated": 3.1,
19+
"tempC": 22.0
20+
}
21+
]
22+
```
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.redislabs.university.RU102J;
2+
3+
import com.google.inject.AbstractModule;
4+
import com.google.inject.Provides;
5+
import io.dropwizard.Configuration;
6+
import redis.clients.jedis.JedisPool;
7+
8+
public class ApplicationModule extends AbstractModule {
9+
10+
private final JedisPool jedisPool;
11+
12+
public ApplicationModule(JedisPool jedisPool) {
13+
this.jedisPool = jedisPool;
14+
}
15+
16+
@Provides
17+
public RediSolarConfiguration configuration(Configuration configuration)
18+
{
19+
return (RediSolarConfiguration) configuration;
20+
}
21+
22+
@Provides
23+
public JedisPool provideJedisPool() {
24+
return jedisPool;
25+
}
26+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package com.redislabs.university.RU102J;
2+
3+
import com.redislabs.redistimeseries.RedisTimeSeries;
4+
import com.redislabs.university.RU102J.command.LoadCommand;
5+
import com.redislabs.university.RU102J.command.RunCommand;
6+
import com.redislabs.university.RU102J.dao.*;
7+
import com.redislabs.university.RU102J.health.RediSolarHealthCheck;
8+
import com.redislabs.university.RU102J.resources.*;
9+
import io.dropwizard.Application;
10+
import io.dropwizard.assets.AssetsBundle;
11+
import io.dropwizard.setup.Bootstrap;
12+
import io.dropwizard.setup.Environment;
13+
import redis.clients.jedis.JedisPool;
14+
import redis.clients.jedis.JedisPoolConfig;
15+
16+
public class RediSolarApplication extends Application<RediSolarConfiguration> {
17+
18+
public static void main(final String[] args) throws Exception {
19+
new RediSolarApplication().run(args);
20+
}
21+
22+
@Override
23+
public String getName() {
24+
return "RediSolar";
25+
}
26+
27+
@Override
28+
public void initialize(final Bootstrap<RediSolarConfiguration> bootstrap) {
29+
bootstrap.addBundle(new AssetsBundle("/dashboard/dist", "/", "index.html"));
30+
bootstrap.addCommand(new LoadCommand());
31+
bootstrap.addCommand(new RunCommand());
32+
}
33+
34+
@Override
35+
public void run(final RediSolarConfiguration configuration,
36+
final Environment environment) {
37+
RedisConfig redisConfig = configuration.getRedisConfig();
38+
JedisPool jedisPool = new JedisPool(new JedisPoolConfig(), redisConfig.getHost(),
39+
redisConfig.getPort());
40+
41+
// To use the geospatial features, replace the following lines with:
42+
SiteGeoResource siteResource =
43+
new SiteGeoResource(new SiteGeoDaoRedisImpl(jedisPool));
44+
// SiteResource siteResource =
45+
// new SiteResource(new SiteDaoRedisImpl(jedisPool));
46+
environment.jersey().register(siteResource);
47+
48+
// For RedisTimeSeries: replace the next lines with
49+
MetricsResource metricsResource =
50+
new MetricsResource(new MetricDaoRedisTSImpl(jedisPool));
51+
// MetricsResource metricsResource =
52+
// new MetricsResource(new MetricDaoRedisZsetImpl(jedisPool));
53+
environment.jersey().register(metricsResource);
54+
55+
CapacityResource capacityResource =
56+
new CapacityResource(new CapacityDaoRedisImpl(jedisPool));
57+
environment.jersey().register(capacityResource);
58+
59+
MeterReadingResource meterResource =
60+
new MeterReadingResource(new SiteStatsDaoRedisImpl(jedisPool),
61+
// new MetricDaoRedisZsetImpl(jedisPool),
62+
// For RedisTimeSeries:
63+
new MetricDaoRedisTSImpl(jedisPool),
64+
new CapacityDaoRedisImpl(jedisPool),
65+
new FeedDaoRedisImpl(jedisPool));
66+
environment.jersey().register(meterResource);
67+
68+
RediSolarHealthCheck healthCheck = new RediSolarHealthCheck(redisConfig);
69+
environment.healthChecks().register("healthy", healthCheck);
70+
}
71+
}

0 commit comments

Comments
 (0)