def persist
      future = nil
      set_id if new_record?
      callback = new_record? ? :create : :update

      self.class.transaction do |redis|
        run_callbacks :save do
          run_callbacks callback do
            redis.pipelined do
              attrs = coerced_attributes
              key = self.class.sti_child? ? self.class.sti_base_key_for(id) : self.class.key_for(id)
              future = attrs.any? ? redis.hmset(key, attrs) : :unchanged

              if new_record?
                if self.class.all_index_enabled?
                  redis.sadd(self.class.key_for(:all), id)
                  redis.sadd(self.class.sti_base_key_for(:all), id) if self.class.sti_child?
                end
                add_to_indexes(redis)
              else
                update_indexes(redis)
              end
            end
          end
        end
      end

      future
    end
def persist
      future = nil
      set_id if new_record?
      callback = new_record? ? :create : :update

      self.class.transaction do |redis|
        run_callbacks :save do
          run_callbacks callback do
            redis.pipelined do
              attrs = coerced_attributes
              key = self.class.sti_child? ? self.class.sti_base_key_for(id) : self.class.key_for(id)
              future = attrs.any? ? redis.hmset(key, attrs) : :unchanged

              if new_record?
                if self.class.all_index_enabled?
                  redis.sadd(self.class.key_for(:all), id)
                  redis.sadd(self.class.sti_base_key_for(:all), id) if self.class.sti_child?
                end
                add_to_indexes(redis)
              else
                update_indexes(redis)
              end
            end
          end
        end
      end

      future
    end
rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity