1313import java .util .Map ;
1414
1515import 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 ;
1620import com .redislabs .demos .redisbank .SerializationUtil ;
1721import 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 ;
2322
2423import org .slf4j .Logger ;
2524import org .slf4j .LoggerFactory ;
@@ -47,14 +46,11 @@ public class BankTransactionGenerator {
4746 private final NumberFormat nf = NumberFormat .getCurrencyInstance (Locale .GERMANY );
4847
4948 private final StringRedisTemplate redis ;
50- private final StatefulRediSearchConnection <String , String > connection ;
51- private final TimeSeriesCommands tsc ;
49+ private final StatefulRedisModulesConnection <String , String > connection ;
5250
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 {
5552 this .redis = redis ;
5653 this .connection = connection ;
57- this .tsc = tsc ;
5854 transactionSources = SerializationUtil .loadObjectList (TransactionSource .class , "/transaction_sources.csv" );
5955 random = SecureRandom .getInstance ("SHA1PRNG" );
6056 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
7066 private void createSearchIndices () {
7167 RediSearchCommands <String , String > commands = connection .sync ();
7268 try {
73- commands .dropIndex (ACCOUNT_INDEX );
74- commands .dropIndex (SEARCH_INDEX );
69+ commands .dropindex (ACCOUNT_INDEX );
70+ commands .dropindex (SEARCH_INDEX );
7571 } catch (RedisCommandExecutionException e ) {
7672 if (!e .getMessage ().equals ("Unknown Index name" )) {
7773 LOGGER .error ("Error dropping index: {}" , e .getMessage ());
@@ -81,9 +77,9 @@ private void createSearchIndices() {
8177 commands .create (ACCOUNT_INDEX , Field .text ("toAccountName" ).build ());
8278 LOGGER .info ("Created {} index" , ACCOUNT_INDEX );
8379
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 ());
8783 LOGGER .info ("Created {} index" , SEARCH_INDEX );
8884 }
8985
@@ -95,7 +91,8 @@ private void deleteSortedSet() {
9591
9692 private void createTimeSeries () {
9793 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 );
9996 LOGGER .info ("Created {} time seris" , BALANCE_TS );
10097 }
10198
@@ -153,7 +150,7 @@ private String createTransactionAmount(String accountName) {
153150 }
154151
155152 balance = balance + roundedAmount ;
156- tsc . add (BALANCE_TS , balance );
153+ connection . sync (). addAutoTimestamp (BALANCE_TS , balance );
157154 redis .opsForZSet ().incrementScore (SORTED_SET_KEY , accountName , roundedAmount * -1 );
158155
159156 return nf .format (roundedAmount );
0 commit comments