code: def encode(cls, value):
          
          try:
              coerced = dict(value)
              if coerced == value:
                  return json.dumps(coerced).encode(cls._encoding)
          except (TypeError, ValueError):
              pass
          raise InvalidValue('not a dict')
docs: encode the dict as a json string to be written into redis.
  
          :param value: dict
          :return: bytes