|
35 | 35 | import org.apache.beam.sdk.values.KV; |
36 | 36 | import org.apache.beam.sdk.values.PCollection; |
37 | 37 | import org.apache.beam.sdk.values.PCollectionView; |
| 38 | +import org.joda.time.Duration; |
38 | 39 |
|
39 | 40 | @AutoValue |
40 | 41 | public abstract class RedisFeatureSink implements FeatureSink { |
@@ -113,11 +114,29 @@ public PCollection<FeatureSetReference> prepareWrite( |
113 | 114 | @Override |
114 | 115 | public PTransform<PCollection<FeatureRow>, WriteResult> writer() { |
115 | 116 | if (getRedisClusterConfig() != null) { |
116 | | - return new RedisCustomIO.Write( |
117 | | - new RedisClusterIngestionClient(getRedisClusterConfig()), getSpecsView()); |
| 117 | + RedisCustomIO.Write writer = |
| 118 | + new RedisCustomIO.Write( |
| 119 | + new RedisClusterIngestionClient(getRedisClusterConfig()), getSpecsView()); |
| 120 | + |
| 121 | + if (getRedisClusterConfig().getFlushFrequencySeconds() > 0) { |
| 122 | + writer = |
| 123 | + writer.withFlushFrequency( |
| 124 | + Duration.standardSeconds(getRedisClusterConfig().getFlushFrequencySeconds())); |
| 125 | + } |
| 126 | + |
| 127 | + return writer; |
118 | 128 | } else if (getRedisConfig() != null) { |
119 | | - return new RedisCustomIO.Write( |
120 | | - new RedisStandaloneIngestionClient(getRedisConfig()), getSpecsView()); |
| 129 | + RedisCustomIO.Write writer = |
| 130 | + new RedisCustomIO.Write( |
| 131 | + new RedisStandaloneIngestionClient(getRedisConfig()), getSpecsView()); |
| 132 | + |
| 133 | + if (getRedisConfig().getFlushFrequencySeconds() > 0) { |
| 134 | + writer = |
| 135 | + writer.withFlushFrequency( |
| 136 | + Duration.standardSeconds(getRedisConfig().getFlushFrequencySeconds())); |
| 137 | + } |
| 138 | + |
| 139 | + return writer; |
121 | 140 | } else { |
122 | 141 | throw new RuntimeException( |
123 | 142 | "At least one RedisConfig or RedisClusterConfig must be provided to Redis Sink"); |
|
0 commit comments