<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _prepare_sets(self, sets):
 """ The original "_prepare_sets" method simple return the list of sets in _lazy_collection, know to be all keys of redis sets. As the new "intersect" method can accept different types of "set", we have to handle them because we must return only keys of redis sets. """


        if self.stored_key and not self.stored_key_exists():
            raise DoesNotExist('This collection is based on a previous one, '
                               'stored at a key that does not exist anymore.')

        conn = self.cls.get_connection()

        all_sets = set()
        tmp_keys = set()
        lists = []

        def add_key(key, key_type=None, is_tmp=False):
            if not key_type:
                key_type = conn.type(key)
            if key_type == 'set':
                all_sets.add(key)
            elif key_type == 'zset':
                all_sets.add(key)
                self._has_sortedsets = True
            elif key_type == 'list':
                # if only one list, and no sets, at the end we'll directly use the list
                # else lists will be converted to sets
                lists.append(key)
            elif key_type == 'none':
                # considered as an empty set
                 all_sets.add(key)
            else:
                raise ValueError('Cannot use redis key %s of type %s for filtering' % (
                    key, key_type
                ))
            if is_tmp:
                tmp_keys.add(key)

        for set_ in sets:
            if isinstance(set_, str):
                add_key(set_)
            elif isinstance(set_, ParsedFilter):

                value = set_.value
                # We have a RedisModel and we'll use its pk, or a RedisField
                # (single value) and we'll use its value
                if isinstance(value, RedisModel):
                    value = value.pk.get()
                elif isinstance(value, SingleValueField):
                    value = value.proxy_get()
                elif isinstance(value, RedisField):
                    raise ValueError(u'Invalid filter value for %s: %s' % (set_.index.field.name, value))

                for index_key, key_type, is_tmp in set_.index.get_filtered_keys(
                            set_.suffix,
                            accepted_key_types=self._accepted_key_types,
                            *(set_.extra_field_parts + [value])
                        ):
                    if key_type not in self._accepted_key_types:
                        raise ValueError('The index key returned by the index %s is not valid' % (
                            set_.index.__class__.__name__
                        ))
                    add_key(index_key, key_type, is_tmp)

            elif isinstance(set_, SetField):
                # Use the set key. If we need to intersect, we'll use
                # sunionstore, and if not, store accepts set
                add_key(set_.key, 'set')
            elif isinstance(set_, SortedSetField):
                # Use the sorted set key. If we need to intersect, we'll use
                # zinterstore, and if not, store accepts zset
                add_key(set_.key, 'zset')
            elif isinstance(set_, (ListField, _StoredCollection)):
                add_key(set_.key, 'list')
            elif isinstance(set_, tuple) and len(set_):
                # if we got a list or set, create a redis set to hold its values
                tmp_key = self._unique_key()
                conn.sadd(tmp_key, *set_)
                add_key(tmp_key, 'set', True)
            else:
                raise ValueError('Invalid filter type')

        if lists:
            if not len(all_sets) and len(lists) == 1:
                # only one list, nothing else, we can return the list key
                all_sets = {lists[0]}
            else:
                # we have many sets/lists, we need to convert them to sets
                for list_key in lists:
                    # many sets, convert the list to a simple redis set
                    tmp_key = self._unique_key()
                    self._list_to_set(list_key, tmp_key)
                    add_key(tmp_key, 'set', True)

        return all_sets, tmp_keys