<commit_before>module FakeRedis
  class Redis
    module SetsMethods
      def sadd(key, value)
        fail_unless_set(key)
        case set = @data[key]
          when nil then @data[key] = Set.new([value.to_s])
          when Set then set.add(value.to_s)
        end
      end

      def scard(key)
        fail_unless_set(key)
        case set = @data[key]
          when nil then 0
          when Set then set.size
        end
      end

      def sdiff(key1, *keys)
        [key1, *keys].each { |k| fail_unless_set(k) }
        keys = keys.map { |k| @data[k] || Set.new }
        keys.inject(@data[key1]) do |memo, set|
          memo - set
        end.to_a
      end

      def sdiffstore(destination, key1, *keys)
        fail_unless_set(destination)
        result = sdiff(key1, *keys)
        @data[destination] = Set.new(result)
      end

      def sinter(*keys)
        keys.each { |k| fail_unless_set(k) }
        return Set.new if keys.any? { |k| @data[k].nil? }
        keys = keys.map { |k| @data[k] || Set.new }
        keys.inject do |set, key|
          set & key
        end.to_a
      end

      def sinterstore(destination, *keys)
        fail_unless_set(destination)
        result = sinter(*keys)
        @data[destination] = Set.new(result)
      end

      def sismember(key, value)
        fail_unless_set(key)
        case set = @data[key]
          when nil then false
          when Set then set.include?(value.to_s)
        end
      end

      def smembers(key)
        fail_unless_set(key)
        case set = @data[key]
          when nil then []
          when Set then set.to_a
        end
      end

      def smove(source, destination, value)
        fail_unless_set(destination)
        if elem = self.srem(source, value)
          self.sadd(destination, value)
        end
      end

      def spop(key)
        fail_unless_set(key)
        elem = srandmember(key)
        srem(key, elem)
        elem
      end

      def srandmember(key)
        fail_unless_set(key)<commit_msg>smembers return elements in reverse order<commit_after>module FakeRedis
  class Redis
    module SetsMethods
      def sadd(key, value)
        fail_unless_set(key)
        case set = @data[key]
          when nil then @data[key] = Set.new([value.to_s])
          when Set then set.add(value.to_s)
        end
      end

      def scard(key)
        fail_unless_set(key)
        case set = @data[key]
          when nil then 0
          when Set then set.size
        end
      end

      def sdiff(key1, *keys)
        [key1, *keys].each { |k| fail_unless_set(k) }
        keys = keys.map { |k| @data[k] || Set.new }
        keys.inject(@data[key1]) do |memo, set|
          memo - set
        end.to_a
      end

      def sdiffstore(destination, key1, *keys)
        fail_unless_set(destination)
        result = sdiff(key1, *keys)
        @data[destination] = Set.new(result)
      end

      def sinter(*keys)
        keys.each { |k| fail_unless_set(k) }
        return Set.new if keys.any? { |k| @data[k].nil? }
        keys = keys.map { |k| @data[k] || Set.new }
        keys.inject do |set, key|
          set & key
        end.to_a
      end

      def sinterstore(destination, *keys)
        fail_unless_set(destination)
        result = sinter(*keys)
        @data[destination] = Set.new(result)
      end

      def sismember(key, value)
        fail_unless_set(key)
        case set = @data[key]
          when nil then false
          when Set then set.include?(value.to_s)
        end
      end

      def smembers(key)
        fail_unless_set(key)
        case set = @data[key]
          when nil then []
          when Set then set.to_a.reverse
        end
      end

      def smove(source, destination, value)
        fail_unless_set(destination)
        if elem = self.srem(source, value)
          self.sadd(destination, value)
        end
      end

      def spop(key)
        fail_unless_set(key)
        elem = srandmember(key)
        srem(key, elem)
        elem
      end

      def srandmember(key)
        fail_unless_set(key)
{'fraction_non_alphanumeric': 0.09985279685966635, 'fraction_numerical': 0.002944062806673209, 'mean_word_length': 1.7198132088058706, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '314771', 'n_tokens_mistral': 1364, 'n_tokens_neox': 1320, 'n_words': 326}