Skip to content

refactor: extract Redis I/O threads configuration into reusable function - #230

Merged
PDowney merged 3 commits into
masterfrom
copilot/refactor-redis-io-threads-configuration
May 2, 2026
Merged

PDowney merged 3 commits into
masterfrom
copilot/refactor-redis-io-threads-configuration

Conversation

Copilot AI commented May 2, 2026

Copy link
Copy Markdown
Contributor

Redundant sed commands for io-threads / io-threads-do-reads were duplicated verbatim across four CPU-count branches in redis-install.sh. This refactor centralises them into a single parameterised function.

Software Version Updates

No version changes — this is a code quality refactor.

Changed Versions

N/A

Version Diff

-if [[ "${CPU_COUNT}" -ge '16' ]]; then
-  sed -i "s|^# io-threads 4|io-threads 8|" /etc/redis/redis.conf
-  sed -i "s|^# io-threads-do-reads no|io-threads-do-reads yes|" /etc/redis/redis.conf
-  elif [[ "${CPU_COUNT}" -ge '12' && "${CPU_COUNT}" -le '15' ]]; then
-    sed -i "s|^# io-threads 4|io-threads 6|" /etc/redis/redis.conf
-    sed -i "s|^# io-threads-do-reads no|io-threads-do-reads yes|" /etc/redis/redis.conf
-  elif ...  # same two sed lines repeated for every branch
+configure_redis_io_threads() {
+  local thread_count="$1"
+  sed -i "s|^# io-threads 4|io-threads ${thread_count}|" /etc/redis/redis.conf
+  sed -i "s|^# io-threads-do-reads no|io-threads-do-reads yes|" /etc/redis/redis.conf
+}
+
+if [[ "${CPU_COUNT}" -ge '16' ]]; then
+  configure_redis_io_threads 8
+elif [[ "${CPU_COUNT}" -ge '12' && "${CPU_COUNT}" -le '15' ]]; then
+  configure_redis_io_threads 6
+elif [[ "${CPU_COUNT}" -ge '7' && "${CPU_COUNT}" -le '11' ]]; then
+  configure_redis_io_threads 4
+elif [[ "${CPU_COUNT}" -ge '4' && "${CPU_COUNT}" -le '6' ]]; then
+  configure_redis_io_threads 2
+fi

Verification Checklist

  • Version numbers are correctly formatted
  • Version numbers are stable releases (not beta/RC)
  • No syntax errors in variables file

Notes

Behaviour is identical to the original — only structure changed. elif indentation also corrected to standard Bash if/elif/fi style. CHANGELOG.md updated.

Original prompt
Please apply the following diffs and create a pull request.
Once the PR is ready, give it a title based on the messages of the fixes being applied.

[{"message":"The Redis I/O threads configuration has redundant sed commands across multiple conditions. Consider using a function that takes thread count as a parameter to reduce code duplication and improve maintainability.","fixFiles":[{"filePath":"scripts/install/redis/redis-install.sh","diff":"diff --git a/scripts/install/redis/redis-install.sh b/scripts/install/redis/redis-install.sh\n--- a/scripts/install/redis/redis-install.sh\n+++ b/scripts/install/redis/redis-install.sh\n@@ -45,20 +45,22 @@\n # Redis Tuning\n sed -i \"s|SEDREDISMAXMEM|${SERVER_MEMORY_TOTAL_06}|g\" /etc/redis/redis.conf\n \n-if [[ \"${CPU_COUNT}\" -ge '16' ]]; then\n-  sed -i \"s|^# io-threads 4|io-threads 8|\" /etc/redis/redis.conf\n+configure_redis_io_threads() {\n+  local thread_count=\"$1\"\n+  sed -i \"s|^# io-threads 4|io-threads ${thread_count}|\" /etc/redis/redis.conf\n   sed -i \"s|^# io-threads-do-reads no|io-threads-do-reads yes|\" /etc/redis/redis.conf\n-  elif [[ \"${CPU_COUNT}\" -ge '12' && \"${CPU_COUNT}\" -le '15' ]]; then\n-    sed -i \"s|^# io-threads 4|io-threads 6|\" /etc/redis/redis.conf\n-    sed -i \"s|^# io-threads-do-reads no|io-threads-do-reads yes|\" /etc/redis/redis.conf\n-  elif [[ \"${CPU_COUNT}\" -ge '7' && \"${CPU_COUNT}\" -le '11' ]]; then\n-    sed -i \"s|^# io-threads 4|io-threads 4|\" /etc/redis/redis.conf\n-    sed -i \"s|^# io-threads-do-reads no|io-threads-do-reads yes|\" /etc/redis/redis.conf\n-  elif [[ \"${CPU_COUNT}\" -ge '4' && \"${CPU_COUNT}\" -le '6' ]]; then\n-    sed -i \"s|^# io-threads 4|io-threads 2|\" /etc/redis/redis.conf\n-    sed -i \"s|^# io-threads-do-reads no|io-threads-do-reads yes|\" /etc/redis/redis.conf\n-  fi\n+}\n \n+if [[ \"${CPU_COUNT}\" -ge '16' ]]; then\n+  configure_redis_io_threads 8\n+elif [[ \"${CPU_COUNT}\" -ge '12' && \"${CPU_COUNT}\" -le '15' ]]; then\n+  configure_redis_io_threads 6\n+elif [[ \"${CPU_COUNT}\" -ge '7' && \"${CPU_COUNT}\" -le '11' ]]; then\n+  configure_redis_io_threads 4\n+elif [[ \"${CPU_COUNT}\" -ge '4' && \"${CPU_COUNT}\" -le '6' ]]; then\n+  configure_redis_io_threads 2\n+fi\n+\n # Redis Service\n #sed -i \"s|Type=notify|Type=forking|g\" /lib/systemd/system/redis-server.service\n #sed -i \"s|--daemonize no|--daemonize yes|g\" /lib/systemd/system/redis-server.service\n"}]}]

…_io_threads function

Agent-Logs-Url: https://github.com/EngineScript/EngineScript/sessions/941a899e-7964-4104-9aec-ca3b624d7a22

Co-authored-by: PDowney <11467177+PDowney@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor Redis I/O threads configuration to improve maintainability refactor: extract Redis I/O threads configuration into reusable function May 2, 2026
Copilot finished work on behalf of PDowney May 2, 2026 05:26
Copilot AI requested a review from PDowney May 2, 2026 05:26
Removed details about refactoring Redis I/O threads configuration from the changelog.
@github-actions

github-actions Bot commented May 2, 2026

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@PDowney
PDowney marked this pull request as ready for review May 2, 2026 06:12
@sonarqubecloud

sonarqubecloud Bot commented May 2, 2026

Copy link
Copy Markdown

Copilot AI review requested due to automatic review settings May 2, 2026 06:13
@PDowney
PDowney merged commit c0a51e2 into master May 2, 2026
11 of 12 checks passed
@github-actions
github-actions Bot deleted the copilot/refactor-redis-io-threads-configuration branch May 2, 2026 06:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the Redis install script to centralize Redis I/O threads tuning into a reusable function, reducing duplication across CPU-count branches.

Changes:

  • Extracted Redis io-threads / io-threads-do-reads sed updates into configure_redis_io_threads().
  • Replaced duplicated per-CPU branches with calls to the new helper.

Comment on lines +48 to +62
configure_redis_io_threads() {
local thread_count="$1"
sed -i "s|^# io-threads 4|io-threads ${thread_count}|" /etc/redis/redis.conf
sed -i "s|^# io-threads-do-reads no|io-threads-do-reads yes|" /etc/redis/redis.conf
elif [[ "${CPU_COUNT}" -ge '12' && "${CPU_COUNT}" -le '15' ]]; then
sed -i "s|^# io-threads 4|io-threads 6|" /etc/redis/redis.conf
sed -i "s|^# io-threads-do-reads no|io-threads-do-reads yes|" /etc/redis/redis.conf
elif [[ "${CPU_COUNT}" -ge '7' && "${CPU_COUNT}" -le '11' ]]; then
sed -i "s|^# io-threads 4|io-threads 4|" /etc/redis/redis.conf
sed -i "s|^# io-threads-do-reads no|io-threads-do-reads yes|" /etc/redis/redis.conf
elif [[ "${CPU_COUNT}" -ge '4' && "${CPU_COUNT}" -le '6' ]]; then
sed -i "s|^# io-threads 4|io-threads 2|" /etc/redis/redis.conf
sed -i "s|^# io-threads-do-reads no|io-threads-do-reads yes|" /etc/redis/redis.conf
fi
}

if [[ "${CPU_COUNT}" -ge '16' ]]; then
configure_redis_io_threads 8
elif [[ "${CPU_COUNT}" -ge '12' && "${CPU_COUNT}" -le '15' ]]; then
configure_redis_io_threads 6
elif [[ "${CPU_COUNT}" -ge '7' && "${CPU_COUNT}" -le '11' ]]; then
configure_redis_io_threads 4
elif [[ "${CPU_COUNT}" -ge '4' && "${CPU_COUNT}" -le '6' ]]; then
configure_redis_io_threads 2
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants