use of com.rdbcache.models.KeyInfo in project rdbcache by rdbcache.
the class Query method ifUpdateOk.
public boolean ifUpdateOk() {
Assert.isTrue(anyKey.size() == pairs.size(), anyKey.size() + " != " + pairs.size() + ", update only supports anyKey size == pairs size");
KeyInfo keyInfo = anyKey.getKeyInfo();
String table = keyInfo.getTable();
if (table == null) {
return false;
}
String queryKey = keyInfo.getQueryKey();
if (queryKey == null) {
return false;
}
return true;
}
use of com.rdbcache.models.KeyInfo in project rdbcache by rdbcache.
the class Query method ifInsertOk.
public boolean ifInsertOk() {
Assert.isTrue(anyKey.size() == 1, "anyKey.size() = " + anyKey.size() + ", insert only supports anyKey size == 1");
KeyInfo keyInfo = anyKey.getKeyInfo();
String table = keyInfo.getTable();
if (table == null) {
return false;
}
String queryKey = keyInfo.getQueryKey();
if (queryKey == null) {
return false;
}
return true;
}
use of com.rdbcache.models.KeyInfo in project rdbcache by rdbcache.
the class Query method getLimit.
private int getLimit() {
KeyInfo keyInfo = anyKey.getKeyInfo();
Integer queryLimit = keyInfo.getQueryLimit();
int size = pairs.size();
int limit = 0;
if (queryLimit != null || size > 0) {
if (size == 0) {
limit = queryLimit;
} else if (queryLimit != null && size > queryLimit) {
limit = queryLimit;
} else {
limit = size;
}
}
if (limit == 0 && !context.isBatch()) {
limit = 1;
}
return limit;
}
use of com.rdbcache.models.KeyInfo in project rdbcache by rdbcache.
the class RedisRepoImpl method find.
@Override
public boolean find(Context context, KvPairs pairs, AnyKey anyKey) {
LOGGER.trace("find pairs(" + pairs.size() + "): " + pairs.printKey() + "anyKey(" + anyKey.size() + "): " + anyKey.printTable());
boolean foundAll = true;
for (int i = 0; i < pairs.size(); i++) {
KvPair pair = pairs.get(i);
String key = pair.getId();
KeyInfo keyInfo = anyKey.getAny(i);
String hashKey = hdataPrefix + "::" + key;
Map<String, Object> map = null;
if (enableDataCache) {
map = (Map<String, Object>) AppCtx.getLocalCache().getData(key);
if (map != null && map.size() > 0) {
LOGGER.debug("find - found from cache " + key);
}
}
if (map == null) {
StopWatch stopWatch = context.startStopWatch("redis", "hashOps.entries");
try {
map = hashOps.entries(hashKey);
if (stopWatch != null)
stopWatch.stopNow();
if (map != null && map.size() > 0) {
if (enableDataCache) {
AppCtx.getLocalCache().putData(pair, keyInfo);
}
LOGGER.debug("find - found from redis " + key);
}
} catch (Exception e) {
if (stopWatch != null)
stopWatch.stopNow();
foundAll = false;
String msg = e.getCause().getMessage();
LOGGER.error(msg);
context.logTraceMessage(msg);
e.printStackTrace();
if (context.isSync()) {
throw new ServerErrorException(context, msg);
}
continue;
}
}
if (map == null || map.size() == 0) {
foundAll = false;
LOGGER.debug("find - not found " + key);
continue;
}
pair.setData(map);
}
LOGGER.trace("find returns " + foundAll);
return foundAll;
}
use of com.rdbcache.models.KeyInfo in project rdbcache by rdbcache.
the class ExpireOps method setExpireKey.
// set up expire key
//
// expire = X, it schedules an event in X seconds, only if not such event exists.
// The expiration event will happen at X seconds.
//
// expire = +X, it schedules an event in X seconds always, even if such event exists.
// It may use to delay the event, if next call happens before X seconds.
//
// expire = -X, it schedules a repeat event to occur every X seconds.
//
// expire = 0, it removes existing event and not to set any event
//
public void setExpireKey(Context context, KvPairs pairs, AnyKey anyKey) {
for (int i = 0; i < pairs.size(); i++) {
try {
KvPair pair = pairs.get(i);
String key = pair.getId();
KeyInfo keyInfo = anyKey.getAny(i);
LOGGER.trace("setExpireKey: " + pair.printKey() + " expire: " + keyInfo.getExpire());
String expire = keyInfo.getExpire();
String expKey = eventPrefix + "::" + key;
StopWatch stopWatch = context.startStopWatch("redis", "scriptExecutor.execute");
Long result = scriptExecutor.execute(set_expire_key_script, Collections.singletonList(expKey), context.getTraceId(), expire);
if (stopWatch != null)
stopWatch.stopNow();
if (result != 1) {
keyInfo.restoreExpire();
}
if (keyInfo.getIsNew()) {
AppCtx.getKeyInfoRepo().save(context, new KvPairs(pair), new AnyKey(keyInfo));
}
} catch (Exception e) {
String msg = e.getCause().getMessage();
LOGGER.error(msg);
context.logTraceMessage(msg);
}
}
}
Aggregations