Suppose, I have created a 301 redirect in my site. So, how long do I have to keep it in order to keep my ranking same as before?
Don't bother to remove it unless it is utmostly necessary. Keep it forever.
Forever, may be the nearest answer. But after 5 years I don't think its completely necessary.
Why do you want to remove them anyway? Keep them as long as you can.
It can take 6-months to a year for Google to fully recognize a site has moved. Plus you may have people finding old links and if those no longer have redirects, they may lead to a 404 page or a parked domain, which would result in a bad user experience.
it can take sometimes for all, approx 6 month