use of doitincloud.rdbcache.supports.Context in project rdbcache by rdbcache.
the class RdbcacheApis method get_get.
/**
* get_get get single item
*
* To get data based on key and/or query string.
* Once data found, it returns immediately. It queries redis first, then database.
*
* @param request HttpServletRequest
* @param key String, hash key
* @param opt1 String, can be expire or table or "sync" or "async"
* @param opt2 String, can be expire or table or "sync" or "async", but not otp1
* @param opt3 String, can be expire or table or "sync" or "async", but not otp1 and opt2
* @return ResponseEntity
*/
@RequestMapping(value = { "/rdbcache/v1/get/{key}", "/rdbcache/v1/get/{key}/{opt1}", "/rdbcache/v1/get/{key}/{opt1}/{opt2}", "/rdbcache/v1/get/{key}/{opt1}/{opt2}/{opt3}" }, method = RequestMethod.GET)
public ResponseEntity<?> get_get(HttpServletRequest request, @PathVariable("key") String key, @PathVariable Optional<String> opt1, @PathVariable Optional<String> opt2, @PathVariable Optional<String> opt3) {
Context context = new Context(true);
KvPairs pairs = new KvPairs(key);
AnyKey anyKey = Request.process(context, request, pairs, opt1, opt2, opt3);
LOGGER.trace(anyKey.print() + " pairs(" + pairs.size() + "): " + pairs.printKey());
if (key.equals("*")) {
if (AppCtx.getDbaseRepo().find(context, pairs, anyKey)) {
AppCtx.getAsyncOps().doSaveToRedis(context, pairs, anyKey);
} else {
throw new NotFoundException(context, "data not found");
}
} else {
if (!AppCtx.getRedisRepo().find(context, pairs, anyKey)) {
if (AppCtx.getDbaseRepo().find(context, pairs, anyKey)) {
AppCtx.getAsyncOps().doSaveToRedis(context, pairs, anyKey);
} else {
throw new NotFoundException(context, "data not found");
}
}
}
return Response.send(context, pairs);
}
use of doitincloud.rdbcache.supports.Context in project rdbcache by rdbcache.
the class RequestTest method process1.
@Test
public void process1() {
try {
String key = "*";
Optional<String> tableOpt = Optional.of("tb1");
Optional<String> expireOpt = Optional.of("30");
String queryString = "id=1";
HttpServletRequest request = getRequest("get", key, null, tableOpt, expireOpt, queryString);
Context context = new Context();
AnyKey anyKey = Request.process(context, request, new KvPairs(key), tableOpt, expireOpt);
assertEquals(1, anyKey.size());
KeyInfo keyInfo = anyKey.getKeyInfo();
assertTrue(keyInfo.getIsNew());
assertEquals("KeyInfo(true, tb1, 30, {id: {=: [1]}})", keyInfo.toString());
} catch (Exception e) {
e.printStackTrace();
fail(e.getCause().getMessage());
}
}
use of doitincloud.rdbcache.supports.Context in project rdbcache by rdbcache.
the class RTQueryApis method queryConfigurations.
/**
* query configurations
*
* @param request HttpServletRequest
* @return ResponseEntity
*/
@RequestMapping(value = { "/rtquery/v1/configurations", "/rtquery/v1/configurations/{nameOpt}" }, method = RequestMethod.GET)
public ResponseEntity<?> queryConfigurations(HttpServletRequest request, @PathVariable Optional<String> nameOpt) {
Context context = new Context();
Request.process(context, request);
Map<String, Object> data = Utils.toMap(PropCfg.printConfigurations());
if (nameOpt.isPresent()) {
Map<String, Object> map = new LinkedHashMap<String, Object>();
String key = nameOpt.get();
map.put(key, data.get(key));
data = map;
}
return Response.send(context, data);
}
Aggregations