Hash 如何使用Trident存储Redis哈希键

Hash 如何使用Trident存储Redis哈希键,hash,redis,apache-storm,trident,Hash,Redis,Apache Storm,Trident,我正在进行一个实时数据项目,目前正在使用trident redis库来存储带有计数的密钥集。我想存储一些更高级的细分,包括每个关键点的纬度和经度值。使用命令行上的Redis,我可以使用: HSET 123 lat "40" HSET 123 lon "-37" 得到 1) "lat" 2) "40" 3) "lon" 4) "-37" 与 如何使用trident redis实现同样的效果? 我的拓扑结构当前如下所示: public class TridentEventTopology {

我正在进行一个实时数据项目,目前正在使用trident redis库来存储带有计数的密钥集。我想存储一些更高级的细分,包括每个关键点的纬度和经度值。使用命令行上的Redis,我可以使用:

HSET 123 lat "40"
HSET 123 lon "-37"
得到

1) "lat"
2) "40"
3) "lon"
4) "-37"

如何使用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));
    }
}

我也遇到过同样的情况。我认为您可以修改RedisState的multiput和multiget函数,在该函数中,您可以hget或hput所需的键和字段。实际上,它已经为一个固定的散列键实现了。因此,您需要做的就是从multiget或multiput键参数中提取字段

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));
    }
}