191 Commits

Author SHA1 Message Date
Salvatore Sanfilippo
d7a561fbc7 Merge pull request #1677 from mattsta/expire-before-delete
Check key expiration before deleting
2014-04-23 16:13:49 +02:00
antirez
07ea1eb083 Always pass sorted set range objects by reference. 2014-04-17 14:30:12 +02:00
Matt Stancliff
9f92489df7 Check key expiration before deleting
Deleting an expired key should return 0, not success.

Fixes #1648
2014-04-10 17:08:02 -04:00
antirez
6028bc5501 String value unsharing refactored into proper function.
All the Redis functions that need to modify the string value of a key in
a destructive way (APPEND, SETBIT, SETRANGE, ...) require to make the
object unshared (if refcount > 1) and encoded in raw format (if encoding
is not already REDIS_ENCODING_RAW).

This was cut & pasted many times in multiple places of the code. This
commit puts the small logic needed into a function called
dbUnshareStringValue().
2014-03-30 18:32:17 +02:00
antirez
74f0696064 struct dictEntry -> dictEntry. 2014-03-20 16:20:37 +01:00
antirez
d7a2dd9f2e Obtain LRU clock in a resolution dependent way.
For testing purposes it is handy to have a very high resolution of the
LRU clock, so that it is possible to experiment with scripts running in
just a few seconds how the eviction algorithms works.

This commit allows Redis to use the cached LRU clock, or a value
computed on demand, depending on the resolution. So normally we have the
good performance of a precomputed value, and a clock that wraps in many
days using the normal resolution, but if needed, changing a define will
switch behavior to an high resolution LRU clock.
2014-03-20 11:47:12 +01:00
antirez
c56bd67494 Cluster: make sortGetKeys() able to handle multiple STORE options.
It does not make sense to pass multiple store options, so, better to
handle it ;-)
2014-03-10 16:39:07 +01:00
antirez
e695beb0f7 Cluster: SORT get keys helper implemented. 2014-03-10 16:26:08 +01:00
antirez
d24625dbbd Cluster: evalGetKeys() fixed: was not setting keys count. 2014-03-10 16:23:42 +01:00
antirez
fbb208395c Cluster: getKeysFromCommand() top comment improved. 2014-03-10 15:31:01 +01:00
antirez
fa29266526 Cluster: evalGetKey() added for EVAL/EVALSHA.
Previously we used zunionInterGetKeys(), however after this function was
fixed to account for the destination key (not needed when the API was
designed for "diskstore") the two set of commands can no longer be served
by an unique keys-extraction function.
2014-03-10 15:26:13 +01:00
antirez
b2c76e713a Cluster: getKeysFromCommand() and related: top-comments added. 2014-03-10 15:24:38 +01:00
antirez
24f7ef6e3b Cluster: getKeysFromCommand() API cleaned up.
This API originated from the "diskstore" experiment, not for Redis
Cluster itself, so there were legacy/useless things trying to
differentiate between keys that are going to be overwritten and keys
that need to be fetched from disk (preloaded).

All useless with Cluster, so removed with the result of code
simplification.
2014-03-10 13:18:41 +01:00
antirez
e803fa4b8b Cluster: some zunionInterGetKeys() comment trimmed.
Everything was pretty clear again from the initial statements.
2014-03-10 11:43:56 +01:00
Matt Stancliff
22bd3cd3ba Fix key extraction for z{union,inter}store
The previous implementation wasn't taking into account
the storage key in position 1 being a requirement (it
was only counting the source keys in positions 3 to N).

Fixes antirez/redis#1581
2014-03-07 16:33:20 -05:00
antirez
1a88341fb6 Sentinel: allow SHUTDOWN command in Sentinel mode. 2014-02-07 11:22:24 +01:00
antirez
c7426670a0 Scripting: expire keys in scripts only at first access.
Keys expiring in the middle of the execution of Lua scripts are to
create inconsistencies in masters and / or AOF files. See the following
example:

    if redis.call("exists",KEYS[1]) == 1
    then
        redis.call("incr","mycounter")
    end

    if redis.call("exists",KEYS[1]) == 1
    then
        return redis.call("incr","mycounter")
    end

The script executes two times the same *if key exists then incrementcounter*
logic. However the two executions will work differently in the master and
the slaves, provided some unlucky timing happens.

In the master the first time the key may still exist, while the second time
the key may no longer exist. This will result in the key incremented just one
time. However as a side effect the master will generate a synthetic
`DEL` command in the replication channel in order to force the slaves to
expire the key (given that key expiration is master-driven).

When the same script will run in the slave, the key will no longer be
there, so the script will not increment the key.

The key idea used to implement the expire-at-first-lookup semantics was
provided by Marc Gravell.
2014-02-03 16:15:53 +01:00
antirez
247a311317 dict.c: added optional callback to dictEmpty().
Redis hash table implementation has many non-blocking features like
incremental rehashing, however while deleting a large hash table there
was no way to have a callback called to do some incremental work.

This commit adds this support, as an optiona callback argument to
dictEmpty() that is currently called at a fixed interval (one time every
65k deletions).
2013-12-10 18:46:24 +01:00
antirez
7a5a646df9 Fixed grammar: before H the article is a, not an. 2013-12-05 16:35:32 +01:00
antirez
1071abc4a4 Sentinel: always send CONFIG REWRITE when changing instance role.
This change makes Sentinel less fragile about a number of failure modes.

This commit also fixes a different bug as a side effect, SLAVEOF command
was sent multiple times without incrementing the pending commands count.
2013-11-06 11:13:27 +01:00
antirez
1a1eb8bc8d SCAN code refactored to parse cursor first.
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.
2013-11-05 15:47:50 +01:00
antirez
f31cf249b9 SCAN: when iterating ziplists or intsets always return cursor of 0.
The previous implementation assumed that the first call always happens
with cursor set to 0, this may not be the case, and we want to return 0
anyway otherwise the (broken) client code will loop forever.
2013-11-05 15:32:25 +01:00
antirez
b97cff8b63 Use strtoul() instead of sscanf() in SCAN implementation. 2013-11-05 15:30:21 +01:00
antirez
56f53f7b3c HSCAN/ZSCAN: skip value when matching.
This fixes issue #1360 and #1362.
2013-11-05 12:16:29 +01:00
antirez
522549729f Pass int64_t to intsetGet() instead of long long. 2013-11-05 11:57:30 +01:00
antirez
653347d253 Inverted variable boolean value and name after scanGenericCommand() refactoring. 2013-10-31 10:35:56 +01:00
antirez
34e471e748 scanGenericCommand() refactoring and handling of integer encoded elements.
This commit fixes issue #1354.
2013-10-31 10:32:39 +01:00
antirez
6618167a9f HSCAN implemented. 2013-10-28 11:35:26 +01:00
antirez
0685c1ca13 SCAN: refactored into scanGenericCommand.
The new implementation is capable of iterating the keyspace but also
sets, hashes, and sorted sets, and can be used to implement SSCAN, ZSCAN
and HSCAN.
2013-10-28 11:11:34 +01:00
antirez
eda292a7fa SCAN: stay inside 80 cols. 2013-10-25 12:01:49 +02:00
antirez
fe0ffe6a1c Revert "Fixed typo in SCAN comment. iff -> if."
Probably here Pieter means "if and only if".

This reverts commit 0a970b93e911c0ece1fa2551ade71e122d8c01e1.
2013-10-25 12:00:13 +02:00
antirez
7bd87839c1 SCAN: simplify keys list cleanup using listSetFreeMethod(). 2013-10-25 11:58:03 +02:00
antirez
6f69128751 SCAN: improve variable names for readability. 2013-10-25 11:54:45 +02:00
antirez
6bff0f3cb6 SCAN: remove additional newlines to conform to Redis code base. 2013-10-25 11:51:08 +02:00
antirez
32b555c5fb SCAN: remove useless assertion, already enforced by command table. 2013-10-25 11:49:08 +02:00
antirez
6874fcc216 SCAN: use define REDIS_LONGSTR_SIZE instead of fixed len. 2013-10-25 11:48:18 +02:00
antirez
0a970b93e9 Fixed typo in SCAN comment. iff -> if. 2013-10-25 11:46:02 +02:00
antirez
5227a1f66f SCAN option name changed: pattern -> match. 2013-10-25 11:45:32 +02:00
Pieter Noordhuis
25ae316f65 SCAN requires at least 1 argument 2013-10-25 10:49:56 +02:00
Pieter Noordhuis
956c0ed927 Add SCAN command 2013-10-25 10:49:48 +02:00
antirez
1560b70889 Cluster: cluster stuff moved from redis.h to cluster.h. 2013-10-09 15:38:05 +02:00
antirez
e94b5b9359 Allow SHUTDOWN in loading state. 2013-06-27 12:18:29 +02:00
antirez
cf608e0451 EXPIRE should not resurrect keys. Issue #1026. 2013-03-28 12:45:07 +01:00
antirez
f334cccf8e TTL / PTTL commands: two bugs fixed.
This commit fixes two corner cases for the TTL command.

1) When the key was already logically expired (expire time older
than current time) the command returned -1 instead of -2.

2) When the key was existing and the expire was found to be exactly 0
(the key was just about to expire), the command reported -1 (that is, no
expire) instead of a TTL of zero (that is, about to expire).
2013-03-26 11:45:22 +01:00
antirez
4ad1f69d2a Cluster: move slotToKeyFlush() to emptyDb().
This way we are sure to destroy the slot->key map every time we destroy
the DB, for instance when reloading a DB due to replication.
2013-03-21 17:13:08 +01:00
antirez
e1b0d246f9 Cluster: use O(log(N)) algo for countKeysInSlot(). 2013-02-25 12:37:50 +01:00
antirez
301f162a2d Cluster: fix case for getKeysInSlot() and countKeysInSlot().
Redis functions start in low case. A few functions about cluster were
capitalized the wrong way.
2013-02-25 11:25:40 +01:00
antirez
9766072239 Cluster: added new API countKeysInSlot().
This is similar to getKeysInSlot() but just returns the number of keys
found in a given hash slot, without returning the keys.
2013-02-25 11:15:03 +01:00
antirez
ff71171a8e Cluster: fix case of slotToKey...() functions. 2013-02-22 10:16:21 +01:00
antirez
782e3ee485 Cluster: empty the internal sorted set mapping keys to slots on FLUSHDB/ALL. 2013-02-22 10:15:32 +01:00