forked from sorccu/r2d2-redis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcounter.rs
More file actions
29 lines (22 loc) · 663 Bytes
/
Copy pathcounter.rs
File metadata and controls
29 lines (22 loc) · 663 Bytes
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
extern crate r2d2_redis;
use std::thread;
use r2d2_redis::{r2d2, redis, RedisConnectionManager};
use redis::Commands;
fn main() {
let manager = RedisConnectionManager::new("redis://localhost").unwrap();
let pool = r2d2::Pool::builder()
.build(manager)
.unwrap();
let mut handles = vec![];
for _i in 0..10i32 {
let pool = pool.clone();
handles.push(thread::spawn(move || {
let mut conn = pool.get().unwrap();
let n: i64 = conn.incr("counter", 1).unwrap();
println!("Counter increased to {}", n);
}));
}
for h in handles {
h.join().unwrap();
}
}