-
-
Save alvinkatojr/9cdf0c1a5893ccf6f4cc862560bbebc6 to your computer and use it in GitHub Desktop.
Redis Readonly Console
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
| if ENV['REDIS_ACCESS_MODE'] == 'readonly' | |
| class Redis | |
| class Client | |
| WRITE_COMMANDS = ::Rails.cache.data.command.map { |a| a[0] if a[2].include?('write') }.compact.to_set.freeze | |
| def process(commands) | |
| if commands.flatten.any? { |c| WRITE_COMMANDS.include?(c.to_s) } | |
| raise NotImplementedError, "REDIS_ACCESS_MODE is set to 'readonly', disallowing writes" | |
| end | |
| logging(commands) do | |
| ensure_connected do | |
| commands.each do |command| | |
| if command_map[command.first] | |
| command = command.dup | |
| command[0] = command_map[command.first] | |
| end | |
| write(command) | |
| end | |
| yield if block_given? | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment