key words, practice
its really not that hard its about themes and triggers the hardest thing are hecklers as they can throw you of course.
i used to Play Music for 4 Hours, a night 4 sets of 45 minutes each. You just know your Material. :)
They don't use sc<x>ripts, like an actor would. They just know the jokes they like to share and they deliver them, more or less in order. The better ones think on their feet and can squeeze in a number of jokes ba<x>sed on the locale, a member of the audience, an opening act, something a heckler says. It's an art, basically, and very little memorization.
The same way musicians remember lyrics. Q-cards help too.