@Test public void testGetFields() { Jedis jedis = pool.getResource(); jedis.auth(password); try { ManagerExpiredHash managerExpiredHash = new ManagerExpiredHash(jedis, KEY_NAME, EXPIRE, MAX_SPAN_TIME); managerExpiredHash.addFields(FIELDS); List<String> fields = managerExpiredHash.getFields(); assertTrue(fields.size() == 0); Thread.sleep(3_000); fields = managerExpiredHash.getFields(); assertTrue(fields.size() == FIELDS.length); jedis.del(KEY_NAME); } catch (InterruptedException e) { e.printStackTrace(); } finally { pool.returnResource(jedis); } }
@Override public List<String> getFields() { Set<String> allFields = jedis.hkeys(keyName); Set<String> allKeys = jedis.keys("*"); List<String> result = new ArrayList<>(); for (String field : allFields) { if (!allKeys.contains(field)) { result.add(field); jedis.pexpire(field, expire); } } return result; }
ManagerExpiredHash implements ManagerHash { @Override public List<String> getFields() { Set<String> allFields = jedis.hkeys(keyName); Set<String> allKeys = jedis.keys("*"); List<String> result = new ArrayList<>(); for (String field : allFields) { if (!allKeys.contains(field)) { result.add(field); jedis.pexpire(field, expire); } } return result; } }
ManagerExpiredHash implements ManagerHash { @Override public List<String> getFields() { Set<String> allFields = jedis.hkeys(keyName); Set<String> allKeys = jedis.keys("*"); List<String> result = new ArrayList<>(); for (String field : allFields) { if (!allKeys.contains(field)) { result.add(field); jedis.pexpire(field, expire); } } return result; } ManagerExpiredHash(Jedis jedis, String keyName, long expire, long maxSpanTime); }
ManagerExpiredHash implements ManagerHash { @Override public List<String> getFields() { Set<String> allFields = jedis.hkeys(keyName); Set<String> allKeys = jedis.keys("*"); List<String> result = new ArrayList<>(); for (String field : allFields) { if (!allKeys.contains(field)) { result.add(field); jedis.pexpire(field, expire); } } return result; } ManagerExpiredHash(Jedis jedis, String keyName, long expire, long maxSpanTime); @Override void addField(String field); @Override void addFields(String... fields); @Override List<String> getFields(); @Override boolean isExisted(String field); @Override void delFields(); }
ManagerExpiredHash implements ManagerHash { @Override public List<String> getFields() { Set<String> allFields = jedis.hkeys(keyName); Set<String> allKeys = jedis.keys("*"); List<String> result = new ArrayList<>(); for (String field : allFields) { if (!allKeys.contains(field)) { result.add(field); jedis.pexpire(field, expire); } } return result; } ManagerExpiredHash(Jedis jedis, String keyName, long expire, long maxSpanTime); @Override void addField(String field); @Override void addFields(String... fields); @Override List<String> getFields(); @Override boolean isExisted(String field); @Override void delFields();  }