Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a redis reliable queue implementation #133

Merged
merged 15 commits into from
May 21, 2023
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"rust-analyzer.cargo.target": "i686-pc-windows-msvc"
"rust-analyzer.cargo.target": "i686-pc-windows-msvc",
"rust-analyzer.linkedProjects": [
".\\Cargo.toml"
]
}
57 changes: 12 additions & 45 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ png = { version = "0.17", optional = true }
image = { version = "0.24", optional = true, default-features = false, features = ["png"] }
git2 = { version = "0.17.1", optional = true, default-features = false }
noise = { version = "0.8", optional = true }
redis = { version = "0.21", optional = true }
redis = { version = "0.23", optional = true }
reqwest = { version = "0.11", optional = true, default-features = false, features = [
"blocking",
"rustls-tls",
Expand Down Expand Up @@ -103,6 +103,7 @@ hash = [
]
pathfinder = ["num", "pathfinding", "serde", "serde_json"]
redis_pubsub = ["flume", "redis", "serde", "serde_json"]
redis_reliablequeue = ["flume", "redis", "serde", "serde_json"]
unzip = ["zip", "jobs"]
worleynoise = ["rand", "rayon"]

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

Expand Down
38 changes: 38 additions & 0 deletions dmsrc/redis-reliablequeue.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Connects to a given redis server.
*
* Arguments:
* * addr - The address of the server, for example "redis://127.0.0.1/"
*/
#define rustg_redis_connect_rq(addr) RUSTG_CALL(RUST_G, "redis_connect_rq")(addr)
/**
* Disconnects from a previously connected redis server
*/
/proc/rustg_redis_disconnect_rq() return RUSTG_CALL(RUST_G, "redis_disconnect_rq")()
/**
* https://redis.io/commands/lpush/
*
* Arguments
* * key (string) - The key to use
* * elements (list) - The elements to push, use a list even if there's only one element.
*/
#define rustg_redis_lpush(key, elements) RUSTG_CALL(RUST_G, "redis_lpush")(key, json_encode(elements))
/**
* https://redis.io/commands/lrange/
*
* Arguments
* * key (string) - The key to use
* * start (string) - The zero-based index to start retrieving at
* * stop (string) - The zero-based index to stop retrieving at (inclusive)
*/
#define rustg_redis_lrange(key, start, stop) RUSTG_CALL(RUST_G, "redis_lrange")(key, start, stop)
/**
* https://redis.io/commands/lpop/
*
* Arguments
* * key (string) - The key to use
* * count (string|null) - The amount to pop off the list, pass null to omit (thus just 1)
*
* Note: `count` was added in Redis version 6.2.0
*/
#define rustg_redis_lpop(key, count) RUSTG_CALL(RUST_G, "redis_lpop")(key, count)
6 changes: 5 additions & 1 deletion src/acreplace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ struct AhoCorasickOptions {
impl AhoCorasickOptions {
fn auto_configure_and_build(&self, patterns: &[String]) -> AhoCorasick {
AhoCorasickBuilder::new()
.start_kind(if self.anchored { StartKind::Anchored } else { StartKind::Unanchored })
.start_kind(if self.anchored {
StartKind::Anchored
} else {
StartKind::Unanchored
})
.ascii_case_insensitive(self.ascii_case_insensitive)
.match_kind(self.match_kind)
.build(patterns)
Expand Down
5 changes: 1 addition & 4 deletions src/cellularnoise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ fn noise_gen(
.map(|x| {
let mut rng = rand::thread_rng();
(0..height + 3)
.into_iter()
.map(|y| {
if x == 0 || y == 0 || x == width + 2 || y == height + 2 {
return false;
Expand All @@ -39,12 +38,11 @@ fn noise_gen(
.collect::<Vec<Vec<bool>>>();

//then we smoothe it
(0..smoothing_level).into_iter().for_each(|_| {
(0..smoothing_level).for_each(|_| {
let replace_vec = (0..width + 3)
.into_par_iter()
.map(|x| {
(0..height + 3)
.into_iter()
.map(|y| {
if x == 0 || y == 0 || x == width + 2 || y == height + 2 {
return false;
Expand Down Expand Up @@ -77,7 +75,6 @@ fn noise_gen(
.into_par_iter()
.map(|x| {
(1..height + 1)
.into_iter()
.map(|y| filled_vec[x][y])
.collect::<Vec<bool>>()
})
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ pub mod noise_gen;
pub mod pathfinder;
#[cfg(feature = "redis_pubsub")]
pub mod redis_pubsub;
#[cfg(feature = "redis_reliablequeue")]
pub mod redis_reliablequeue;
#[cfg(feature = "sql")]
pub mod sql;
#[cfg(feature = "time")]
Expand Down
Loading