122 Commits

Author SHA1 Message Date
antirez
2a014229f0 Test: fix false positive in HSTRLEN test.
HINCRBY* tests later used the value "tmp" that was sometimes generated
by the random key generation function. The result was ovewriting what
Tcl expected to be inside Redis with another value, causing the next
HSTRLEN test to fail.
2015-09-15 09:37:30 +02:00
antirez
e8bee5c796 Test: print info on HSTRLEN test failure.
This additional info may provide more clues about the test randomly
failing from time to time. Probably the failure is due to some previous
test that overwrites the logical content in the Tcl variable, but this
will make the problem more obvious.
2015-09-07 11:14:52 +02:00
antirez
e5c00e6d3a Test: ZADD CH tests 2015-05-29 11:34:43 +02:00
antirez
1372f1fb0f Test: ZADD INCR test 2015-05-29 11:28:52 +02:00
antirez
034d1b5046 Test: ZADD NX and XX options tests 2015-05-29 11:23:49 +02:00
Glenn Nethercutt
d8390522cb uphold the smove contract to return 0 when the element is not a member of the source set, even if source=dest 2015-04-17 09:27:54 -04:00
antirez
5f6292f980 Test: HSTRLEN stress test of corner cases.
Main point here is to correctly report LLONG_MIN length, since to take
the absolute value we need care in sdigits10().
2015-02-27 15:44:44 +01:00
antirez
d4a13bd2f4 Hash: HSTRLEN (was HVSTRLEN) improved.
1. HVSTRLEN -> HSTRLEN. It's unlikely one needs the length of the key,
   not clear how the API would work (by value does not make sense) and
   there will be better names anyway.
2. Default is to return 0 when field is missing.
3. Default is to return 0 when key is missing.
4. The implementation was slower than needed, and produced unnecessary COW.

Related issue #2415.
2015-02-27 15:31:55 +01:00
Salvatore Sanfilippo
261b9d1b0f Merge pull request #2415 from landmime/unstable
added a new hvstrlen command
2015-02-27 15:24:04 +01:00
antirez
d5efd018cf Test: fixes a few tests after basic unit refactoring. 2015-02-25 10:37:52 +01:00
antirez
5b562e64a0 Test: split basic unit into string, incr, keyspace units. 2015-02-25 10:33:29 +01:00
Jason Roth
6cc1d51719 added a new hvstrlen command
the hvstrlen command returns the length of a hash field value
2015-02-21 15:01:18 +00:00
antirez
b842565acb SPOP explicit tests for the three different code paths. 2015-02-11 10:52:28 +01:00
Matt Stancliff
16cda6f076 Config: Add quicklist, remove old list options
This removes:
  - list-max-ziplist-entries
  - list-max-ziplist-value

This adds:
  - list-max-ziplist-size
  - list-compress-depth

Also updates config file with new sections and updates
tests to use quicklist settings instead of old list settings.
2015-01-02 11:16:10 -05:00
Matt Stancliff
e24ef16446 Add quicklist implementation
This replaces individual ziplist vs. linkedlist representations
for Redis list operations.

Big thanks for all the reviews and feedback from everybody in
https://github.com/antirez/redis/pull/2143
2015-01-02 11:16:08 -05:00
Alon Diamant
582c15db57 Added <count> parameter to SPOP:
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
2014-12-14 12:25:42 +02:00
antirez
822c911566 Test: check sorted set elements order after union.
This is not a regression but issue #1786 showed the need for this test.
2014-07-22 17:52:04 +02:00
Matt Stancliff
c5b960f5a0 Fix blocking operations from missing new lists
Behrad Zari discovered [1] and Josiah reported [2]: if you block
and wait for a list to exist, but the list creates from
a non-push command, the blocked client never gets notified.

This commit adds notification of blocked clients into
the DB layer and away from individual commands.

Lists can be created by [LR]PUSH, SORT..STORE, RENAME, MOVE,
and RESTORE.  Previously, blocked client notifications were
only triggered by [LR]PUSH.  Your client would never get
notified if a list were created by SORT..STORE or RENAME or
a RESTORE, etc.

Blocked client notification now happens in one unified place:
  - dbAdd() triggers notification when adding a list to the DB

Two new tests are added that fail prior to this commit.

All test pass.

Fixes #1668

[1]: https://groups.google.com/forum/#!topic/redis-db/k4oWfMkN1NU
[2]: #1668
2014-05-21 09:52:52 -04:00
antirez
ed2cc684ab Fuzzy test for ZREMRANGEBYLEX added. 2014-04-18 13:02:16 +02:00
antirez
00e9dc8b75 Sorted set lex ranges stress tester. 2014-04-17 10:25:58 +02:00
antirez
cd35352677 Basic ZRANGEBYLEX / ZLEXCOUNT tests. 2014-04-17 00:08:11 +02:00
antirez
f71de5ab4e SDIFF iterator misuse bug regression test added.
See commit 69a3303 for more info about the bug.
2013-12-13 11:37:13 +01:00
antirez
e9f1288faf Test: regression for issue #801. 2012-12-02 20:43:11 +01:00
antirez
68e2d2ce07 SDIFF is now able to select between two algorithms for speed.
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.
2012-11-30 16:36:42 +01:00
antirez
f76b95e713 SDIFF fuzz test added. 2012-11-30 01:35:34 +01:00
antirez
a037c6abf5 Type mismatch errors are now prefixed with WRONGTYPE.
So instead to reply with a generic error like:

-ERR ... wrong kind of value ...

now it replies with:

-WRONGTYPE ... wrong kind of value ...

This makes this particular error easy to check without resorting to
(fragile) pattern matching of the error string (however the error string
used to be consistent already).

Client libraries should return a specific exeption type for this error.

Most of the commit is about fixing unit tests.
2012-11-06 20:25:34 +01:00
antirez
0a1a7308a1 Test for SRANDMEMBER with <count>. 2012-09-21 11:55:36 +02:00
antirez
8574733f48 A reimplementation of blocking operation internals.
Redis provides support for blocking operations such as BLPOP or BRPOP.
This operations are identical to normal LPOP and RPOP operations as long
as there are elements in the target list, but if the list is empty they
block waiting for new data to arrive to the list.

All the clients blocked waiting for th same list are served in a FIFO
way, so the first that blocked is the first to be served when there is
more data pushed by another client into the list.

The previous implementation of blocking operations was conceived to
serve clients in the context of push operations. For for instance:

1) There is a client "A" blocked on list "foo".
2) The client "B" performs `LPUSH foo somevalue`.
3) The client "A" is served in the context of the "B" LPUSH,
synchronously.

Processing things in a synchronous way was useful as if "A" pushes a
value that is served by "B", from the point of view of the database is a
NOP (no operation) thing, that is, nothing is replicated, nothing is
written in the AOF file, and so forth.

However later we implemented two things:

1) Variadic LPUSH that could add multiple values to a list in the
context of a single call.
2) BRPOPLPUSH that was a version of BRPOP that also provided a "PUSH"
side effect when receiving data.

This forced us to make the synchronous implementation more complex. If
client "B" is waiting for data, and "A" pushes three elemnents in a
single call, we needed to propagate an LPUSH with a missing argument
in the AOF and replication link. We also needed to make sure to
replicate the LPUSH side of BRPOPLPUSH, but only if in turn did not
happened to serve another blocking client into another list ;)

This were complex but with a few of mutually recursive functions
everything worked as expected... until one day we introduced scripting
in Redis.

Scripting + synchronous blocking operations = Issue #614.

Basically you can't "rewrite" a script to have just a partial effect on
the replicas and AOF file if the script happened to serve a few blocked
clients.

The solution to all this problems, implemented by this commit, is to
change the way we serve blocked clients. Instead of serving the blocked
clients synchronously, in the context of the command performing the PUSH
operation, it is now an asynchronous and iterative process:

1) If a key that has clients blocked waiting for data is the subject of
a list push operation, We simply mark keys as "ready" and put it into a
queue.
2) Every command pushing stuff on lists, as a variadic LPUSH, a script,
or whatever it is, is replicated verbatim without any rewriting.
3) Every time a Redis command, a MULTI/EXEC block, or a script,
completed its execution, we run the list of keys ready to serve blocked
clients (as more data arrived), and process this list serving the
blocked clients.
4) As a result of "3" maybe more keys are ready again for other clients
(as a result of BRPOPLPUSH we may have push operations), so we iterate
back to step "3" if it's needed.

The new code has a much simpler semantics, and a simpler to understand
implementation, with the disadvantage of not being able to "optmize out"
a PUSH+BPOP as a No OP.

This commit will be tested with care before the final merge, more tests
will be added likely.
2012-09-17 10:26:46 +02:00
antirez
3e0309f0a9 Added a new hash fuzzy tester.
The new fuzzy tester also removes elements from the hash instead of just
adding random fields. This should increase the probability to find bugs
in the implementations of the hash type internal representations.
2012-06-12 15:21:54 +02:00
antirez
c1be7c2610 New test: hash ziplist -> hashtable encoding conversion.
A new stress test was added to stress test the code converting a ziplist
into an hash table.

In this commit also randomValue helper function was modified to also
return negative values.
2012-06-11 15:19:46 +02:00
antirez
e093a09c2f Fixed issue #516 (ZINTERSTORE mixing sets and zsets).
Weeks ago trying to fix an harmless GCC warning I introduced a bug in
the ziplist-encoded implementations of sorted sets.

The bug completely broke zuiNext() iterator, that is used in the
ZINTERSTORE and ZUNIONSTORE implementation, so those two commands are no
longer reliable starting from Redis version 2.4.12 and latest 2.6.0-RC
releases.

This commit fixes the problem and adds a regression test.
2012-05-23 11:12:43 +02:00
antirez
e12b40d3be Ziplist encoding now tested with negative integers as well. 2012-04-23 17:27:46 +02:00
antirez
9d80adcf99 Test SDIFF with first set empty. 2012-04-18 18:13:31 +02:00
antirez
bfdb8667fd Test SINTER against same integer elements, but different set encoding. 2012-04-18 18:10:48 +02:00
antirez
f56007b3d5 Test SINTER with non existing key. 2012-04-18 18:05:02 +02:00
antirez
9611f24607 Added an SMOVE test where src and dest key are the same. 2012-04-18 18:00:12 +02:00
antirez
25b016e4d3 New hash fuzzing test. 2012-04-18 17:56:17 +02:00
antirez
353f01d462 Explicit RPOP/LPOP tests. 2012-04-18 17:32:48 +02:00
antirez
62d36c3d16 Test LINSERT syntax error. 2012-04-18 17:22:14 +02:00
antirez
eab7143b2c Test LINDEX out of range index. 2012-04-18 17:17:53 +02:00
antirez
afadac1728 Merge conflicts resolved. 2012-03-09 22:07:45 +01:00
antirez
5c54ab0b7f Issue #330 regression test. 2012-02-16 16:13:40 +01:00
Pieter Noordhuis
ae204e5428 Encode small hashes with a ziplist 2012-01-02 22:14:10 -08:00
antirez
d000c35b60 Added regression test for ZUNIONSTORE creating NaN (github issue #264) 2011-12-23 09:34:06 +01:00
antirez
26d2ed1ce4 more valgrind (and other archs) friendly testing of floating number related features. 2011-11-16 14:40:50 +01:00
antirez
85056993ed valgrind handles floating point numbers differently for some reason, so using "simpler" numbers to make tests happy. 2011-11-16 13:35:22 +01:00
antirez
0321c79b42 HINCRBYFLOAT tests 2011-11-15 15:26:10 +01:00
antirez
33dcbd6df7 string to number API is now more strict not accepting spaces before or after the number. A few tests converted to match the new error messages using the word float instead of double. 2011-11-14 15:34:44 +01:00
antirez
e9dee96c29 regression test for bug 593 added 2011-09-12 10:53:49 +02:00
Pieter Noordhuis
49fd303a6b HDEL: Abort deleting fields when hash is removed 2011-07-27 12:29:40 +02:00