Basic redis lock and some refactoring