0
我正在處理實時數據項目,並且當前正在使用trident-redis庫https://github.com/kstyrc/trident-redis來存儲具有計數的鍵集。我有一些更高級的細分我想存儲,包括每個鍵的經度和緯度值。在命令行上的Redis,我可以使用:如何使用Trident存儲Redis哈希鍵
HSET 123 lat "40"
HSET 123 lon "-37"
得到
1) "lat"
2) "40"
3) "lon"
4) "-37"
與
HGETALL 123
我如何使用三叉戟的Redis實現這個同樣的效果? 我的拓撲結構目前看起來像這樣:
public class TridentEventTopology {
public static final StormTopology buildTopology(LocalDRPC drpc, StateFactory state) throws IOException {
final int batchSize = 500;
final BatchSpout spout = new BatchSpout(batchSize);
final TridentTopology topology = new TridentTopology();
TridentState batchedCounts = topology.newStream("spout", spout)
.groupBy(new Fields("id"))
.persistentAggregate(state, new Count(), new Fields("count"));
topology.newDRPCStream("stream", drpc)
.groupBy(new Fields("args"))
.stateQuery(batchedCounts, new Fields("args"), new MapGet(), new Fields("count"))
.each(new Fields("count"), new FilterNull())
.aggregate(new Fields("count"), new Sum(), new Fields("sum"));
return topology.build();
}
public static final void executeTopology() throws IOException {
final StateFactory redis = RedisState.nonTransactional(new InetSocketAddress("localhost", 6379));
final Config conf = new Config();
final LocalDRPC drpc = new LocalDRPC();
final LocalCluster cluster = new LocalCluster();
cluster.submitTopology("test", conf, buildTopology(drpc, redis));
}
}