import json


def strval(value):
    """JSON serialize value as appropriate.

    This function should only be used internally.

    :param dict|list|string|number value: An input value.
    :returns string: The output value, suitable for saving by Redis. If
        ``value`` is a ``dict`` or ``list``, it will be JSON-serialized.
        Otherwise it will be left as-is. Note that while Redis only takes
        string values, numbers have their string values be themselves in
        strings, and the conversion will be done by Redis automatically.
    """
    return json.dumps(value) if isinstance(value, (list, dict)) else value