factor out some patterns of the redis code to make the redis code more simple.