@Test public void range() throws Exception { String head = "range0"; RList list = db.getList(); int num = 10 * 10000; for (int i = 0; i < num; i++) { list.add(head, ("hello" + i).getBytes()); } int i = 1234; List<byte[]> rangs = list.range(head, i, i + i); for (int j = 0; j < i; j++) { Assert.assertEquals(("hello" + (i + j)), new String(rangs.get(j))); } }
public List<byte[]> range(String key, long start, long end) throws KitDBException { try (CloseLock ignored = checkClose()) { byte[] key_b = getKey(key); List<byte[]> list = new ArrayList<>(); MetaV metaV = getMeta(key_b); if (metaV == null) { return list; } ValueK valueK_seek = new ValueK(key_b.length, key_b, metaV.getVersion(), start); try (final RocksIterator iterator = newIterator(SstColumnFamily.DEFAULT)) { ValueKD valueKD = valueK_seek.convertValueBytes(); byte[] heads = valueKD.toHeadBytes(); iterator.seek(valueKD.toBytes()); long index = 0; while (iterator.isValid() && index < end) { byte[] key_bs = iterator.key(); if (!BytesUtil.checkHead(heads, key_bs)) break; ValueK valueK = ValueKD.build(key_bs).convertValue(); index = valueK.getIndex(); list.add(iterator.value()); iterator.next(); } } catch (Exception e) { throw e; } return list; } }
RList extends RCollection { public List<byte[]> range(String key, long start, long end) throws KitDBException { try (CloseLock ignored = checkClose()) { byte[] key_b = getKey(key); List<byte[]> list = new ArrayList<>(); MetaV metaV = getMeta(key_b); if (metaV == null) { return list; } ValueK valueK_seek = new ValueK(key_b.length, key_b, metaV.getVersion(), start); try (final RocksIterator iterator = newIterator(SstColumnFamily.DEFAULT)) { ValueKD valueKD = valueK_seek.convertValueBytes(); byte[] heads = valueKD.toHeadBytes(); iterator.seek(valueKD.toBytes()); long index = 0; while (iterator.isValid() && index < end) { byte[] key_bs = iterator.key(); if (!BytesUtil.checkHead(heads, key_bs)) break; ValueK valueK = ValueKD.build(key_bs).convertValue(); index = valueK.getIndex(); list.add(iterator.value()); iterator.next(); } } catch (Exception e) { throw e; } return list; } } }
RList extends RCollection { public List<byte[]> range(String key, long start, long end) throws KitDBException { try (CloseLock ignored = checkClose()) { byte[] key_b = getKey(key); List<byte[]> list = new ArrayList<>(); MetaV metaV = getMeta(key_b); if (metaV == null) { return list; } ValueK valueK_seek = new ValueK(key_b.length, key_b, metaV.getVersion(), start); try (final RocksIterator iterator = newIterator(SstColumnFamily.DEFAULT)) { ValueKD valueKD = valueK_seek.convertValueBytes(); byte[] heads = valueKD.toHeadBytes(); iterator.seek(valueKD.toBytes()); long index = 0; while (iterator.isValid() && index < end) { byte[] key_bs = iterator.key(); if (!BytesUtil.checkHead(heads, key_bs)) break; ValueK valueK = ValueKD.build(key_bs).convertValue(); index = valueK.getIndex(); list.add(iterator.value()); iterator.next(); } } catch (Exception e) { throw e; } return list; } } protected  RList(DB db); }
RList extends RCollection { public List<byte[]> range(String key, long start, long end) throws KitDBException { try (CloseLock ignored = checkClose()) { byte[] key_b = getKey(key); List<byte[]> list = new ArrayList<>(); MetaV metaV = getMeta(key_b); if (metaV == null) { return list; } ValueK valueK_seek = new ValueK(key_b.length, key_b, metaV.getVersion(), start); try (final RocksIterator iterator = newIterator(SstColumnFamily.DEFAULT)) { ValueKD valueKD = valueK_seek.convertValueBytes(); byte[] heads = valueKD.toHeadBytes(); iterator.seek(valueKD.toBytes()); long index = 0; while (iterator.isValid() && index < end) { byte[] key_bs = iterator.key(); if (!BytesUtil.checkHead(heads, key_bs)) break; ValueK valueK = ValueKD.build(key_bs).convertValue(); index = valueK.getIndex(); list.add(iterator.value()); iterator.next(); } } catch (Exception e) { throw e; } return list; } } protected  RList(DB db); void add(String key, byte[] v); void addAll(String key, List<byte[]> vs); void addAllMayTTL(String key, List<byte[]> vs, int ttl); void set(String key, long i, byte[] v); byte[] get(String key, long i); List<byte[]> get(String key, List<Long> is); Long left(String key); Long right(String key); int size(String key); void deleteFast(String key); void delete(String key); boolean isExist(String key); List<byte[]> range(String key, long start, long end); @Override @SuppressWarnings("unchecked") RIterator<RList> iterator(String key); Entry getEntry(RocksIterator iterator); List<byte[]> blpop(String key, int num); List<byte[]> brpop(String key, int num); @Override KeyIterator getKeyIterator(); void ttl(String key, int ttl); void delTtl(String key); int getTtl(String key); void addMayTTL(String key, byte[] v, int ttl); }
RList extends RCollection { public List<byte[]> range(String key, long start, long end) throws KitDBException { try (CloseLock ignored = checkClose()) { byte[] key_b = getKey(key); List<byte[]> list = new ArrayList<>(); MetaV metaV = getMeta(key_b); if (metaV == null) { return list; } ValueK valueK_seek = new ValueK(key_b.length, key_b, metaV.getVersion(), start); try (final RocksIterator iterator = newIterator(SstColumnFamily.DEFAULT)) { ValueKD valueKD = valueK_seek.convertValueBytes(); byte[] heads = valueKD.toHeadBytes(); iterator.seek(valueKD.toBytes()); long index = 0; while (iterator.isValid() && index < end) { byte[] key_bs = iterator.key(); if (!BytesUtil.checkHead(heads, key_bs)) break; ValueK valueK = ValueKD.build(key_bs).convertValue(); index = valueK.getIndex(); list.add(iterator.value()); iterator.next(); } } catch (Exception e) { throw e; } return list; } } protected  RList(DB db); void add(String key, byte[] v); void addAll(String key, List<byte[]> vs); void addAllMayTTL(String key, List<byte[]> vs, int ttl); void set(String key, long i, byte[] v); byte[] get(String key, long i); List<byte[]> get(String key, List<Long> is); Long left(String key); Long right(String key); int size(String key); void deleteFast(String key); void delete(String key); boolean isExist(String key); List<byte[]> range(String key, long start, long end); @Override @SuppressWarnings("unchecked") RIterator<RList> iterator(String key); Entry getEntry(RocksIterator iterator); List<byte[]> blpop(String key, int num); List<byte[]> brpop(String key, int num); @Override KeyIterator getKeyIterator(); void ttl(String key, int ttl); void delTtl(String key); int getTtl(String key); void addMayTTL(String key, byte[] v, int ttl); final static String HEAD; final static byte[] HEAD_VALUE_B; final static byte[] HEAD_B; }