title: Redis Lua Script Unpack Returning Different Results
body: <p>Setup by running sadd a b c</p>
  
  <p>When I execute this code against the set a
  keystoclear1 has a single value of "b" in it.
  keystoclear2 as both values in it.</p>
  
  <pre><code>local keystoclear = unpack(redis.call('smembers', KEYS[1]))
  
  redis.call('sadd', 'keystoclear1', keystoclear)
  
  redis.call('sadd', 'keystoclear2', unpack(redis.call('smembers', KEYS[1])))
  </code></pre>
  
  <p>I am by no means a lua expert, so I could just have some strange behavior here, but I would like to know what is causing it.</p>
  
  <p>I tested this on both the windows and linux version of redis, with redis-cli and the stackexchange.redis client. Same behavior in all cases. This is a trivial example, I actually would like to store the results of the unpack because I need to perform several operations with it. </p>
  
  <p>UPDATE: I understand the issue. </p>
  
  <p><a href="https://stackoverflow.com/questions/32439689/table-unpack-only-returns-the-first-element">table.unpack() only returns the first element</a></p>
  
  <blockquote>
    <p>Lua always adjusts the number of results from a function to the circumstances of the call. When we call a function as a statement, Lua discards all of its results. When we use a call as an expression, Lua keeps only the first result. We get all results only when the call is the last (or the only) expression in a list of expressions.</p>
  </blockquote>