1. 26 Jul, 2015 5 commits
  2. 15 May, 2015 1 commit
  3. 17 Apr, 2015 1 commit
  4. 31 Mar, 2015 1 commit
    • antirez's avatar
      Fix setTypeNext call assuming NULL can be passed. · 66f9393e
      antirez authored
      Segfault introduced during a refactoring / warning suppression a few
      commits away. This particular call assumed that it is safe to pass NULL
      to the object pointer argument when we are sure the set has a given
      encoding. This can't be assumed and is now guaranteed to segfault
      because of the new API of setTypeNext().
      66f9393e
  5. 30 Mar, 2015 1 commit
    • antirez's avatar
      Set: setType*() API more defensive initializing both values. · 7f330b16
      antirez authored
      This change fixes several warnings compiling at -O3 level with GCC
      4.8.2, and at the same time, in case of misuse of the API, we have the
      pointer initialize to NULL or the integer initialized to the value
      -123456789 which is easy to spot by naked eye.
      7f330b16
  6. 11 Feb, 2015 4 commits
    • antirez's avatar
      a37d0f8b
    • antirez's avatar
      SPOP: reimplemented for speed and better distribution. · 9feee428
      antirez authored
      The old version of SPOP with "count" argument used an API call of dict.c
      which was actually designed for a different goal, and was not capable of
      good distribution. We follow a different three-cases approach optimized
      for different ratiion between sets and requested number of elements.
      
      The implementation is simpler and allowed the removal of a large amount
      of code.
      9feee428
    • antirez's avatar
      Change alsoPropagate() behavior to make it more usable. · cc7f0434
      antirez authored
      Now the API automatically creates its argv copy and increment ref count
      of passed objects.
      cc7f0434
    • antirez's avatar
      SPOP with count: initial fixes to the implementation. · 6b5922dc
      antirez authored
      Severan problems are addressed but still a few missing.
      Since replication of this command was more complex than others since it
      needs to replicate multiple SREM commands, an old API able to do this
      was reused (it was taken inside the implementation since it was pretty
      obvious soon or later that would be useful). The API was improved a bit
      so that now a command may opt-out for the standard command replication
      when the server.dirty counter is incremented, in order to "manually"
      replicate what it wants.
      6b5922dc
  7. 21 Dec, 2014 1 commit
    • Alon Diamant's avatar
      Following @mattsta's friendly review: · d74a5a08
      Alon Diamant authored
        1. memory leak in t_set.c has been fixed
        2. end-of-line spaces has been removed (from all over the place)
        3. for loops have been ordered up to match existing Redis style (less weird)
        4. comments format has been fixed (added * in the beggining of every comment line)
      d74a5a08
  8. 18 Dec, 2014 1 commit
    • Alon Diamant's avatar
      Fix: case when SPOP with count>MAXINT, setTypeRandomElements() will get... · 3c8a7558
      Alon Diamant authored
      Fix: case when SPOP with count>MAXINT, setTypeRandomElements() will get negative count argument due to signed/unsigned mismatch.
      
      setTypeRandomElements() now returns unsigned long, and also uses unsigned long for anything related to count of members.
      spopWithCountCommand() now uses unsigned long elements_returned instead of int, for values returned from setTypeRandomElements()
      3c8a7558
  9. 14 Dec, 2014 1 commit
    • Alon Diamant's avatar
      Added <count> parameter to SPOP: · 28802887
      Alon Diamant authored
      spopCommand() now runs spopWithCountCommand() in case the <count> param is found.
      Added intsetRandomMembers() to Intset: Copies N random members from the set into inputted 'values' array. Uses either the Knuth or Floyd sample algos depending on ratio count/size.
      Added setTypeRandomElements() to SET type: Returns a number of random elements from a non empty set. This is a version of setTypeRandomElement() that is modified in order to return multiple entries, using dictGetRandomKeys() and intsetRandomMembers().
      Added tests for SPOP with <count>: unit/type/set, unit/scripting, integration/aof
      --
      Cleaned up code a bit to match with required Redis coding style
      28802887
  10. 26 Jun, 2014 1 commit
  11. 13 Dec, 2013 1 commit
    • antirez's avatar
      SDIFF iterator misuse fixed in diff algorithm #1. · c00453da
      antirez authored
      The bug could be easily triggered by:
      
          SADD foo a b c 1 2 3 4 5 6
          SDIFF foo foo
      
      When the key was the same in two sets, an unsafe iterator was used to
      check existence of elements in the same set we were iterating.
      Usually this would just result into a wrong output, however with the
      dict.c API misuse protection we have in place, the result was actually
      an assertion failed that was triggered by the CI test, while creating
      random datasets for the "MASTER and SLAVE consistency" test.
      c00453da
  12. 05 Nov, 2013 1 commit
    • antirez's avatar
      SCAN code refactored to parse cursor first. · ebcb6251
      antirez authored
      The previous implementation of SCAN parsed the cursor in the generic
      function implementing SCAN, SSCAN, HSCAN and ZSCAN.
      
      The actual higher-level command implementation only checked for empty
      keys and return ASAP in that case. The result was that inverting the
      arguments of, for instance, SSCAN for example and write:
      
          SSCAN 0 key
      
      Instead of
      
          SSCAN key 0
      
      Resulted into no error, since 0 is a non-existing key name very likely.
      Just the iterator returned no elements at all.
      
      In order to fix this issue the code was refactored to extract the
      function to parse the cursor and return the error. Every higher level
      command implementation now parses the cursor and later checks if the key
      exist or not.
      ebcb6251
  13. 28 Oct, 2013 1 commit
  14. 22 Jul, 2013 1 commit
    • antirez's avatar
      Introduction of a new string encoding: EMBSTR · 894eba07
      antirez authored
      Previously two string encodings were used for string objects:
      
      1) REDIS_ENCODING_RAW: a string object with obj->ptr pointing to an sds
      stirng.
      
      2) REDIS_ENCODING_INT: a string object where the obj->ptr void pointer
      is casted to a long.
      
      This commit introduces a experimental new encoding called
      REDIS_ENCODING_EMBSTR that implements an object represented by an sds
      string that is not modifiable but allocated in the same memory chunk as
      the robj structure itself.
      
      The chunk looks like the following:
      
      +--------------+-----------+------------+--------+----+
      | robj data... | robj->ptr | sds header | string | \0 |
      +--------------+-----+-----+------------+--------+----+
                           |                       ^
                           +-----------------------+
      
      The robj->ptr points to the contiguous sds string data, so the object
      can be manipulated with the same functions used to manipulate plan
      string objects, however we need just on malloc and one free in order to
      allocate or release this kind of objects. Moreover it has better cache
      locality.
      
      This new allocation strategy should benefit both the memory usage and
      the performances. A performance gain between 60 and 70% was observed
      during micro-benchmarks, however there is more work to do to evaluate
      the performance impact and the memory usage behavior.
      894eba07
  15. 05 Feb, 2013 1 commit
  16. 04 Feb, 2013 1 commit
    • Gengliang Wang's avatar
      Fix a bug in srandmemberWithCountCommand() · 00274733
      Gengliang Wang authored
      In CASE 2, the call sunionDiffGenericCommand will involve the string "srandmember" 
      > sadd foo one
      (integer 1)
      > sadd srandmember two
      (integer 2)
      > srandmember foo 3
      1)"one"
      2)"two"
      00274733
  17. 29 Jan, 2013 1 commit
  18. 28 Jan, 2013 2 commits
  19. 19 Jan, 2013 1 commit
  20. 30 Nov, 2012 1 commit
    • antirez's avatar
      SDIFF is now able to select between two algorithms for speed. · f50e6584
      antirez authored
      SDIFF used an algorithm that was O(N) where N is the total number
      of elements of all the sets involved in the operation.
      
      The algorithm worked like that:
      
      ALGORITHM 1:
      
      1) For the first set, add all the members to an auxiliary set.
      2) For all the other sets, remove all the members of the set from the
      auxiliary set.
      
      So it is an O(N) algorithm where N is the total number of elements in
      all the sets involved in the diff operation.
      
      Cristobal Viedma suggested to modify the algorithm to the following:
      
      ALGORITHM 2:
      
      1) Iterate all the elements of the first set.
      2) For every element, check if the element also exists in all the other
      remaining sets.
      3) Add the element to the auxiliary set only if it does not exist in any
      of the other sets.
      
      The complexity of this algorithm on the worst case is O(N*M) where N is
      the size of the first set and M the total number of sets involved in the
      operation.
      
      However when there are elements in common, with this algorithm we stop
      the computation for a given element as long as we find a duplicated
      element into another set.
      
      I (antirez) added an additional step to algorithm 2 to make it faster,
      that is to sort the set to subtract from the biggest to the
      smallest, so that it is more likely to find a duplicate in a larger sets
      that are checked before the smaller ones.
      
      WHAT IS BETTER?
      
      None of course, for instance if the first set is much larger than the
      other sets the second algorithm does a lot more work compared to the
      first algorithm.
      
      Similarly if the first set is much smaller than the other sets, the
      original algorithm will less work.
      
      So this commit makes Redis able to guess the number of operations
      required by each algorithm, and select the best at runtime according
      to the input received.
      
      However, since the second algorithm has better constant times and can do
      less work if there are duplicated elements, an advantage is given to the
      second algorithm.
      f50e6584
  21. 08 Nov, 2012 1 commit
  22. 21 Sep, 2012 2 commits
    • antirez's avatar
      SRANDMEMBER <count> leak fixed. · 578c9459
      antirez authored
      For "CASE 4" (see code) we need to free the element if it's already in
      the result dictionary and adding it failed.
      578c9459
    • antirez's avatar
      Added the SRANDMEMBER key <count> variant. · be90c803
      antirez authored
      SRANDMEMBER called with just the key argument can just return a single
      random element from a Redis Set. However many users need to return
      multiple unique elements from a Set, this is not a trivial problem to
      handle in the client side, and for truly good performance a C
      implementation was required.
      
      After many requests for this feature it was finally implemented.
      
      The problem implementing this command is the strategy to follow when
      the number of elements the user asks for is near to the number of
      elements that are already inside the set. In this case asking random
      elements to the dictionary API, and trying to add it to a temporary set,
      may result into an extremely poor performance, as most add operations
      will be wasted on duplicated elements.
      
      For this reason this implementation uses a different strategy in this
      case: the Set is copied, and random elements are returned to reach the
      specified count.
      
      The code actually uses 4 different algorithms optimized for the
      different cases.
      
      If the count is negative, the command changes behavior and allows for
      duplicated elements in the returned subset.
      be90c803
  23. 07 Apr, 2012 1 commit
  24. 08 Nov, 2011 1 commit
  25. 04 Oct, 2011 1 commit
  26. 20 Jun, 2011 1 commit
  27. 31 May, 2011 1 commit
  28. 15 May, 2011 1 commit
  29. 19 Apr, 2011 1 commit
  30. 15 Apr, 2011 1 commit
  31. 16 Feb, 2011 1 commit