我正在开发一个实时数据项目,目前正在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));
}
}
答案 0 :(得分:0)
我遇到了同样的情况。我认为您可以修改RedisState的多输出和多重功能,您可以在其中设置或输入所需的键和字段。实际上它已经实现了固定的哈希键。所以你需要做的就是从multiget或multiput key params中提取字段。