Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
R
rust-rocksdb
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fangzongwu
rust-rocksdb
Commits
6ce85985
Commit
6ce85985
authored
Jun 01, 2016
by
siddontang
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #18 from siddontang/siddontang/get-property
public get property function
parents
3f1a2a31
beda9591
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
13 deletions
+23
-13
rocksdb.rs
src/rocksdb.rs
+23
-13
No files found.
src/rocksdb.rs
View file @
6ce85985
...
@@ -207,7 +207,7 @@ impl<'a> Snapshot<'a> {
...
@@ -207,7 +207,7 @@ impl<'a> Snapshot<'a> {
let
readopts
=
ReadOptions
::
new
();
let
readopts
=
ReadOptions
::
new
();
self
.iter_opt
(
readopts
)
self
.iter_opt
(
readopts
)
}
}
pub
fn
iter_opt
(
&
self
,
mut
opt
:
ReadOptions
)
->
DBIterator
{
pub
fn
iter_opt
(
&
self
,
mut
opt
:
ReadOptions
)
->
DBIterator
{
opt
.set_snapshot
(
self
);
opt
.set_snapshot
(
self
);
DBIterator
::
new
(
self
.db
,
&
opt
)
DBIterator
::
new
(
self
.db
,
&
opt
)
...
@@ -589,7 +589,7 @@ impl DB {
...
@@ -589,7 +589,7 @@ impl DB {
let
opts
=
ReadOptions
::
new
();
let
opts
=
ReadOptions
::
new
();
self
.iter_opt
(
&
opts
)
self
.iter_opt
(
&
opts
)
}
}
pub
fn
iter_opt
(
&
self
,
opt
:
&
ReadOptions
)
->
DBIterator
{
pub
fn
iter_opt
(
&
self
,
opt
:
&
ReadOptions
)
->
DBIterator
{
DBIterator
::
new
(
&
self
,
opt
)
DBIterator
::
new
(
&
self
,
opt
)
}
}
...
@@ -823,22 +823,27 @@ impl DB {
...
@@ -823,22 +823,27 @@ impl DB {
sizes
sizes
}
}
fn
get_property_value
(
&
self
,
name
:
&
str
)
->
Option
<
String
>
{
pub
fn
get_property_value
(
&
self
,
name
:
&
str
)
->
Option
<
String
>
{
self
.get_property_value_cf_opt
(
None
,
name
)
self
.get_property_value_cf_opt
(
None
,
name
)
}
}
fn
get_property_value_cf
(
&
self
,
pub
fn
get_property_value_cf
(
&
self
,
cf
:
DBCFHandle
,
cf
:
DBCFHandle
,
name
:
&
str
)
name
:
&
str
)
->
Option
<
String
>
{
->
Option
<
String
>
{
self
.get_property_value_cf_opt
(
Some
(
cf
),
name
)
self
.get_property_value_cf_opt
(
Some
(
cf
),
name
)
}
}
fn
get_property_int
(
&
self
,
name
:
&
str
)
->
Option
<
u64
>
{
/// Return the int property in rocksdb.
/// Return None if the property not exists or not int type.
pub
fn
get_property_int
(
&
self
,
name
:
&
str
)
->
Option
<
u64
>
{
self
.get_property_int_cf_opt
(
None
,
name
)
self
.get_property_int_cf_opt
(
None
,
name
)
}
}
fn
get_property_int_cf
(
&
self
,
cf
:
DBCFHandle
,
name
:
&
str
)
->
Option
<
u64
>
{
pub
fn
get_property_int_cf
(
&
self
,
cf
:
DBCFHandle
,
name
:
&
str
)
->
Option
<
u64
>
{
self
.get_property_int_cf_opt
(
Some
(
cf
),
name
)
self
.get_property_int_cf_opt
(
Some
(
cf
),
name
)
}
}
...
@@ -876,10 +881,15 @@ impl DB {
...
@@ -876,10 +881,15 @@ impl DB {
cf
:
Option
<
DBCFHandle
>
,
cf
:
Option
<
DBCFHandle
>
,
name
:
&
str
)
name
:
&
str
)
->
Option
<
u64
>
{
->
Option
<
u64
>
{
// Rocksdb guarantee that the return property int
// Rocksdb guarantee
s
that the return property int
// value is u64 if exists.
// value is u64 if exists.
self
.get_property_value_cf_opt
(
cf
,
name
)
if
let
Some
(
value
)
=
self
.get_property_value_cf_opt
(
cf
,
name
)
{
.map
(|
value
|
value
.as_str
()
.parse
::
<
u64
>
()
.unwrap
())
if
let
Ok
(
num
)
=
value
.as_str
()
.parse
::
<
u64
>
()
{
return
Some
(
num
);
}
}
None
}
}
}
}
...
@@ -1191,7 +1201,7 @@ mod test {
...
@@ -1191,7 +1201,7 @@ mod test {
#[test]
#[test]
fn
property_test
()
{
fn
property_test
()
{
let
path
=
TempDir
::
new
(
"_rust_rocksdb_
iterator
test"
)
.expect
(
""
);
let
path
=
TempDir
::
new
(
"_rust_rocksdb_
property
test"
)
.expect
(
""
);
let
db
=
DB
::
open_default
(
path
.path
()
.to_str
()
.unwrap
())
.unwrap
();
let
db
=
DB
::
open_default
(
path
.path
()
.to_str
()
.unwrap
())
.unwrap
();
db
.put
(
b
"a1"
,
b
"v1"
)
.unwrap
();
db
.put
(
b
"a1"
,
b
"v1"
)
.unwrap
();
db
.flush
(
true
)
.unwrap
();
db
.flush
(
true
)
.unwrap
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment