コード例 #1
0
    def test_writes_disabled_tracking(self):
        tracker = HotKeyTracker(self.rc, 0, 0)
        for _ in range(5):
            tracker.maybe_track_key_usage(["SET", "foo", "bar"])

        self.assertEqual(
            tracker.redis_client.zrangebyscore(
                "baseplate-hot-key-tracker-writes",
                "-inf",
                "+inf",
                withscores=True),
            [],
        )
コード例 #2
0
    def test_write_multikey_commands(self):
        tracker = HotKeyTracker(self.rc, 1, 1)

        tracker.maybe_track_key_usage(["DEL", "foo", "bar"])

        self.assertEqual(
            tracker.redis_client.zrangebyscore(
                "baseplate-hot-key-tracker-writes",
                "-inf",
                "+inf",
                withscores=True),
            [(b"bar", float(1)), (b"foo", float(1))],
        )
コード例 #3
0
    def test_reads_enabled_tracking(self):
        tracker = HotKeyTracker(self.rc, 1, 1)
        for _ in range(5):
            tracker.maybe_track_key_usage(["GET", "foo"])

        self.assertEqual(
            tracker.redis_client.zrangebyscore(
                "baseplate-hot-key-tracker-reads",
                "-inf",
                "+inf",
                withscores=True),
            [(b"foo", float(5))],
        )