use of com.rdbcache.models.KeyInfo in project rdbcache by rdbcache.
the class UtilsTest method toPojoTest.
@Test
public void toPojoTest() {
KeyInfo keyInfo1 = new KeyInfo();
keyInfo1.setExpire("100");
keyInfo1.setTable("table");
Map<String, Object> map = Utils.toMap(keyInfo1);
KeyInfo keyInfo2 = Utils.toPojo(map, KeyInfo.class);
assertEquals(keyInfo1, keyInfo2);
}
use of com.rdbcache.models.KeyInfo in project rdbcache by rdbcache.
the class UtilsTest method toMapTestWithPojo.
@Test
public void toMapTestWithPojo() {
KeyInfo keyInfo = new KeyInfo();
keyInfo.setExpire("100");
keyInfo.setTable("table");
keyInfo.cleanup();
Map<String, Object> map = Utils.toMap(keyInfo);
// System.out.println(Utils.toJsonMap(map));
assertNotNull(map.get("created_at"));
map.remove("created_at");
String json = "{\"expire\":\"100\",\"table\":\"table\",\"clause\":\"\",\"query_key\":\"\",\"is_new\":false}";
Map<String, Object> newMap = Utils.toMap(json);
assertEquals(map, newMap);
}
use of com.rdbcache.models.KeyInfo in project rdbcache by rdbcache.
the class RdbcacheApis method delkey_post.
/**
* delkey_post post multiple items
*
* To delete one or more keys from redis based on the input keys. No query string.
* It returns immediately. It will not delete database entry.
*
* @param request HttpServletRequest
* @param keys List, list of keys for returned entries
* @param opt1 String, can be sync only
* @return ResponseEntity
*/
@RequestMapping(value = { "/rdbcache/v1/delkey", "/rdbcache/v1/delkey/{opt1}" }, method = RequestMethod.POST)
public ResponseEntity<?> delkey_post(HttpServletRequest request, @RequestBody List<String> keys, @PathVariable Optional<String> opt1) {
if (keys.contains("*")) {
throw new BadRequestException("no * allowed as key");
}
if (opt1.isPresent() && !"sync".equals(opt1.get())) {
throw new BadRequestException("only option allowed is sync");
}
Context context = new Context();
KvPairs pairs = new KvPairs(keys);
AnyKey anyKey = Request.process(context, request, pairs);
if (anyKey.size() != keys.size()) {
context.logTraceMessage("one or more keys not found");
}
if (opt1.isPresent() && !"sync".equals(opt1.get())) {
throw new BadRequestException("only option allowed is sync");
}
for (int i = 0; i < anyKey.size(); i++) {
KvPair pair = pairs.get(i);
KeyInfo keyInfo = anyKey.get(i);
if (keyInfo.getIsNew()) {
context.logTraceMessage("key not found for " + pair.getId());
}
}
LOGGER.trace(anyKey.print() + " pairs(" + pairs.size() + "): " + pairs.printKey());
AppCtx.getAsyncOps().doDeleteFromRedis(context, pairs, anyKey);
return Response.send(context, pairs);
}
use of com.rdbcache.models.KeyInfo in project rdbcache by rdbcache.
the class RdbcacheApis method delall_post.
/**
* delall_post post multple items
*
* To delete one or more keys from redis and database based on the input keys. No query string.
* It returns immediately.
*
* @param request HttpServletRequest
* @param keys List, list of keys for returned entries
* @param opt1 String, can be sync only
* @return ResponseEntity
*/
@RequestMapping(value = { "/rdbcache/v1/delall", "/rdbcache/v1/delall/{opt1}" }, method = RequestMethod.POST)
public ResponseEntity<?> delall_post(HttpServletRequest request, @RequestBody List<String> keys, @PathVariable Optional<String> opt1) {
if (keys.contains("*")) {
throw new BadRequestException("no * allowed as key");
}
if (opt1.isPresent() && !"sync".equals(opt1.get())) {
throw new BadRequestException("only option allowed is sync");
}
Context context = new Context();
KvPairs pairs = new KvPairs(keys);
AnyKey anyKey = Request.process(context, request, pairs);
if (anyKey.size() != keys.size()) {
context.logTraceMessage("one or more keys not found");
}
for (int i = 0; i < anyKey.size(); i++) {
KvPair pair = pairs.get(i);
KeyInfo keyInfo = anyKey.get(i);
if (keyInfo.getIsNew()) {
context.logTraceMessage("key not found for " + pair.getId());
}
}
AppCtx.getAsyncOps().doDeleteFromRedisAndDbase(context, pairs, anyKey);
return Response.send(context, pairs);
}
use of com.rdbcache.models.KeyInfo in project rdbcache by rdbcache.
the class RdbcacheApis method select_post.
/**
* select_post post multiple items
*
* To select one or more entries based on query string.
* It queries database and return immediately, and asynchronously saves the data to redis
*
* @param request HttpServletRequest
* @param opt1 String, can be expire or table
* @param opt2 String, can be expire or table, but not otp1
* @param keys List, list of keys for returned entries
* @return ResponseEntity
*/
@RequestMapping(value = { "/rdbcache/v1/select", "/rdbcache/v1/select/{opt1}", "/rdbcache/v1/select/{opt1}/{opt2}" }, method = RequestMethod.POST)
public ResponseEntity<?> select_post(HttpServletRequest request, @PathVariable Optional<String> opt1, @PathVariable Optional<String> opt2, @RequestBody ArrayList<String> keys) {
Context context = new Context(true, true);
KvPairs pairs = new KvPairs(keys);
AnyKey anyKey = Request.process(context, request, pairs, opt1, opt2);
LOGGER.trace(anyKey.print() + " pairs(" + pairs.size() + "): " + pairs.printKey());
KeyInfo keyInfo = anyKey.getKeyInfo();
if (keyInfo.getQuery() == null && pairs.size() == 0) {
QueryInfo query = new QueryInfo(keyInfo.getTable());
query.setLimit(1024);
keyInfo.setQuery(query);
String msg = "no query string found, max rows limit is forced to 1024";
LOGGER.info(msg);
context.logTraceMessage(msg);
}
if (!AppCtx.getDbaseRepo().find(context, pairs, anyKey)) {
LOGGER.debug("no record(s) found from database");
} else {
AppCtx.getAsyncOps().doSaveToRedis(context, pairs, anyKey);
}
return Response.send(context, pairs);
}
Aggregations