Skip to content

Commit 24aa1cc

Browse files
committed
Added support for Spring Session Redis
Minor refactoring Added k8s config (WIP)
1 parent dd9dc94 commit 24aa1cc

File tree

6 files changed

+55
-12
lines changed

6 files changed

+55
-12
lines changed

deploy-on-k8s.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: redisbank-deployment
5+
spec:
6+
selector:
7+
matchLabels:
8+
app: redisbank
9+
replicas: 1
10+
template:
11+
metadata:
12+
labels:
13+
app: redisbank
14+
spec:
15+
containers:
16+
- name: redisbank
17+
image: <yourimageurl>
18+
imagePullPolicy: Always
19+
ports:
20+
- name: redisbank
21+
containerPort: 8080
22+
env:
23+
- name: SPRING_REDIS_HOST
24+
valueFrom:
25+
secretKeyRef:
26+
name: redb-redis-enterprise-database
27+
key: service_name
28+
- name: SPRING_REDIS_PORT
29+
valueFrom:
30+
secretKeyRef:
31+
name: redb-redis-enterprise-database
32+
key: port
33+
- name: SPRING_REDIS_PASSWORD
34+
valueFrom:
35+
secretKeyRef:
36+
name: redb-redis-enterprise-database
37+
key: password

pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
<groupId>org.springframework.boot</groupId>
2929
<artifactId>spring-boot-starter-data-redis-reactive</artifactId>
3030
</dependency>
31+
<dependency>
32+
<groupId>org.springframework.session</groupId>
33+
<artifactId>spring-session-data-redis</artifactId>
34+
</dependency>
3135
<dependency>
3236
<groupId>org.springframework.boot</groupId>
3337
<artifactId>spring-boot-starter-websocket</artifactId>

src/main/java/com/redislabs/demos/redisbank/RedisTimeSeriesConfiguration.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.redislabs.demos.redisbank;
22

3+
import com.redislabs.demos.redisbank.timeseries.TimeSeriesCommands;
4+
35
import org.springframework.context.annotation.Bean;
46
import org.springframework.context.annotation.Configuration;
57

@@ -14,4 +16,9 @@ RedisCommandFactory redisCommandFactory(RedisClient redis) {
1416
return new RedisCommandFactory(redis.connect());
1517
}
1618

19+
@Bean
20+
TimeSeriesCommands timeSeriesCommands(RedisCommandFactory rcf) {
21+
return rcf.getCommands(TimeSeriesCommands.class);
22+
}
23+
1724
}

src/main/java/com/redislabs/demos/redisbank/transactions/BankTransactionGenerator.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.springframework.stereotype.Component;
2828

2929
import io.lettuce.core.RedisCommandExecutionException;
30-
import io.lettuce.core.dynamic.RedisCommandFactory;
3130

3231
@Component
3332
public class BankTransactionGenerator {
@@ -51,10 +50,10 @@ public class BankTransactionGenerator {
5150
private final TimeSeriesCommands tsc;
5251

5352
public BankTransactionGenerator(StringRedisTemplate redis, StatefulRediSearchConnection<String, String> connection,
54-
RedisCommandFactory rcf) throws NoSuchAlgorithmException, UnsupportedEncodingException {
53+
TimeSeriesCommands tsc) throws NoSuchAlgorithmException, UnsupportedEncodingException {
5554
this.redis = redis;
5655
this.connection = connection;
57-
this.tsc = rcf.getCommands(TimeSeriesCommands.class);
56+
this.tsc = tsc;
5857
transactionSources = SerializationUtil.loadObjectList(TransactionSource.class, "/transaction_sources.csv");
5958
random = SecureRandom.getInstance("SHA1PRNG");
6059
random.setSeed("lars".getBytes("UTF-8")); // Prime the RNG so it always generates the same pseudorandom set

src/main/java/com/redislabs/demos/redisbank/transactions/TransactionOverviewController.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import com.redislabs.demos.redisbank.Config;
88
import com.redislabs.demos.redisbank.Config.StompConfig;
9-
import com.redislabs.demos.redisbank.Utilities;
109
import com.redislabs.demos.redisbank.timeseries.TimeSeriesCommands;
1110
import com.redislabs.lettusearch.RediSearchCommands;
1211
import com.redislabs.lettusearch.SearchOptions;
@@ -25,8 +24,6 @@
2524
import org.springframework.web.bind.annotation.RequestParam;
2625
import org.springframework.web.bind.annotation.RestController;
2726

28-
import io.lettuce.core.dynamic.RedisCommandFactory;
29-
3027
@RestController
3128
@RequestMapping(path = "/api")
3229
@CrossOrigin
@@ -45,10 +42,10 @@ public class TransactionOverviewController {
4542
private final TimeSeriesCommands tsc;
4643

4744
public TransactionOverviewController(Config config, StatefulRediSearchConnection<String, String> srsc,
48-
RedisCommandFactory rcf, StringRedisTemplate redis) {
45+
TimeSeriesCommands tsc, StringRedisTemplate redis) {
4946
this.config = config;
5047
this.srsc = srsc;
51-
this.tsc = rcf.getCommands(TimeSeriesCommands.class);
48+
this.tsc = tsc;
5249
this.redis = redis;
5350
}
5451

@@ -61,7 +58,6 @@ public StompConfig stompConfig() {
6158
public Balance[] balance() {
6259
Map<String, String> tsValues = tsc.range(BALANCE_TS, System.currentTimeMillis() - (1000 * 60 * 60 * 24 * 7),
6360
System.currentTimeMillis());
64-
6561
Balance[] balanceTs = new Balance[tsValues.size()];
6662
int i = 0;
6763

@@ -77,9 +73,7 @@ public Balance[] balance() {
7773

7874
@GetMapping("/biggestspenders")
7975
public BiggestSpenders biggestSpenders() {
80-
8176
Set<TypedTuple<String>> range = redis.opsForZSet().rangeByScoreWithScores(SORTED_SET_KEY, 0, Double.MAX_VALUE);
82-
8377
if (range.size() > 0) {
8478
BiggestSpenders biggestSpenders = new BiggestSpenders(range.size());
8579
int i = 0;

src/main/resources/application.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ spring.redis.port=6379
1717
stomp.endpoint=/websocket
1818
stomp.destinationPrefix=/topic
1919
stomp.transactionsTopic=/topic/transactions
20-
management.endpoints.web.exposure.include=env
20+
management.endpoints.web.exposure.include=env
21+
spring.session.store-type=redis
22+
session.redis.namespace={lars:}spring:session

0 commit comments

Comments
 (0)