code: def process_items(r, keys, timeout, limit=0, log_every=1000, wait=.1):
      
      limit = limit or float('inf')
      processed = 0
      while processed < limit:
          # Change ``blpop`` to ``brpop`` to process as LIFO.
          ret = r.blpop(keys, timeout)
          # If data is found before the timeout then we consider we are done.
          if ret is None:
              time.sleep(wait)
              continue
  
          source, data = ret
          try:
              item = json.loads(data)
          except Exception:
              logger.exception("Failed to load item:\n%r", pprint.pformat(data))
              continue
  
          try:
              name = item.get('name') or item.get('title')
              url = item.get('url') or item.get('link')
              logger.debug("[%s] Processing item: %s <%s>", source, name, url)
          except KeyError:
              logger.exception("[%s] Failed to process item:\n%r",
                               source, pprint.pformat(item))
              continue
  
          processed += 1
          if processed % log_every == 0:
              logger.info("Processed %s items", processed)
docs: Process items from a redis queue.
  
      Parameters
      ----------
      r : Redis
          Redis connection instance.
      keys : list
          List of keys to read the items from.
      timeout: int
          Read timeout.