When electrical power is lost, a typical refrigerator will keep foods at a safe temperature for about 4 hours assuming the door has not been opened and shut multiple times. A good rule is to not open the refrigerator door from the moment when the power goes off. It may be just a very short interruption or a problem that is fixed in an hour or so. But as the clock ticks and ticks, you will be glad that not opening the refrigerator door has given you extra time to figure out what to do.
A generator of some kind is needed to keep a refrigerator running during an extended outage. Luckily a refrigerator does not require a lot of power since it cycles on and off. Consequently, a large generator is not needed just to keep the refrigerator running. Many "experts" now recommend having a dedicated generator just to power a refrigerator and maybe another one for a freezer.
In this scenario, battery/solar generators are the best choice since they can be using inside a house or garage because they produce no toxic fumes from burning gasoline. However, having a small gasoline or propane powered generator is still a good idea because they can be used to charge a battery device when it needs to be charged.
(We do not recommend or endorse specific products.)