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
765bca89
Commit
765bca89
authored
Jan 03, 2016
by
Pete Hunt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update README
parent
09250315
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
9 deletions
+16
-9
README.md
README.md
+16
-9
No files found.
README.md
View file @
765bca89
...
@@ -49,7 +49,7 @@ fn main() {
...
@@ -49,7 +49,7 @@ fn main() {
match
db
.get
(
b
"my key"
)
{
match
db
.get
(
b
"my key"
)
{
Ok
(
Some
(
value
))
=>
println!
(
"retrieved value {}"
,
value
.to_utf8
()
.unwrap
()),
Ok
(
Some
(
value
))
=>
println!
(
"retrieved value {}"
,
value
.to_utf8
()
.unwrap
()),
Ok
(
None
)
=>
println!
(
"value not found"
),
Ok
(
None
)
=>
println!
(
"value not found"
),
Err
(
e
)
=>
println!
(
"operational problem encountered: {}"
,
e
),
Err
(
e
)
=>
println!
(
"operational problem encountered: {}"
,
e
),
}
}
db
.delete
(
b
"my key"
);
db
.delete
(
b
"my key"
);
...
@@ -77,25 +77,33 @@ fn main() {
...
@@ -77,25 +77,33 @@ fn main() {
###### Getting an Iterator
###### Getting an Iterator
```
rust
```
rust
extern
crate
rocksdb
;
extern
crate
rocksdb
;
use
rocksdb
::{
DB
,
Direction
};
use
rocksdb
::{
DB
,
Direction
,
IteratorMode
};
fn
main
()
{
fn
main
()
{
// NB: db is automatically freed at end of lifetime
// NB: db is automatically freed at end of lifetime
let
mut
db
=
DB
::
open_default
(
"/path/for/rocksdb/storage"
)
.unwrap
();
let
mut
db
=
DB
::
open_default
(
"/path/for/rocksdb/storage"
)
.unwrap
();
let
mut
iter
=
db
.iterator
(
);
let
mut
iter
=
db
.iterator
(
IteratorMode
::
Start
);
// Always iterates forward
for
(
key
,
value
)
in
iter
.from_start
()
{
// Always iterates forward
for
(
key
,
value
)
in
iter
{
println!
(
"Saw {} {}"
,
key
,
value
);
//actually, need to convert [u8] keys into Strings
println!
(
"Saw {} {}"
,
key
,
value
);
//actually, need to convert [u8] keys into Strings
}
}
for
(
key
,
value
)
in
iter
.from_end
()
{
//Always iterates backward
iter
=
db
.iterator
(
IteratorMode
::
End
);
// Always iterates backward
for
(
key
,
value
)
in
iter
{
println!
(
"Saw {} {}"
,
key
,
value
);
}
iter
=
db
.iterator
(
IteratorMode
::
From
(
b
"my key"
,
Direction
::
forward
));
// From a key in Direction::{forward,reverse}
for
(
key
,
value
)
in
iter
{
println!
(
"Saw {} {}"
,
key
,
value
);
println!
(
"Saw {} {}"
,
key
,
value
);
}
}
for
(
key
,
value
)
in
iter
.from
(
b
"my key"
,
Direction
::
forward
)
{
// From a key in Direction::{forward,reverse}
// You can seek with an existing Iterator instance, too
iter
.set_mode
(
IteratorMode
::
From
(
b
"another key"
,
Direction
::
reverse
));
for
(
key
,
value
)
in
iter
{
println!
(
"Saw {} {}"
,
key
,
value
);
println!
(
"Saw {} {}"
,
key
,
value
);
}
}
}
}
```
```
###### Getting an Iterator
###### Getting an Iterator
from a Snapshot
```
rust
```
rust
extern
crate
rocksdb
;
extern
crate
rocksdb
;
use
rocksdb
::{
DB
,
Direction
};
use
rocksdb
::{
DB
,
Direction
};
...
@@ -104,7 +112,7 @@ fn main() {
...
@@ -104,7 +112,7 @@ fn main() {
// NB: db is automatically freed at end of lifetime
// NB: db is automatically freed at end of lifetime
let
mut
db
=
DB
::
open_default
(
"/path/for/rocksdb/storage"
)
.unwrap
();
let
mut
db
=
DB
::
open_default
(
"/path/for/rocksdb/storage"
)
.unwrap
();
let
snapshot
=
db
.snapshot
();
// Creates a longer-term snapshot of the DB, but freed when goes out of scope
let
snapshot
=
db
.snapshot
();
// Creates a longer-term snapshot of the DB, but freed when goes out of scope
let
mut
iter
=
snapshot
.iterator
();
// Make as many iterators as you'd like from one snapshot
let
mut
iter
=
snapshot
.iterator
(
IteratorMode
::
Start
);
// Make as many iterators as you'd like from one snapshot
}
}
```
```
...
@@ -176,4 +184,3 @@ fn badly_tuned_for_somebody_elses_disk() -> DB {
...
@@ -176,4 +184,3 @@ fn badly_tuned_for_somebody_elses_disk() -> DB {
DB
::
open
(
&
opts
,
path
)
.unwrap
()
DB
::
open
(
&
opts
,
path
)
.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