11package com .redis .enterprise .rest ;
22
3- import java .util .Collections ;
3+ import java .util .ArrayList ;
4+ import java .util .Arrays ;
45import java .util .List ;
56import java .util .stream .Collectors ;
6- import java .util .stream .Stream ;
77
88import org .apache .hc .core5 .util .Asserts ;
99import org .springframework .util .unit .DataSize ;
@@ -26,10 +26,10 @@ public class Database {
2626 private boolean ossCluster ;
2727 private ProxyPolicy proxyPolicy ;
2828 private IPType ossClusterAPIPreferredIPType ;
29- private List <Regex > shardKeyRegex ;
29+ private List <ShardKeyRegex > shardKeyRegex ;
3030 private Integer shardCount ;
3131 private ShardPlacement shardPlacement ;
32- private List <ModuleConfig > moduleConfigs ;
32+ private List <ModuleConfig > modules ;
3333
3434 private Database () {
3535 }
@@ -45,10 +45,10 @@ private Database(Builder builder) {
4545 this .ossCluster = builder .ossCluster ;
4646 this .proxyPolicy = builder .proxyPolicy ;
4747 this .ossClusterAPIPreferredIPType = builder .ossClusterAPIPreferredIPType ;
48- this .shardKeyRegex = builder .shardKeyRegex ;
48+ this .shardKeyRegex = builder .shardKeyRegexes . stream (). map ( ShardKeyRegex :: new ). collect ( Collectors . toList ()) ;
4949 this .shardCount = builder .shardCount ;
5050 this .shardPlacement = builder .shardPlacement ;
51- this .moduleConfigs = builder .moduleConfigs ;
51+ this .modules = builder .moduleConfigs ;
5252 }
5353
5454 public Long getUid () {
@@ -136,11 +136,11 @@ public void setOssClusterAPIPreferredIPType(IPType ossClusterAPIPreferredIPType)
136136 }
137137
138138 @ JsonProperty ("shard_key_regex" )
139- public List <Regex > getShardKeyRegex () {
139+ public List <ShardKeyRegex > getShardKeyRegex () {
140140 return shardKeyRegex ;
141141 }
142142
143- public void setShardKeyRegex (List <Regex > shardKeyRegex ) {
143+ public void setShardKeyRegex (List <ShardKeyRegex > shardKeyRegex ) {
144144 this .shardKeyRegex = shardKeyRegex ;
145145 }
146146
@@ -163,16 +163,12 @@ public void setShardPlacement(ShardPlacement shardPlacement) {
163163 }
164164
165165 @ JsonProperty ("module_list" )
166- public List <ModuleConfig > getModuleConfigs () {
167- return moduleConfigs ;
166+ public List <ModuleConfig > getModules () {
167+ return modules ;
168168 }
169169
170- public void setModuleConfigs (List <ModuleConfig > moduleConfigs ) {
171- this .moduleConfigs = moduleConfigs ;
172- }
173-
174- public void setModules (List <String > names ) {
175- this .setModuleConfigs (names .stream ().map (ModuleConfig ::new ).collect (Collectors .toList ()));
170+ public void setModules (List <ModuleConfig > modules ) {
171+ this .modules = modules ;
176172 }
177173
178174 public enum IPType {
@@ -239,14 +235,14 @@ public void setArgs(String args) {
239235 }
240236
241237 @ JsonInclude (JsonInclude .Include .NON_NULL )
242- public static class Regex {
238+ public static class ShardKeyRegex {
243239
244240 private String regex ;
245241
246- public Regex () {
242+ public ShardKeyRegex () {
247243 }
248244
249- public Regex (String regex ) {
245+ public ShardKeyRegex (String regex ) {
250246 this .regex = regex ;
251247 }
252248
@@ -280,10 +276,10 @@ public static final class Builder {
280276 private boolean ossCluster ;
281277 private ProxyPolicy proxyPolicy ;
282278 private IPType ossClusterAPIPreferredIPType ;
283- private List <Regex > shardKeyRegex = Collections . emptyList ();
279+ private List <String > shardKeyRegexes = new ArrayList <> ();
284280 private Integer shardCount ;
285281 private ShardPlacement shardPlacement ;
286- private List <ModuleConfig > moduleConfigs = Collections . emptyList ();
282+ private List <ModuleConfig > moduleConfigs = new ArrayList <> ();
287283
288284 private Builder () {
289285 }
@@ -345,17 +341,24 @@ public Builder ossClusterAPIPreferredIPType(IPType ossClusterAPIPreferredIPType)
345341 return this ;
346342 }
347343
348- public Builder shardKeyRegex (List <Regex > shardKeyRegex ) {
349- this .shardKeyRegex = shardKeyRegex ;
344+ public Builder shardKeyRegex (String regex ) {
345+ this .shardKeyRegexes .add (regex );
346+ return this ;
347+ }
348+
349+ public Builder shardKeyRegexes (String ... regexes ) {
350+ for (String regex : regexes ) {
351+ shardKeyRegex (regex );
352+ }
350353 return this ;
351354 }
352355
353356 public Builder shardCount (int shardCount ) {
354357 Asserts .check (shardCount > 0 , "Shard count must be strictly positive" );
355358 this .shardCount = shardCount ;
356359 if (shardCount > 1 ) {
357- this . sharding = true ;
358- this . shardKeyRegex = Stream . of (DEFAULT_SHARD_KEY_REGEXES ). map ( Regex :: new ). collect ( Collectors . toList () );
360+ sharding ( true ) ;
361+ shardKeyRegexes (DEFAULT_SHARD_KEY_REGEXES );
359362 }
360363 return this ;
361364 }
@@ -365,13 +368,46 @@ public Builder shardPlacement(ShardPlacement shardPlacement) {
365368 return this ;
366369 }
367370
368- public Builder moduleConfigs (List <ModuleConfig > moduleConfigs ) {
369- this .moduleConfigs = moduleConfigs ;
371+ public Builder module (Module module ) {
372+ this .moduleConfigs .add (new ModuleConfig (module .getName ()));
373+ return this ;
374+ }
375+
376+ public Builder modules (Module ... modules ) {
377+ for (Module module : modules ) {
378+ module (module );
379+ }
380+ return this ;
381+ }
382+
383+ public Builder moduleConfig (ModuleConfig moduleConfig ) {
384+ this .moduleConfigs .add (moduleConfig );
385+ return this ;
386+ }
387+
388+ public Builder moduleConfigs (ModuleConfig ... moduleConfigs ) {
389+ this .moduleConfigs = Arrays .asList (moduleConfigs );
370390 return this ;
371391 }
372392
373393 public Database build () {
374394 return new Database (this );
375395 }
396+
397+ public enum Module {
398+
399+ BLOOM ("bf" ), GEARS ("rg" ), GRAPH ("graph" ), JSON ("ReJSON" ), SEARCH ("search" ), TIMESERIES ("timeseries" );
400+
401+ private final String name ;
402+
403+ Module (String name ) {
404+ this .name = name ;
405+ }
406+
407+ public String getName () {
408+ return name ;
409+ }
410+
411+ }
376412 }
377413}
0 commit comments