mirror of
https://gitee.com/BDWare/agent-backend
synced 2025-01-10 01:44:14 +00:00
38 lines
958 B
Plaintext
38 lines
958 B
Plaintext
|
@Permission("RocksDB")
|
|||
|
@Description("这是个使用RocksDB的参考代码")
|
|||
|
contract RocksDBSample{
|
|||
|
function onCreate(){
|
|||
|
Global.rocksdb = RocksDBUtil.loadDB("./dbdir/","false");
|
|||
|
}
|
|||
|
@Description("示例参数: {\"key\":\"abc\",\"value\":\"def\"}")
|
|||
|
export function put(arg){
|
|||
|
arg = JSON.parse(arg);
|
|||
|
Global.rocksdb.put(arg.key,arg.value);
|
|||
|
return "success";
|
|||
|
}
|
|||
|
@Description("示例参数: \"abc\"}")
|
|||
|
export function get(arg){
|
|||
|
|
|||
|
return Global.rocksdb.get(arg);
|
|||
|
|
|||
|
return "failed";
|
|||
|
}
|
|||
|
|
|||
|
@Description("示例参数: \"abc\"")
|
|||
|
export function deleteKey(arg){
|
|||
|
return Global.rocksdb.delete(arg);
|
|||
|
}
|
|||
|
@Description("遍历KV库,无需参数")
|
|||
|
export function iter(arg){
|
|||
|
var iter = Global.rocksdb.newIterator();
|
|||
|
var obj = undefined;
|
|||
|
|
|||
|
var ret = {
|
|||
|
};
|
|||
|
for (iter.seekToFirst();(obj=Global.rocksdb.getNext(iter))!=undefined;){
|
|||
|
ret[obj.key]=obj.value;
|
|||
|
}
|
|||
|
return JSON.stringify(ret)
|
|||
|
}
|
|||
|
}
|