Commit 0d0660a8 authored by Nidhey Indurkar's avatar Nidhey Indurkar 💻
Browse files

docs(rate_limit): note why the hash tag keeps the rule name

parent 4c65e0cf
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -393,11 +393,10 @@ module Labkit
        Result::Evaluation.new(rule: rule, exceeded: count > resolved_limit, info: info)
      end

      # The limiter, rule and characteristics sit inside a Redis hash tag, so a
      # counter and its ban always hash to the same cluster slot. BAN_SCRIPT
      # touches both in one call, and Redis Cluster rejects a script whose keys
      # span slots. +suffix+ is appended outside the tag, so it cannot change
      # the slot and cannot collide with a characteristic value.
      # The braces are the cluster hash tag: a counter and its ban must share a
      # slot because BAN_SCRIPT touches both in one call. The rule name stays
      # inside it so one identifier's keys spread across nodes instead of piling
      # onto one. +suffix+ sits outside, so it cannot change the slot.
      def build_redis_key(rule, identifier, suffix = nil)
        key = "#{REDIS_KEY_PREFIX}:{#{@name}:#{rule.name}"
        rule.characteristics.each do |char|