-
Notifications
You must be signed in to change notification settings - Fork 0
feat: implement 20 missing Redis commands (COPY, bit ops, SORT, GEO*, CONFIG REWRITE, CLIENT PAUSE, MEMORY) #68
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
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
5dd7e11
feat: implement COPY command for atomic key duplication
TinDang97 efa490e
feat: implement bit operations (GETBIT, SETBIT, BITCOUNT, BITOP, BITPOS)
TinDang97 757ccb3
feat: implement SORT command with BY/GET/LIMIT/ALPHA/DESC/STORE
TinDang97 f3b787a
feat: implement geospatial commands (GEOADD, GEOPOS, GEODIST, GEOHASH…
TinDang97 eb32d3e
style: fix clippy manual_is_multiple_of warning in geo_cmd
TinDang97 a89f440
fix: update dispatch_read prefilter test for new (6,b'b') bucket
TinDang97 9be660e
style: cargo fmt
TinDang97 a32f0b5
feat: implement CONFIG REWRITE and CONFIG RESETSTAT
TinDang97 e781ee1
feat: implement P1 medium-impact features
TinDang97 cfbcaf0
style: cargo fmt
TinDang97 a86dbb9
refactor: split COPY/SORT/MEMORY from key.rs into key_extra.rs
TinDang97 50db06f
docs: add CHANGELOG entry for high-impact Redis command parity
TinDang97 dfc4849
fix: address all 16 review findings from PR #68
TinDang97 05c782a
feat: implement Tier 1 gap commands (EXPIREAT, FLUSHDB, TIME, RANDOMK…
TinDang97 ce01137
docs: add Tier 1 commands to CHANGELOG
TinDang97 0f5c2d4
feat: resolve all remaining Redis command gaps
TinDang97 5d122f4
docs: add remaining gap commands to CHANGELOG
TinDang97 9649ec6
fix: SORT STORE preserves nil GET results as empty strings
TinDang97 813c068
fix: CLIENT PAUSE/UNPAUSE, COPY same-key, RANDOMKEY expiry, MEMORY SA…
TinDang97 3572b1e
fix: COPY same-key ERR, EXPIREAT accepts past timestamps, LCS OOM guard
TinDang97 6f0c104
merge: sync with main (graph engine PR #70)
TinDang97 50b2062
merge: sync with main (PR #69 security hardening)
TinDang97 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {"sessionId":"66332041-4f74-42df-8954-9e0482baacdd","pid":11173,"acquiredAt":1775933454187} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,6 +51,10 @@ pub fn config_get( | |
| runtime_config.protected_mode.clone(), | ||
| ), | ||
| (b"acllog-max-len", runtime_config.acllog_max_len.to_string()), | ||
| ( | ||
| b"lazyfree-threshold" as &[u8], | ||
| runtime_config.lazyfree_threshold.to_string(), | ||
| ), | ||
| (b"maxclients", runtime_config.maxclients.to_string()), | ||
| (b"timeout", runtime_config.timeout.to_string()), | ||
| (b"tcp-keepalive", runtime_config.tcp_keepalive.to_string()), | ||
|
|
@@ -174,6 +178,15 @@ pub fn config_set(runtime_config: &mut RuntimeConfig, args: &[Frame]) -> Frame { | |
| ))); | ||
| } | ||
| }, | ||
| "lazyfree-threshold" => match value_str.parse::<usize>() { | ||
| Ok(v) => runtime_config.lazyfree_threshold = v, | ||
| Err(_) => { | ||
| return Frame::Error(Bytes::from(format!( | ||
| "ERR Invalid argument '{}' for CONFIG SET 'lazyfree-threshold'", | ||
| value_str | ||
| ))); | ||
| } | ||
| }, | ||
| "maxclients" => match value_str.parse::<usize>() { | ||
| Ok(v) => runtime_config.maxclients = v, | ||
| Err(_) => { | ||
|
|
@@ -215,6 +228,93 @@ pub fn config_set(runtime_config: &mut RuntimeConfig, args: &[Frame]) -> Frame { | |
| Frame::SimpleString(Bytes::from_static(b"OK")) | ||
| } | ||
|
|
||
| /// CONFIG REWRITE — serialize current runtime config to a Redis-style config file. | ||
| /// | ||
| /// Writes to `<dir>/moon.conf` atomically (tmpfile + rename). | ||
| pub fn config_rewrite(runtime_config: &RuntimeConfig, server_config: &ServerConfig) -> Frame { | ||
| let mut lines = Vec::with_capacity(20); | ||
| lines.push("# Moon configuration file — generated by CONFIG REWRITE".to_string()); | ||
| lines.push(format!("# {}", chrono_lite_now())); | ||
| lines.push(String::new()); | ||
|
|
||
| // Server settings (from ServerConfig — immutable at runtime but persisted) | ||
| lines.push(format!("bind {}", server_config.bind)); | ||
| lines.push(format!("port {}", server_config.port)); | ||
| lines.push(format!("databases {}", server_config.databases)); | ||
| if let Some(ref pass) = runtime_config.requirepass { | ||
| lines.push(format!("requirepass {}", pass)); | ||
| } | ||
| lines.push(format!("protected-mode {}", runtime_config.protected_mode)); | ||
| lines.push(String::new()); | ||
|
|
||
| // Memory settings | ||
| lines.push(format!("maxmemory {}", runtime_config.maxmemory)); | ||
| lines.push(format!( | ||
| "maxmemory-policy {}", | ||
| runtime_config.maxmemory_policy | ||
| )); | ||
| lines.push(format!( | ||
| "maxmemory-samples {}", | ||
| runtime_config.maxmemory_samples | ||
| )); | ||
| lines.push(format!("lfu-log-factor {}", runtime_config.lfu_log_factor)); | ||
| lines.push(format!("lfu-decay-time {}", runtime_config.lfu_decay_time)); | ||
| lines.push(String::new()); | ||
|
|
||
| // Persistence settings | ||
| lines.push(format!("dir {}", runtime_config.dir)); | ||
| lines.push(format!("dbfilename {}", server_config.dbfilename)); | ||
| lines.push(format!("appendonly {}", runtime_config.appendonly)); | ||
| lines.push(format!("appendfsync {}", runtime_config.appendfsync)); | ||
| lines.push(format!("appendfilename {}", server_config.appendfilename)); | ||
| if let Some(ref save) = runtime_config.save { | ||
| lines.push(format!("save {}", save)); | ||
| } | ||
| lines.push(String::new()); | ||
|
|
||
| // ACL settings | ||
| lines.push(format!("acllog-max-len {}", runtime_config.acllog_max_len)); | ||
| if let Some(ref aclfile) = runtime_config.aclfile { | ||
| lines.push(format!("aclfile {}", aclfile)); | ||
| } | ||
| lines.push(format!( | ||
| "lazyfree-threshold {}", | ||
| runtime_config.lazyfree_threshold | ||
| )); | ||
|
|
||
| let content = lines.join("\n") + "\n"; | ||
|
|
||
| // Atomic write: tmpfile + rename | ||
| let dir = &runtime_config.dir; | ||
| let conf_path = std::path::Path::new(dir).join("moon.conf"); | ||
| let tmp_path = std::path::Path::new(dir).join("moon.conf.tmp"); | ||
|
|
||
| if let Err(e) = std::fs::write(&tmp_path, content.as_bytes()) { | ||
| return Frame::Error(Bytes::from(format!("ERR failed to write config: {e}"))); | ||
| } | ||
| if let Err(e) = std::fs::rename(&tmp_path, &conf_path) { | ||
| let _ = std::fs::remove_file(&tmp_path); | ||
| return Frame::Error(Bytes::from(format!("ERR failed to rename config: {e}"))); | ||
|
Comment on lines
+290
to
+297
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use a unique temp filename to avoid concurrent rewrite collisions.
💡 Suggested fix- let tmp_path = std::path::Path::new(dir).join("moon.conf.tmp");
+ let nonce = std::time::SystemTime::now()
+ .duration_since(std::time::UNIX_EPOCH)
+ .unwrap_or_default()
+ .as_nanos();
+ let tmp_path = std::path::Path::new(dir).join(format!(
+ "moon.conf.tmp.{}.{}",
+ std::process::id(),
+ nonce
+ ));🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| Frame::SimpleString(Bytes::from_static(b"OK")) | ||
| } | ||
|
|
||
| /// Lightweight timestamp without chrono dependency. | ||
| fn chrono_lite_now() -> String { | ||
| use std::time::{SystemTime, UNIX_EPOCH}; | ||
| let secs = SystemTime::now() | ||
| .duration_since(UNIX_EPOCH) | ||
| .unwrap_or_default() | ||
| .as_secs(); | ||
| format!("Generated at epoch {secs}") | ||
| } | ||
|
|
||
| /// CONFIG RESETSTAT — reset server statistics (placeholder). | ||
| pub fn config_resetstat() -> Frame { | ||
| Frame::SimpleString(Bytes::from_static(b"OK")) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
@@ -323,4 +423,30 @@ mod tests { | |
| assert_eq!(rt.maxmemory, 2048); | ||
| assert_eq!(rt.maxmemory_policy, "allkeys-lfu"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_config_rewrite() { | ||
| let tmp = std::env::temp_dir().join(format!("moon-test-{}", std::process::id())); | ||
| std::fs::create_dir_all(&tmp).unwrap(); | ||
|
|
||
| let mut rt = RuntimeConfig::default(); | ||
| rt.maxmemory = 1_073_741_824; // 1GB | ||
| rt.maxmemory_policy = "allkeys-lru".to_string(); | ||
| rt.dir = tmp.to_string_lossy().to_string(); | ||
|
|
||
| let sc = default_server_config(); | ||
| let result = config_rewrite(&rt, &sc); | ||
| assert_eq!(result, Frame::SimpleString(Bytes::from_static(b"OK"))); | ||
|
|
||
| // Verify file was created | ||
| let conf_path = tmp.join("moon.conf"); | ||
| assert!(conf_path.exists()); | ||
| let content = std::fs::read_to_string(&conf_path).unwrap(); | ||
| assert!(content.contains("maxmemory 1073741824")); | ||
| assert!(content.contains("maxmemory-policy allkeys-lru")); | ||
| assert!(content.contains("port 6379")); | ||
|
|
||
| // Cleanup | ||
| let _ = std::fs::remove_dir_all(tmp); | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.