Why do diesel automotive engines redline at around 4500 rpm whereas petrol ones go to 6500-8000 rpm?
Does this have something to do with the compression ratio?
In Short its based on low burn rate of diesel plus the longer stroke of the diesel engine.
First you must understand the difference between these engines, the diesel works on purely compression of fuel , heating and generating bang to produce power, the gasoline on the other hand is natively twitchy and needs a spark to explode and produce power on its own.
Think of the petrol engine as a cheetah, it has lightweight bones and has a streamlined body thus is very fast but is not powerful enough to kill a lion or a rhino.
The Diesel engine is like an elephant, its slow and has a lot of strength, but needs heavier legs to support the huge body mass thus it cant run as fast as the cheetah but has a lot of strength. By strength of the elephant I mean torque in the engine.
The petrol engine natively combusts so it does not need heavy duty parts to withstand the explosion, yes you are compressing the fuel but its not nearly as much as the diesel, that is why 100cc motorcycles rev like crazy they have lightweight construction (cranks, pistons).
The diesel does not combust as much as petrol, it needs to be compressed to a much higher extent to combust thus the cylinder head, the piston, the crank everything needs to be heavy duty to withstand the compression explosion thus slowing down the speed of the piston.
Finally to answer your question:
Diesel burns slowly compared to petrol and for most diesel engines the limit is around 4800 to 5000 RPM.
Adding clarity to the above point, in a petrol engine almost 95% of the fuel is burnt in every stroke but in the diesel engine not all of the diesel is burnt in each stroke due to the slow combustion rate some diesel remains in the cylinder before the next stroke so no matter how hard you push, that small quantity of diesel will not burn before the piston is ready for the next stroke thus limiting the speed or redline.
To expand on Anarach's excellent answer; the burn rate of diesel is slower than petrol and at higher RPM you would risk the exhaust valve opening whist the mixture in the cylinder was still burning. Increase the RPM higher, especially on engines designed with some overlap so that inlet and exhaust valves are open at the same time and if you still have a burn event happening in your combustion chamber, you risk detonation which will totally ruin your engine.
There is probably also an argument that on a petrol engine, you are controlling the exact point in the cycle of each cylinder that the combustion starts. A petrol engine advances ignition by virtue of either weights within the distributor body or by electronic means via an ECU map. With a diesel engine you are reliant on compression ignite the fuel and thus limited to when this event is triggered which is likely the reason that such engines typically have a far narrower power band.
Paulster2 is right, varying the injection timing with respect to the engine crank angle timing is the main way to control the combustion process in a diesel engine. In a conventional gasoline engine (PFI or SIDI) fuel and air are largely pre-mixed before the spark event (which controls the start of the combustion process) which then leads to a fast propagating flame front that consumes the compressed fuel/air mixture in its path, even for SIDI the fuel injection timing is usually very early with respect to the engine top dead center (TDC). All these would result in a relatively quicker combustion process.
In diesel engines, fuel is injected into hot air (the result of compression) near the TDC, which would take awhile (ignition delay) before the fuel-air mixture auto-ignites. Until this point, the fuel injection is still happening (for conventional diesel combustion) which then leads to a diesel-engine-specific combustion model: mixing controlled combustion. In this model, the rate of combustion is determined by the rate of fuel/air mixing. The unique model of diesel combustion basically determined that the process of combustion has included mixing and combustion, unlike gasoline engines which allocates the mixing process in the intake or compression stroke, leading to an overall faster process. Other factors also contributes like the heavier build of diesel engine (larger momentum), higher compression ratio (longer stroke).
Generally speaking, the diesel engine just cannot/does not require high rev to obtain sufficient torque/power output.