I sleep on memory foam due to some hardware that protrudes just slightly and bothers me to lay on. The memory foam helps a lot, but for a hernia, that's going to be just a bandaid on your problem. A hernia surgery is not a big surgery. It will cause you some pain for a while, maybe a week, but you'll be glad to get it dealt with. And then you'll be FINE! Don't think of it as getting "cut open." Think of it as repairing a problem. You can do that, okay? You bit the bullet and went to the doctor, right? So now go to the next step. Look at it a step at a time. Don't let yourself dwell on it or fret about it. If you find yourself getting worried about it, you've got to force your mind to think about something else instead.
You hang in there! I wish you the best as you get your problem resolved.