@Test public void keys() throws Exception { RKv kv = db.getrKv(); String head = "keysA"; try { Set<String> keys1 = new HashSet<>(); for (int i = 0; i < 100; i++) { kv.set(head + i, ("test" + i).getBytes()); keys1.add(head + i); } List<String> keys = kv.keys("keysA", 0, 999999); Set<String> sets = new TreeSet<>(keys); Assert.assertTrue(sets.containsAll(keys1)); Assert.assertTrue(keys1.containsAll(sets)); sets.clear(); for (int i = 0; i < 10; i++) { List<String> keys_i = kv.keys("keysA", (i * 10), 10); sets.addAll(keys_i); Assert.assertEquals(10, keys_i.size()); } Assert.assertEquals(100, sets.size()); Assert.assertTrue(sets.containsAll(keys1)); Assert.assertTrue(keys1.containsAll(sets)); } finally { kv.delPrefix(head); } }
public List<String> keys(String key_, int start, int limit) throws KitDBException { try (CloseLock ignored = checkClose()) { byte[] keyb_ = getKey(key_); List<String> list = new ArrayList<>(); int index = 0; int count = 0; try (final RocksIterator iterator = newIterator(SstColumnFamily.DEFAULT)) { byte[] head = ArrayKits.addAll(HEAD_B, keyb_); iterator.seek(head); while (iterator.isValid() && count < limit) { byte[] key = iterator.key(); if (!BytesUtil.checkHead(head, key)) break; if (index >= start) { list.add(new String(ArrayKits.sub(key, 1, key.length), charset)); count++; } index++; iterator.next(); } } return list; } }
RKv extends RBase { public List<String> keys(String key_, int start, int limit) throws KitDBException { try (CloseLock ignored = checkClose()) { byte[] keyb_ = getKey(key_); List<String> list = new ArrayList<>(); int index = 0; int count = 0; try (final RocksIterator iterator = newIterator(SstColumnFamily.DEFAULT)) { byte[] head = ArrayKits.addAll(HEAD_B, keyb_); iterator.seek(head); while (iterator.isValid() && count < limit) { byte[] key = iterator.key(); if (!BytesUtil.checkHead(head, key)) break; if (index >= start) { list.add(new String(ArrayKits.sub(key, 1, key.length), charset)); count++; } index++; iterator.next(); } } return list; } } }
RKv extends RBase { public List<String> keys(String key_, int start, int limit) throws KitDBException { try (CloseLock ignored = checkClose()) { byte[] keyb_ = getKey(key_); List<String> list = new ArrayList<>(); int index = 0; int count = 0; try (final RocksIterator iterator = newIterator(SstColumnFamily.DEFAULT)) { byte[] head = ArrayKits.addAll(HEAD_B, keyb_); iterator.seek(head); while (iterator.isValid() && count < limit) { byte[] key = iterator.key(); if (!BytesUtil.checkHead(head, key)) break; if (index >= start) { list.add(new String(ArrayKits.sub(key, 1, key.length), charset)); count++; } index++; iterator.next(); } } return list; } } protected  RKv(DB db); }
RKv extends RBase { public List<String> keys(String key_, int start, int limit) throws KitDBException { try (CloseLock ignored = checkClose()) { byte[] keyb_ = getKey(key_); List<String> list = new ArrayList<>(); int index = 0; int count = 0; try (final RocksIterator iterator = newIterator(SstColumnFamily.DEFAULT)) { byte[] head = ArrayKits.addAll(HEAD_B, keyb_); iterator.seek(head); while (iterator.isValid() && count < limit) { byte[] key = iterator.key(); if (!BytesUtil.checkHead(head, key)) break; if (index >= start) { list.add(new String(ArrayKits.sub(key, 1, key.length), charset)); count++; } index++; iterator.next(); } } return list; } } protected  RKv(DB db); void set(String key, byte[] value); long incr(String key, int step, int ttl); long incr(String key, int step); void set(Map<String, byte[]> map); void set(Map<String, byte[]> map, int ttl); void set(String key, byte[] value, int ttl); void ttl(String key, int ttl); Map<String, byte[]> get(List<String> keys); byte[] get(String key); byte[] getNoTTL(String key); void del(String key); void delPrefix(String key_); List<String> keys(String key_, int start, int limit); }
RKv extends RBase { public List<String> keys(String key_, int start, int limit) throws KitDBException { try (CloseLock ignored = checkClose()) { byte[] keyb_ = getKey(key_); List<String> list = new ArrayList<>(); int index = 0; int count = 0; try (final RocksIterator iterator = newIterator(SstColumnFamily.DEFAULT)) { byte[] head = ArrayKits.addAll(HEAD_B, keyb_); iterator.seek(head); while (iterator.isValid() && count < limit) { byte[] key = iterator.key(); if (!BytesUtil.checkHead(head, key)) break; if (index >= start) { list.add(new String(ArrayKits.sub(key, 1, key.length), charset)); count++; } index++; iterator.next(); } } return list; } } protected  RKv(DB db); void set(String key, byte[] value); long incr(String key, int step, int ttl); long incr(String key, int step); void set(Map<String, byte[]> map); void set(Map<String, byte[]> map, int ttl); void set(String key, byte[] value, int ttl); void ttl(String key, int ttl); Map<String, byte[]> get(List<String> keys); byte[] get(String key); byte[] getNoTTL(String key); void del(String key); void delPrefix(String key_); List<String> keys(String key_, int start, int limit); final static String HEAD; final static byte[] HEAD_TTL; final static byte[] HEAD_B; }