将SQL表数据加载到hazelcast中 [英] Loading sql table data into hazelcast

查看:59
本文介绍了将SQL表数据加载到hazelcast中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用hazelcast IMap存储我的应用程序数据.

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

我面临的是小问题.

问题说明:-

启动spring-boot应用程序时,我正在将数据库表数据加载到hazelcast中.

When I start the spring-boot application I'm loading database table data into 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");

但是当我获取相同的数据时,我得到的顺序却不同.

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?

推荐答案

一个

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

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

因此键顺序始终为1,然后为2,但插入顺序将有所不同.

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

使用 PagingPredicate 将允许您按键顺序进行检索.

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

按插入顺序检索会困难得多.通过 EntryView 可以访问创建时间,但您需要自己对此进行排序.如果您的数据足够大,需要将其存储在多个进程中,则可能无法正常工作.

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.

这篇关于将SQL表数据加载到hazelcast中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆