summaryrefslogtreecommitdiff
path: root/src/t_set.c
Commit message (Collapse)AuthorAgeFilesLines
* change SORT and SPOP to use lookupKeyWrite rather than lookupKeyReadOran Agra2019-03-201-1/+1
| | | | | like in SUNIONSTORE etc, commands that perform writes are expected to open all keys, even input keys, with lookupKeyWrite
* try lazyfree temp set in SUNION & SDIFFzhaozhao.zz2019-03-071-1/+2
|
* Better distribution for set get-random-element operations.antirez2019-02-181-1/+1
|
* RESP3: most null replies converted.antirez2019-01-091-9/+9
|
* RESP3: Use new aggregate reply API in t_set.c.antirez2019-01-091-6/+6
|
* Tranfer -> transfer typo fixed.antirez2018-07-311-1/+1
|
* refactor dbOverwrite to make lazyfree workzhaozhao.zz2018-07-311-6/+4
|
* set: fix the int problem for qsortzhaozhao.zz2017-12-051-2/+8
|
* set: fix the int problem for SPOP & SRANDMEMBERzhaozhao.zz2017-12-051-2/+2
|
* Optimize repeated keyname hashing.oranagra2016-09-121-1/+1
| | | | | (Change cherry-picked and modified by @antirez from a larger commit provided by @oranagra in PR #3223).
* Use const in Redis Module API where possible.Yossi Gottlieb2016-06-201-3/+3
|
* minor fixes - mainly signalModifiedKey, and GEORADIUSoranagra2016-05-091-3/+6
|
* Lazyfree: Convert Sets to use plains SDS (several commits squashed).antirez2015-10-011-119/+108
|
* RDMF: More consistent define names.antirez2015-07-271-39/+39
|
* RDMF: REDIS_OK REDIS_ERR -> C_OK C_ERR.antirez2015-07-261-7/+7
|
* RDMF: redisAssert -> serverAssert.antirez2015-07-261-5/+5
|
* RDMF: OBJ_ macros for object related stuff.antirez2015-07-261-52/+52
|
* RDMF: use client instead of redisClient, like Disque.antirez2015-07-261-19/+19
|
* RDMF (Redis/Disque merge friendlyness) refactoring WIP 1.antirez2015-07-261-1/+1
|
* Rewrite smoveCommand test with ternary operatorantirez2015-05-151-4/+1
|
* uphold the smove contract to return 0 when the element is not a member of ↵Glenn Nethercutt2015-04-171-1/+4
| | | | the source set, even if source=dest
* Fix setTypeNext call assuming NULL can be passed.antirez2015-03-311-2/+10
| | | | | | | | 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().
* Set: setType*() API more defensive initializing both values.antirez2015-03-301-0/+6
| | | | | | | 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.
* SPOP with count: fix replication for code path #3.antirez2015-02-111-2/+10
|
* SPOP: reimplemented for speed and better distribution.antirez2015-02-111-140/+80
| | | | | | | | | | 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.
* Change alsoPropagate() behavior to make it more usable.antirez2015-02-111-7/+5
| | | | | Now the API automatically creates its argv copy and increment ref count of passed objects.
* SPOP with count: initial fixes to the implementation.antirez2015-02-111-36/+33
| | | | | | | | | | | 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.
* Following @mattsta's friendly review:Alon Diamant2014-12-211-48/+54
| | | | | | | 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)
* Fix: case when SPOP with count>MAXINT, setTypeRandomElements() will get ↵Alon Diamant2014-12-181-6/+6
| | | | | | | 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()
* Added <count> parameter to SPOP:Alon Diamant2014-12-141-5/+242
| | | | | | | | | 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
* No more trailing spaces in Redis source code.antirez2014-06-261-1/+1
|
* SDIFF iterator misuse fixed in diff algorithm #1.antirez2013-12-131-0/+1
| | | | | | | | | | | | | | 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.
* SCAN code refactored to parse cursor first.antirez2013-11-051-1/+3
| | | | | | | | | | | | | | | | | | | | | | | 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.
* SSCAN implemented.antirez2013-10-281-0/+8
|
* Introduction of a new string encoding: EMBSTRantirez2013-07-221-7/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* retval doesn't initalizedRock Li2013-02-051-1/+1
| | | | If each if conditions are all fail, variable retval will under uninitlized
* Fix a bug in srandmemberWithCountCommand()Gengliang Wang2013-02-041-1/+1
| | | | | | | | | | 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"
* Generate del events when S*STORE commands delete the destination key.antirez2013-01-291-2/+8
|
* Keyspace events: it is now possible to select subclasses of events.antirez2013-01-281-10/+13
| | | | | | | | | When keyspace events are enabled, the overhead is not sever but noticeable, so this commit introduces the ability to select subclasses of events in order to avoid to generate events the user is not interested in. The events can be selected using redis.conf or CONFIG SET / GET.
* Keyspace events added for more commands.antirez2013-01-281-5/+26
|
* Fixed many typos.guiquanz2013-01-191-2/+2
|
* SDIFF is now able to select between two algorithms for speed.antirez2012-11-301-16/+97
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* BSD license added to every C source and header file.antirez2012-11-081-0/+29
|
* SRANDMEMBER <count> leak fixed.antirez2012-09-211-8/+10
| | | | | For "CASE 4" (see code) we need to free the element if it's already in the result dictionary and adding it failed.
* Added the SRANDMEMBER key <count> variant.antirez2012-09-211-0/+154
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Fixed some spelling errors in the commentsErik Dubbelboer2012-04-071-1/+1
|
* dict.c API names modified to be more coincise and consistent.antirez2011-11-081-2/+2
|
* replaced redisAssert() with redisAssertWithInfo() in a shitload of places.antirez2011-10-041-4/+4
|
* Fix for bug 561 and other related problemsantirez2011-06-201-11/+6
|
* Fix for the variadic version of SREM. Regression test added.antirez2011-05-311-1/+4
|