auto expiration for redis and postgres, some refactoring