forked from redis-rs/redis-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
67 lines (50 loc) · 1.71 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
redis-rs // A High Level Redis Library for Rust
redis-rs provides both low level access to redis functionality
as well as high level wrappers around them. It supports simple
multi-connection handling to allow different tasks to all
connect to redis. (Currently without pooling)
To build:
$ make
To test:
$ make test
To compile and run the example:
$ make example
$ ./build/redis-example
Low-level example:
extern crate redis;
use std::str::from_utf8;
fn main() {
let client = redis::Client::open("redis://127.0.0.1/").unwrap();
let mut con = client.get_connection().unwrap();
con.send_command("GET", [redis::StrArg("my_key")]);
match con.read_response() {
redis::Data(value) => {
println!("Got value: {}", from_utf8(value).unwrap());
},
redis::Error(redis::ResponseError, msg) => {
fail!(format!("Redis command failed: {}", msg));
},
_ => {
println!("Did not get value :-(");
}
}
}
High-level example:
extern crate redis;
fn main() {
let client = redis::Client::open("redis://127.0.0.1/").unwrap();
let mut con = client.get_connection().unwrap();
println!("Got value: {}", con.get("my_key").unwrap_or("<no value>"));
}
Scanning over all keys iteratively:
extern crate redis;
fn main() {
let client = redis::Client::open("redis://127.0.0.1/").unwrap();
let mut con = client.get_connection().unwrap();
println!("iterate over all keys starting with 'key:':");
for item in con.scan("key:*") {
println!(" > {}", item);
// note that keys might appear more than once due to how redis
// stateless cursors are implemented.
}
}