title: PHPUnit fixture for redis
body: <p>I wonder if there is an established procedure to create redis fixtures for PHPUnit.
  While I can think of at some ways to achieve this, it would be nice to have something standardized.</p>
  <p>As I dislike the idea of working with those EOF files directly, I currently use</p>
  <ul>
  <li>either a logfile where I run every line as a single command,</li>
  <li>or a LUA script if I need to generate a lot of predicteable or random lines.</li>
  </ul>
  <p>How are you testing scripts incorporating redis? Due to the speed of a local instance, I work with a clean testing instance and consider a mocking of redis clearly overhead.</p>
  <h2>How to record and replay redis commands in php</h2>
  <p>While waiting for your suggestions, I share mine.</p>
  <p>To record a logfile of every command entered into redis, you can use the shell:</p>
  <pre><code>redis-cli monitor &gt; redis.txt
  </code></pre>
  <p>Running while normal usage simply generates real-life fixture.</p>
  <p>In case you wonder how to turn</p>
  <pre><code>&quot;HSET&quot; &quot;foobar&quot; &quot;111&quot; &quot;1&quot;  ---&gt;  $redis-&gt;hset('foobar', '111', '1');
  </code></pre>
  <p>use</p>
  <pre><code>preg_match_all('/&quot;([^\s]+)&quot;/', $line, $matches);
  
  $command_parts = $matches[1];
  $command = array_shift($command_parts);
  $command = strtolower(trim($command));
  
  call_user_func_array(array($redis, $command), $command_parts);
  </code></pre>