@Override public long countBetween(T t, Long scoreStart, Long scoreEnd) { try { Long count = getRao() .zcardBetween( t.getHashKey(), t.getKeyType(), (Double) scoreStart.doubleValue(), (Double) scoreEnd.doubleValue()); if (null != count) { return count; } } catch (Exception e) { logger.warn("index cache error", e); } recover(t); return getRao() .zcardBetween( t.getHashKey(), t.getKeyType(), (Double) scoreStart.doubleValue(), (Double) scoreEnd.doubleValue()); }
@Override public List<T> findByPage(T t, int pageno, int pagesize, int asc) { try { List<T> ts = getRao().findByPage(t.getHashKey(), t.getKeyType(), pageno, pagesize, asc); if (null != ts) { return ts; } } catch (Exception e) { logger.warn("index cache error", e); } recover(t); return getRao().findByPage(t.getHashKey(), t.getKeyType(), pageno, pagesize, asc); }
public List<T> findNext(T t, Long nt, int count, int asc) { try { List<T> ts = getRao().findNext(t.getHashKey(), t.getKeyType(), nt, count, asc); if (null != ts) { return ts; } } catch (Exception e) { logger.warn("index cache error", e); } recover(t); return getRao().findNext(t.getHashKey(), t.getKeyType(), nt, count, asc); }
@Override public Long getScore(T t) { try { Long score = getRao().zscore(t); if (score != null) { return score; } } catch (Exception e) { logger.warn("index cache error", e); } Long score = null; List<T> ts = getDao().query(t, null, t.getConditionsOfQueryAll()); if (ts != null && !ts.isEmpty()) { for (T et : ts) { if (t.equalIndex(et)) { score = et.getScore(); } fillScore(et); } } try { getRao().zaddall(t.getHashKey(), t.getKeyType(), ts); } catch (Exception e) { logger.warn("index cache error", e); } return score; }
@Override public boolean exist(T t) { Boolean exist = null; try { exist = getRao().exist(t); if (exist != null) { return exist; } } catch (Exception e) { logger.warn("index cache error", e); } exist = false; List<T> ts = getDao().query(t, null, t.getConditionsOfQueryAll()); if (ts != null && !ts.isEmpty()) { for (T et : ts) { if (t.equalIndex(et)) { exist = true; } fillScore(et); } } try { getRao().zaddall(t.getHashKey(), t.getKeyType(), ts); } catch (Exception e) { logger.warn("index cache error", e); } return exist; }
@Override public long count(T t) { try { Long count = getRao().zcard(t.getHashKey(), t.getKeyType()); if (null != count) { return count; } } catch (Exception e) { logger.warn("index cache error", e); } return recover(t); }
private int recover(T t) { // TODO:zk锁对象 Long count = getRao().zcard(t.getHashKey(), t.getKeyType()); if (count != null) { return count.intValue(); } List<T> ts = getDao().query(t, null, t.getConditionsOfQueryAll()); int result = 0; if (ts != null && !ts.isEmpty()) { for (T t2 : ts) { fillScore(t2); } } try { getRao().zaddall(t.getHashKey(), t.getKeyType(), ts); result = ts.size(); } catch (Exception e) { logger.warn("index cache error", e); } return result; }