本文整理汇总了Java中org.rocksdb.RocksDB.put方法的典型用法代码示例。如果您正苦于以下问题:Java RocksDB.put方法的具体用法?Java RocksDB.put怎么用?Java RocksDB.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.rocksdb.RocksDB
的用法示例。
在下文中一共展示了RocksDB.put方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.rocksdb.RocksDB; //导入方法依赖的package包/类
public static void main(String[] args) {
RocksDB.loadLibrary();
Options rockopts = new Options().setCreateIfMissing(true);
RocksDB db = null;
int count = 0;
try {
BufferedReader in = new BufferedReader(new FileReader(args[0]));
db = RocksDB.open(rockopts, args[1]);
String line;
while ((line = in.readLine()) != null) {
String[] fields = line.split("\\t+");
if (fields[2].endsWith("@en")) {
byte[] key = fields[0].substring(1, fields[0].length() - 1).getBytes(StandardCharsets.UTF_8);
byte[] value = fields[2].substring(1, fields[2].length() - 4).getBytes(StandardCharsets.UTF_8);
db.put(key, value);
}
count++;
if ((count % 100000) == 0)
System.out.print(".");
}
db.close();
System.out.println();
} catch (RocksDBException rdbe) {
rdbe.printStackTrace(System.err);
} catch (IOException ioe) {
ioe.printStackTrace(System.err);
}
}
示例2: multimapPut
import org.rocksdb.RocksDB; //导入方法依赖的package包/类
private void multimapPut(RocksDB db, byte[] key, byte[] value) throws RocksDBException {
byte[] current = db.get(key);
if (current != null) {
current = ByteBuffer.allocate(current.length + value.length).put(current).put(value).array();
db.delete(key);
} else {
current = value;
}
db.put(key, current);
}
示例3: rocksDbTest
import org.rocksdb.RocksDB; //导入方法依赖的package包/类
private static void rocksDbTest(RocksDB db, List<ColumnFamilyHandle> handlers) {
try {
ColumnFamilyHandle handler1 = null;
ColumnFamilyHandle handler2 = null;
if (handlers.size() > 0) {
// skip default column family
handler1 = handlers.get(1);
handler2 = handlers.get(2);
} else {
handler1 = db.createColumnFamily(new ColumnFamilyDescriptor("test1".getBytes()));
handler2 = db.createColumnFamily(new ColumnFamilyDescriptor("test2".getBytes()));
}
int startValue1 = getStartValue(db, handler1);
int startValue2 = getStartValue(db, handler2);;
Checkpoint cp = Checkpoint.create(db);
if (isCompaction) {
db.compactRange();
LOG.info("Compaction!");
}
long flushWaitTime = System.currentTimeMillis() + flushInterval;
for (int i = 0; i < putNum || putNum == -1; i++) {
db.put(handler1, String.valueOf(i % 1000).getBytes(), String.valueOf(startValue1 + i).getBytes());
db.put(handler2, String.valueOf(i % 1000).getBytes(), String.valueOf(startValue2 + i).getBytes());
if (isFlush && flushWaitTime <= System.currentTimeMillis()) {
db.flush(new FlushOptions());
if (isCheckpoint) {
cp.createCheckpoint(cpPath + "/" + i);
}
flushWaitTime = System.currentTimeMillis() + flushInterval;
}
}
} catch (RocksDBException e) {
LOG.error("Failed to put or flush", e);
}
}