我需要在IMap中动态添加string,date,int类型的某些可移植字段的索引。
为便携式对象添加索引是否需要服务器端的类定义?但是对于可移植序列化,根据文档,不需要在服务器端具有类定义。
会员配置:
<?xml version="1.0" encoding="UTF-8"?>
<hazelcast xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-3.6.xsd"
xmlns="http://www.hazelcast.com/schema/config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<group>
<name>dev</name>
<password>dev-pass</password>
</group>
<management-center enabled="true">http://localhost:8085/mancenter</management-center>
<network>
<port auto-increment="true" port-count="100">5701</port>
<outbound-ports>
<ports>0</ports>
</outbound-ports>
<join>
<multicast enabled="true">
<multicast-group>224.2.2.3</multicast-group>
<multicast-port>54327</multicast-port>
</multicast>
<discovery-strategies>
</discovery-strategies>
</join>
<interfaces enabled="false">
<interface>10.10.1.*</interface>
</interfaces>
</network>
<map name="default">
<in-memory-format>BINARY</in-memory-format>
<backup-count>1</backup-count>
<cache-deserialized-values>INDEX-ONLY</cache-deserialized-values>
</map>
<serialization>
<portable-version>0</portable-version>
</serialization>
<services enable-defaults="true"/>
<lite-member enabled="false"/>
</hazelcast>
请在下面找到客户端代码:
private static void DoMapIndexing()
{
IMap<TKey, TValue> map = GetMap<TKey, TValue>("testMap");
map.AddIndex("name", false);
map.AddIndex("DOB", true);
}
private static IMap<TKey, TValue> GetMap<TKey, TValue>(string mapName)
{
IHazelcastInstance client = getHazelcastClientConnection();
return client.GetMap<TKey, TValue>(mapName);
}
private static IHazelcastInstance getHazelcastClientConnection()
{
ClientConfig config = new ClientConfig();
config.GetNetworkConfig().AddAddress("x.x.x.x");
IDictionary<int, IPortableFactory> factoryClasses = new Dictionary<int, IPortableFactory>();
factoryClasses.Add(2000, new BusinessObjectPortableFactory());
config.GetSerializationConfig().SetPortableFactories(factoryClasses);
return HazelcastClient.NewHazelcastClient(config);
}