title: Increment array index after rake task
body: <p>So I've got an array of strings that I want to send to my Rails logger. What I want is after each rake task run, my index is incremented by one so that the next string is posts in the logger. I have tried this the traditional way of using class variables and using Redis. My index is refusing to increment. This is what I have tried.</p>
  
  <p>TRY 1</p>
  
  <p>accounts_controller.rb</p>
  
  <pre><code>class AccountsController &lt; ApplicationController
    cattr_accessor :index
    @@index ||= 0
  
    def self.post
      current_user = User.find_by(:id =&gt; 1)
      user_posts = current_user.accounts.find_by(:id =&gt; 1).posts
      Rails.logger.info user_posts[@@index].tweet
    end
  end
  </code></pre>
  
  <p>post.rake</p>
  
  <pre><code>desc 'send post to twitter'
  task send_posts: :environment do
    AccountsController.post
    AccountsController.index += 1
  end
  </code></pre>
  
  <p>In the second try I try to use Redis to make my <code>@@index</code> variable persistent. Still no increment.</p>
  
  <p>accounts_controller.rb</p>
  
  <pre><code>class AccountsController &lt; ApplicationController
    cattr_accessor :index
    @@index = $redis.set('index', 0)
  
    def self.post
      current_user = User.find_by(:id =&gt; 1)
      user_posts = current_user.accounts.find_by(:id =&gt; 1).posts
      Rails.logger.info user_posts[@@index.to_i].tweet
    end
  end
  </code></pre>
  
  <p>post.rake</p>
  
  <pre><code>desc 'send post to twitter'
  task send_posts: :environment do
    AccountsController.post
    #AccountsController.index += 1
    $redis.incr('index')
  end
  </code></pre>
  
  <p>Can someone help me iterate over the array AFTER EACH rake task run? </p>