我正在做一个实时数据项目,目前正在使用https://github.com/kstyrc/trident-redis上的 trident-redis 库来存储带有计数的键集。我想存储一些更高级的细分,包括每个键的纬度和经度值。在命令行上使用 Redis,我可以使用:
HSET 123 lat "40"
HSET 123 lon "-37"
要得到
1) "lat"
2) "40"
3) "lon"
4) "-37"
和
HGETALL 123
如何使用 trident-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));
}
}