Loading sql table data into hazelcast

ぐ巨炮叔叔 提交于 2021-02-10 14:22:16

问题


I'm using hazelcast IMap to store my application data.

I'm facing small issue.

Problem explanation:-

When I start the spring-boot application I'm loading database table data into hazelcast.

example:-

HazelcastInstance hazelCast = Hazelcast.getOrCreateHazelcastInstance(HazelcastConfig.getConfig());
IMap<Integer, String> mapInstance= hazelCast.getMap("data");

mapInstance.put(1,"value1");
mapInstance.put(2,"value2");
mapInstance.put(3,"value3");
mapInstance.put(4,"value4");

But when I fetch same data I'm getting in the different order.

So is there any way to get the data in the inserted order?


回答1:


An IMap is not stored in sorted order, as the data content is stored across multiple processes.

What options are then available depend on whether you need insertion order or key order, as these might not be the same. You code could do

mapInstance.put(1,"value1");
mapInstance.put(2,"value2");

or

mapInstance.put(2,"value2");
mapInstance.put(1,"value1");

so key order would always be 1 then 2, but insertion order would differ.

Using the PagingPredicate would allow you to retrieve by key order.

Retrieving by insertion order would be much harder. The EntryView gives access to the creation time, but you'd need to sort on this yourself. If your data is sufficiently big that it needs stored on multiple processes, this might not work well.



来源:https://stackoverflow.com/questions/64423209/loading-sql-table-data-into-hazelcast

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!