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

replace null separator in apq cache key with : to match convention #4886

Merged
merged 3 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changesets/fix_apq_cache_key_to_match_redis_convention.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### Replaces null separator in apq cache key with : to match redis convention

This PR conforms the apq cache key to follow redis convention. This helps when using redis clients to properly display keys in nested form.

query plan cache key was fixed in a similar pr: #4583

By [@tapaderster](https://github.com/tapaderster) in https://github.com/apollographql/router/pull/4886
2 changes: 1 addition & 1 deletion apollo-router/src/services/layers/apq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ fn query_matches_hash(query: &str, hash: &[u8]) -> bool {
}

fn redis_key(query_hash: &str) -> String {
format!("apq\0{query_hash}")
format!("apq:{query_hash}")
}

pub(crate) fn calculate_hash_for_query(query: &str) -> String {
Expand Down
7 changes: 3 additions & 4 deletions apollo-router/tests/integration/redis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ mod test {
let query_hash = "4c45433039407593557f8a982dafd316a66ec03f0e1ed5fa1b7ef8060d76e8ec";

client
.del::<String, _>(&format!("apq\x00{query_hash}"))
.del::<String, _>(&format!("apq:{query_hash}"))
.await
.unwrap();

Expand Down Expand Up @@ -196,8 +196,7 @@ mod test {
res.errors.first().unwrap().message,
"PersistedQueryNotFound"
);

let r: Option<String> = client.get(&format!("apq\x00{query_hash}")).await.unwrap();
let r: Option<String> = client.get(&format!("apq:{query_hash}")).await.unwrap();
assert!(r.is_none());

// Now we register the query
Expand All @@ -222,7 +221,7 @@ mod test {
assert!(res.data.is_some());
assert!(res.errors.is_empty());

let s: Option<String> = client.get(&format!("apq\x00{query_hash}")).await.unwrap();
let s: Option<String> = client.get(&format!("apq:{query_hash}")).await.unwrap();
insta::assert_display_snapshot!(s.unwrap());

// we start a new router with the same config
Expand Down