将Java类放入GemFire键值结构中的步骤如下:
import java.io.Serializable;
public class Person implements Serializable {
private String name;
private int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
// Getters and setters
@Override
public String toString() {
return "Person [name=" + name + ", age=" + age + "]";
}
}
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.CacheFactory;
import org.apache.geode.cache.Region;
public class GemFireExample {
public static void main(String[] args) {
// 创建缓存
Cache cache = new CacheFactory().create();
// 创建区域
Region<String, Person> region = cache.<String, Person>createRegionFactory().create("personRegion");
// 将Java类放入GemFire键值结构中
Person person = new Person("John", 30);
region.put("1", person);
// 从GemFire中获取Java类
Person retrievedPerson = region.get("1");
System.out.println(retrievedPerson);
// 关闭缓存
cache.close();
}
}
领取专属 10元无门槛券
手把手带您无忧上云