英文:
Loading sql table data into hazelcast
问题
我正在使用Hazelcast IMap来存储我的应用程序数据。
我遇到了一个小问题。
问题说明:-
当我启动spring-boot应用程序时,我将数据库表数据加载到Hazelcast中。
示例:-
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");
但是当我获取相同的数据时,顺序不同。
那么是否有任何方法可以按插入顺序获取数据呢?
英文:
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
得分: 1
一个IMap不以排序顺序存储,因为数据内容存储在多个进程之间。
在这种情况下,可用的选项取决于您是否需要插入顺序或键顺序,因为它们可能不相同。您的代码可以这样做:
mapInstance.put(1, "value1");
mapInstance.put(2, "value2");
或者
mapInstance.put(2, "value2");
mapInstance.put(1, "value1");
因此,键顺序始终是1然后是2,但插入顺序会有所不同。
使用PagingPredicate允许您按键顺序检索。
按插入顺序检索要困难得多。EntryView可访问创建时间,但您需要自行对其进行排序。如果您的数据足够大,需要存储在多个进程上,这可能效果不佳。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论