2023-06-08 20:33:05 +00:00
|
|
|
///
|
|
|
|
/// $ cargo run --example simple_client
|
|
|
|
///
|
2023-06-01 21:47:38 +00:00
|
|
|
use redis::{
|
|
|
|
//RedisResult,
|
|
|
|
Client,
|
|
|
|
Commands,
|
|
|
|
Connection,
|
|
|
|
};
|
2024-08-17 13:50:43 +00:00
|
|
|
use std::thread::sleep;
|
|
|
|
use std::time::{Duration, Instant};
|
2023-06-08 20:23:01 +00:00
|
|
|
|
2024-08-19 12:46:25 +00:00
|
|
|
const SCALE: f32 = 20.0;
|
2024-08-19 08:56:33 +00:00
|
|
|
|
2023-06-01 21:47:38 +00:00
|
|
|
fn do_something() -> redis::RedisResult<()> {
|
|
|
|
let client = Client::open("redis://127.0.0.1/")?;
|
|
|
|
let mut con: Connection = client.get_connection()?;
|
2023-06-08 20:23:01 +00:00
|
|
|
let start = Instant::now();
|
2024-08-17 13:50:43 +00:00
|
|
|
|
2023-06-08 20:23:01 +00:00
|
|
|
loop {
|
2024-08-17 13:50:43 +00:00
|
|
|
let elapsed = start.elapsed();
|
|
|
|
let time = 60.0 * elapsed.as_millis() as f32 / 5_000.0;
|
|
|
|
|
|
|
|
let mut v: Vec<(f32, f32, u32)> = vec![];
|
2023-06-08 20:23:01 +00:00
|
|
|
|
2024-08-17 13:50:43 +00:00
|
|
|
for i in 0..128 {
|
|
|
|
let a = (time + i as f32) / 128.0 * std::f32::consts::PI * 2.0;
|
2024-08-19 08:56:33 +00:00
|
|
|
let r = 24.0 * SCALE + (a * 5.0).cos() * (10.0 * SCALE * (time / 5.0).cos());
|
2023-06-08 20:23:01 +00:00
|
|
|
|
2024-08-17 13:50:43 +00:00
|
|
|
let x = a.cos() * r;
|
|
|
|
let y = a.sin() * r;
|
|
|
|
let col = if i % 8 < 4 { 0x000000ff } else { 0x00ff0000 };
|
|
|
|
v.push((x, y, col));
|
|
|
|
}
|
|
|
|
// println!("{:?}", v);
|
|
|
|
let _ = con.set("/pl/0/0", format!("{:?}", v))?;
|
|
|
|
sleep(Duration::from_millis(100));
|
2023-06-08 20:23:01 +00:00
|
|
|
}
|
|
|
|
// Ok(())
|
2023-06-01 21:47:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2023-06-04 13:09:15 +00:00
|
|
|
_ = do_something();
|
2023-06-01 21:47:38 +00:00
|
|
|
}
|