将 SQL 表数据加载到 Hazelcast 中

huangapple go评论66阅读模式
英文:

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&lt;Integer, String&gt; mapInstance= hazelCast.getMap(&quot;data&quot;);

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

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,&quot;value1&quot;);
mapInstance.put(2,&quot;value2&quot;);

or

mapInstance.put(2,&quot;value2&quot;);
mapInstance.put(1,&quot;value1&quot;);

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.

huangapple
  • 本文由 发表于 2020年10月19日 15:53:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/64423209.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定