|
39 | 39 |
|
40 | 40 | @AutoValue |
41 | 41 | public abstract class RedisFeatureSink implements FeatureSink { |
| 42 | + private static final int DEFAULT_BATCH_SIZE = 10000; |
| 43 | + private static final int DEFAULT_FREQUENCY_SECONDS = 30; |
42 | 44 |
|
43 | 45 | /** |
44 | 46 | * Initialize a {@link RedisFeatureSink.Builder} from a {@link StoreProto.Store.RedisConfig}. |
@@ -113,30 +115,28 @@ public PCollection<FeatureSetReference> prepareWrite( |
113 | 115 |
|
114 | 116 | @Override |
115 | 117 | public PTransform<PCollection<FeatureRow>, WriteResult> writer() { |
| 118 | + int flushFrequencySeconds = DEFAULT_FREQUENCY_SECONDS; |
| 119 | + |
116 | 120 | if (getRedisClusterConfig() != null) { |
117 | | - RedisCustomIO.Write writer = |
118 | | - new RedisCustomIO.Write( |
119 | | - new RedisClusterIngestionClient(getRedisClusterConfig()), getSpecsView()); |
120 | 121 |
|
121 | 122 | if (getRedisClusterConfig().getFlushFrequencySeconds() > 0) { |
122 | | - writer = |
123 | | - writer.withFlushFrequency( |
124 | | - Duration.standardSeconds(getRedisClusterConfig().getFlushFrequencySeconds())); |
| 123 | + flushFrequencySeconds = getRedisClusterConfig().getFlushFrequencySeconds(); |
125 | 124 | } |
126 | 125 |
|
127 | | - return writer; |
128 | | - } else if (getRedisConfig() != null) { |
129 | | - RedisCustomIO.Write writer = |
130 | | - new RedisCustomIO.Write( |
131 | | - new RedisStandaloneIngestionClient(getRedisConfig()), getSpecsView()); |
| 126 | + return new RedisCustomIO.Write( |
| 127 | + new RedisClusterIngestionClient(getRedisClusterConfig()), getSpecsView()) |
| 128 | + .withFlushFrequency(Duration.standardSeconds(flushFrequencySeconds)) |
| 129 | + .withBatchSize(DEFAULT_BATCH_SIZE); |
132 | 130 |
|
| 131 | + } else if (getRedisConfig() != null) { |
133 | 132 | if (getRedisConfig().getFlushFrequencySeconds() > 0) { |
134 | | - writer = |
135 | | - writer.withFlushFrequency( |
136 | | - Duration.standardSeconds(getRedisConfig().getFlushFrequencySeconds())); |
| 133 | + flushFrequencySeconds = getRedisConfig().getFlushFrequencySeconds(); |
137 | 134 | } |
138 | 135 |
|
139 | | - return writer; |
| 136 | + return new RedisCustomIO.Write( |
| 137 | + new RedisStandaloneIngestionClient(getRedisConfig()), getSpecsView()) |
| 138 | + .withFlushFrequency(Duration.standardSeconds(flushFrequencySeconds)) |
| 139 | + .withBatchSize(DEFAULT_BATCH_SIZE); |
140 | 140 | } else { |
141 | 141 | throw new RuntimeException( |
142 | 142 | "At least one RedisConfig or RedisClusterConfig must be provided to Redis Sink"); |
|
0 commit comments