code: def _set_redis_lock(redis_params: RedisParams) -> redis.lock.Lock:
      redis_client = RedisClient(
          host=redis_params.redis_host, port=redis_params.redis_port
      ).get_redis_client()
      blocking = not redis_params.raise_task_lock_exception_on_collision
      redis_lock = redis.lock.Lock(
          redis=redis_client,
          name=redis_params.redis_key,
          timeout=redis_params.redis_timeout,
          thread_local=False,
      )
      if not redis_lock.acquire(blocking=blocking):
          raise TaskLockException("Lock already taken by other task.")
      return redis_lock
  
imports: import functools
  import os
  from logging import getLogger
  from typing import Callable, NamedTuple, Optional
  import redis
  from apscheduler.schedulers.background import BackgroundScheduler
label_desc: Use image node_id 2 for calling a global function with example usage: _set_redis_lock(redis_params) and returns: redis_lock