Skip to content

Commit 9b82cf2

Browse files
ZeWakaitsmeow
authored andcommitted
Adds a redis reliable queue implementation (tgstation#133)
* adds project to vscode rust-analyzer config it asked me to * redis reliable queue implementation * readme * cleanup * shit fixed * proper redis response handling for lpop * more clean * okay better handling i GUESS * updated redis crate, all my tests pass breaking changes don't apply either * update the cargo lock to 2.0.0 * ignore clippy for the redis_lpush match return * fixes cellularnoise clippy lints
1 parent 8790918 commit 9b82cf2

File tree

9 files changed

+237
-52
lines changed

9 files changed

+237
-52
lines changed

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
{
2-
"rust-analyzer.cargo.target": "i686-pc-windows-msvc"
2+
"rust-analyzer.cargo.target": "i686-pc-windows-msvc",
3+
"rust-analyzer.linkedProjects": [
4+
".\\Cargo.toml"
5+
]
36
}

Cargo.lock

Lines changed: 12 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ png = { version = "0.17", optional = true }
3737
image = { version = "0.24", optional = true, default-features = false, features = ["png"] }
3838
git2 = { version = "0.17.1", optional = true, default-features = false }
3939
noise = { version = "0.8", optional = true }
40-
redis = { version = "0.21", optional = true }
40+
redis = { version = "0.23", optional = true }
4141
reqwest = { version = "0.11", optional = true, default-features = false, features = [
4242
"blocking",
4343
"rustls-tls",
@@ -103,6 +103,7 @@ hash = [
103103
]
104104
pathfinder = ["num", "pathfinding", "serde", "serde_json"]
105105
redis_pubsub = ["flume", "redis", "serde", "serde_json"]
106+
redis_reliablequeue = ["flume", "redis", "serde", "serde_json"]
106107
unzip = ["zip", "jobs"]
107108
worleynoise = ["rand", "rayon"]
108109

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ Additional features are:
104104
* hash: Faster replacement for `md5`, support for SHA-1, SHA-256, and SHA-512. Requires OpenSSL on Linux.
105105
* pathfinder: An a* pathfinder used for finding the shortest path in a static node map. Not to be used for a non-static map.
106106
* redis_pubsub: Library for sending and receiving messages through Redis.
107+
* redis_reliablequeue: Library for using a reliable queue pattern through Redis.
107108
* unzip: Function to download a .zip from a URL and unzip it to a directory.
108109
* worleynoise: Function that generates a type of nice looking cellular noise, more expensive than cellularnoise
109110

dmsrc/redis-reliablequeue.dm

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Connects to a given redis server.
3+
*
4+
* Arguments:
5+
* * addr - The address of the server, for example "redis://127.0.0.1/"
6+
*/
7+
#define rustg_redis_connect_rq(addr) RUSTG_CALL(RUST_G, "redis_connect_rq")(addr)
8+
/**
9+
* Disconnects from a previously connected redis server
10+
*/
11+
/proc/rustg_redis_disconnect_rq() return RUSTG_CALL(RUST_G, "redis_disconnect_rq")()
12+
/**
13+
* https://redis.io/commands/lpush/
14+
*
15+
* Arguments
16+
* * key (string) - The key to use
17+
* * elements (list) - The elements to push, use a list even if there's only one element.
18+
*/
19+
#define rustg_redis_lpush(key, elements) RUSTG_CALL(RUST_G, "redis_lpush")(key, json_encode(elements))
20+
/**
21+
* https://redis.io/commands/lrange/
22+
*
23+
* Arguments
24+
* * key (string) - The key to use
25+
* * start (string) - The zero-based index to start retrieving at
26+
* * stop (string) - The zero-based index to stop retrieving at (inclusive)
27+
*/
28+
#define rustg_redis_lrange(key, start, stop) RUSTG_CALL(RUST_G, "redis_lrange")(key, start, stop)
29+
/**
30+
* https://redis.io/commands/lpop/
31+
*
32+
* Arguments
33+
* * key (string) - The key to use
34+
* * count (string|null) - The amount to pop off the list, pass null to omit (thus just 1)
35+
*
36+
* Note: `count` was added in Redis version 6.2.0
37+
*/
38+
#define rustg_redis_lpop(key, count) RUSTG_CALL(RUST_G, "redis_lpop")(key, count)

src/acreplace.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ struct AhoCorasickOptions {
2020
impl AhoCorasickOptions {
2121
fn auto_configure_and_build(&self, patterns: &[String]) -> AhoCorasick {
2222
AhoCorasickBuilder::new()
23-
.start_kind(if self.anchored { StartKind::Anchored } else { StartKind::Unanchored })
23+
.start_kind(if self.anchored {
24+
StartKind::Anchored
25+
} else {
26+
StartKind::Unanchored
27+
})
2428
.ascii_case_insensitive(self.ascii_case_insensitive)
2529
.match_kind(self.match_kind)
2630
.build(patterns)

src/cellularnoise.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ fn noise_gen(
2727
.map(|x| {
2828
let mut rng = rand::thread_rng();
2929
(0..height + 3)
30-
.into_iter()
3130
.map(|y| {
3231
if x == 0 || y == 0 || x == width + 2 || y == height + 2 {
3332
return false;
@@ -39,12 +38,11 @@ fn noise_gen(
3938
.collect::<Vec<Vec<bool>>>();
4039

4140
//then we smoothe it
42-
(0..smoothing_level).into_iter().for_each(|_| {
41+
(0..smoothing_level).for_each(|_| {
4342
let replace_vec = (0..width + 3)
4443
.into_par_iter()
4544
.map(|x| {
4645
(0..height + 3)
47-
.into_iter()
4846
.map(|y| {
4947
if x == 0 || y == 0 || x == width + 2 || y == height + 2 {
5048
return false;
@@ -77,7 +75,6 @@ fn noise_gen(
7775
.into_par_iter()
7876
.map(|x| {
7977
(1..height + 1)
80-
.into_iter()
8178
.map(|y| filled_vec[x][y])
8279
.collect::<Vec<bool>>()
8380
})

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ pub mod noise_gen;
3434
pub mod pathfinder;
3535
#[cfg(feature = "redis_pubsub")]
3636
pub mod redis_pubsub;
37+
#[cfg(feature = "redis_reliablequeue")]
38+
pub mod redis_reliablequeue;
3739
#[cfg(feature = "sql")]
3840
pub mod sql;
3941
#[cfg(feature = "time")]

0 commit comments

Comments
 (0)