13
13
import java .util .Map ;
14
14
15
15
import com .fasterxml .jackson .core .JsonProcessingException ;
16
+ import com .redis .lettucemod .api .StatefulRedisModulesConnection ;
17
+ import com .redis .lettucemod .api .sync .RediSearchCommands ;
18
+ import com .redis .lettucemod .search .Field ;
19
+ import com .redis .lettucemod .timeseries .CreateOptions ;
16
20
import com .redislabs .demos .redisbank .SerializationUtil ;
17
21
import com .redislabs .demos .redisbank .Utilities ;
18
- import com .redislabs .demos .redisbank .timeseries .TimeSeriesCommands ;
19
- import com .redislabs .lettusearch .Field ;
20
- import com .redislabs .lettusearch .Field .Text .PhoneticMatcher ;
21
- import com .redislabs .lettusearch .RediSearchCommands ;
22
- import com .redislabs .lettusearch .StatefulRediSearchConnection ;
23
22
24
23
import org .slf4j .Logger ;
25
24
import org .slf4j .LoggerFactory ;
@@ -47,14 +46,11 @@ public class BankTransactionGenerator {
47
46
private final NumberFormat nf = NumberFormat .getCurrencyInstance (Locale .GERMANY );
48
47
49
48
private final StringRedisTemplate redis ;
50
- private final StatefulRediSearchConnection <String , String > connection ;
51
- private final TimeSeriesCommands tsc ;
49
+ private final StatefulRedisModulesConnection <String , String > connection ;
52
50
53
- public BankTransactionGenerator (StringRedisTemplate redis , StatefulRediSearchConnection <String , String > connection ,
54
- TimeSeriesCommands tsc ) throws NoSuchAlgorithmException , UnsupportedEncodingException {
51
+ public BankTransactionGenerator (StringRedisTemplate redis , StatefulRedisModulesConnection <String , String > connection ) throws NoSuchAlgorithmException , UnsupportedEncodingException {
55
52
this .redis = redis ;
56
53
this .connection = connection ;
57
- this .tsc = tsc ;
58
54
transactionSources = SerializationUtil .loadObjectList (TransactionSource .class , "/transaction_sources.csv" );
59
55
random = SecureRandom .getInstance ("SHA1PRNG" );
60
56
random .setSeed ("lars" .getBytes ("UTF-8" )); // Prime the RNG so it always generates the same pseudorandom set
@@ -70,8 +66,8 @@ public BankTransactionGenerator(StringRedisTemplate redis, StatefulRediSearchCon
70
66
private void createSearchIndices () {
71
67
RediSearchCommands <String , String > commands = connection .sync ();
72
68
try {
73
- commands .dropIndex (ACCOUNT_INDEX );
74
- commands .dropIndex (SEARCH_INDEX );
69
+ commands .dropindex (ACCOUNT_INDEX );
70
+ commands .dropindex (SEARCH_INDEX );
75
71
} catch (RedisCommandExecutionException e ) {
76
72
if (!e .getMessage ().equals ("Unknown Index name" )) {
77
73
LOGGER .error ("Error dropping index: {}" , e .getMessage ());
@@ -81,9 +77,9 @@ private void createSearchIndices() {
81
77
commands .create (ACCOUNT_INDEX , Field .text ("toAccountName" ).build ());
82
78
LOGGER .info ("Created {} index" , ACCOUNT_INDEX );
83
79
84
- commands .create (SEARCH_INDEX , Field .text ("description" ).matcher (PhoneticMatcher .English ).build (),
85
- Field .text ("fromAccountName" ).matcher (PhoneticMatcher .English ).build (),
86
- Field .text ("transactionType" ).matcher (PhoneticMatcher .English ).build ());
80
+ commands .create (SEARCH_INDEX , Field .text ("description" ).matcher (Field . TextField . PhoneticMatcher .ENGLISH ).build (),
81
+ Field .text ("fromAccountName" ).matcher (Field . TextField . PhoneticMatcher .ENGLISH ).build (),
82
+ Field .text ("transactionType" ).matcher (Field . TextField . PhoneticMatcher .ENGLISH ).build ());
87
83
LOGGER .info ("Created {} index" , SEARCH_INDEX );
88
84
}
89
85
@@ -95,7 +91,8 @@ private void deleteSortedSet() {
95
91
96
92
private void createTimeSeries () {
97
93
redis .delete (BALANCE_TS );
98
- tsc .create (BALANCE_TS , 0 );
94
+ CreateOptions co = CreateOptions .builder ().retentionPeriod (0 ).build ();
95
+ connection .sync ().create (BALANCE_TS , co );
99
96
LOGGER .info ("Created {} time seris" , BALANCE_TS );
100
97
}
101
98
@@ -153,7 +150,7 @@ private String createTransactionAmount(String accountName) {
153
150
}
154
151
155
152
balance = balance + roundedAmount ;
156
- tsc . add (BALANCE_TS , balance );
153
+ connection . sync (). addAutoTimestamp (BALANCE_TS , balance );
157
154
redis .opsForZSet ().incrementScore (SORTED_SET_KEY , accountName , roundedAmount * -1 );
158
155
159
156
return nf .format (roundedAmount );
0 commit comments