Raspberries get moldy so fast because the raspberries are a soft and fragile fruit.
During transport of the Raspberries they tend to get some damage to them which makes them more prone to mold faster than other fruits and berries.
The Raspberries are a fragile soft fruit that normally get some damage while in transport that damages and also weakens the raspberry fruit making it more susceptible to rot, once one raspberry starts to rot the bacteria spreads to the other fruit.
So you need to eat the raspberries within a few days or so of buying them.
Store the raspberries in the refrigerator in the container they come in and use the raspberries up within a few days before they have time to go bad and get moldy.
You could freeze the raspberries as well to make them last longer and then thaw the raspberries out when ready to eat them.
I've kept raspberries frozen for as long as 6 months and they never got moldy and were good to eat.