gpt4 book ai didi

java - 是否可以使用 java 删除 gemfire 中的特定数据(键及其特定值)?

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:52:54 25 4
gpt4 key购买 nike

我们可以删除特定区域中的整个数据,但是是否可以删除一个特定的键及其在 gemfire 中的值,如果是,那么如何?如果没有,那是为什么

GeodeConfiguration 类

@配置公共(public)类 GeodeConfiguration {

@SuppressWarnings("rawtypes")
@Bean
Region gemfireRegion() throws InterruptedException {

ClientCache cache = new ClientCacheFactory()
.setPdxSerializer(
new ReflectionBasedAutoSerializer(PropertiesCache
.getInstance()
.getProperty("pdxSerializerValue")))
.addPoolLocator(
PropertiesCache.getInstance().getProperty("hostname"),
10334).create();
Region<String, String> region = cache
.<String, String> createClientRegionFactory(
ClientRegionShortcut.CACHING_PROXY)

.setEntryTimeToLive(new ExpirationAttributes(50))
.create(PropertiesCache.getInstance().getProperty("region"));

return region;

}

移动 Controller 类

@ Controller 公共(public)类 MobileController {

@Autowired
Operations operations;

Msg msg = new Msg();
final static Logger logger = Logger.getLogger(MobileController.class);

@RequestMapping(value = "/mobile", method = RequestMethod.POST)
public void dataFromEs(@RequestParam("name") String name,
@RequestParam("message") String message,
@RequestParam("mobileNo") String[] mobileNo) throws IOException,
JSONException {

JSONObject obj = new JSONObject();

obj.put("userName", name);
obj.put("message", message);

JSONObject mainObj = new JSONObject();

JSONArray jsonArray = new JSONArray();

for (int counter = 0; counter < mobileNo.length; counter++) {
// 1st object

JSONObject list1 = new JSONObject();
list1.put("mobilenumber", mobileNo[counter]);

jsonArray.put(list1);
}
mainObj.put("data", obj);

obj.put("mobileno", jsonArray);
logger.info("jsonString----------->: " + jsonArray);

logger.info(mainObj);

msg.setKey(name);
msg.setValue(mainObj.toString());

operations.saveMessageData(msg);

sendMSG(name);

}

public void sendMSG(String name) throws ClientProtocolException,
IOException, JSONException {

String objMobileNo;
String objMessage;
String objUserName;
String userStatus;

JSONObject root = new JSONObject(operations.getDataValue(name));

JSONObject jsonObject = root.getJSONObject("data");

objUserName = (String) jsonObject.get("userName");
objMessage = (String) jsonObject.get("message");

logger.info("UserName ----> " + objUserName);
logger.info("Message sent ---> " + objMessage);

JSONArray mobArray = jsonObject.getJSONArray("mobileno");

// now get the first element:
for (int count = 0; count < mobArray.length(); count++) {
objMobileNo = (String) mobArray.getJSONObject(count).get(
"mobilenumber");

logger.info("Mobile number ----> " + objMobileNo);

JSONObject obj = new JSONObject();
JSONObject objDraftOne = new JSONObject();
JSONObject objDraftTwo = new JSONObject();
JSONObject jsonObjectToSave = new JSONObject();
JSONObject jsonObjectToSaveDraft = new JSONObject();
JSONArray jsonArray = new JSONArray();
objDraftTwo.put("mobilenumber", objMobileNo);
jsonArray.put(objDraftTwo);
objDraftOne.put("mobileno", jsonArray);
objDraftOne.put("userName", objUserName);
objDraftOne.put("message", objMessage);
jsonObjectToSaveDraft.put("data", objDraftOne);
obj.put("userName", objUserName);
obj.put("message", objMessage);
obj.put("mobilenumber", objMobileNo);
jsonObjectToSave.put("data", obj);
HttpClient client = HttpClientBuilder.create().build();

HttpPost request = new HttpPost(
"https://xyzotp.bdt.xyz.com/sendSMS");
StringEntity params = new StringEntity(jsonObjectToSave.toString());
request.addHeader("content-type", "application/json");
request.setEntity(params);
HttpResponse response = client.execute(request);
String responseAsString = EntityUtils
.toString(response.getEntity());

JSONObject responseObjectStatus = new JSONObject(responseAsString);

userStatus = (String) responseObjectStatus.get("message");

logger.info("Message Status: " + userStatus);

if (!userStatus.equals("Message sent successfully")) {
logger.info(jsonObjectToSaveDraft);

}

}

}

在上面的代码中,name 是每次都会更改的key,我们想删除传递给它的键及其值

最佳答案

在区域上有一个删除键和值的删除方法 region.remove(key)。请阅读javadocs了解详情。

关于java - 是否可以使用 java 删除 gemfire 中的特定数据(键及其特定值)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39077104/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com