89 Commits

Author SHA1 Message Date
hwware
4a03e1e1f8 fix server crash in STRALGO command
(cherry picked from commit 44195a2047efbe4db1b37365bd4ed66ba0f9d306)
2020-07-20 21:08:26 +03:00
hwware
08c70f7dce using moreargs variable 2020-05-22 12:37:59 +02:00
hwware
5c70dab9fc fix server crash for STRALGO command 2020-05-22 12:37:49 +02:00
antirez
262da0ba78 LCS -> STRALGO LCS.
STRALGO should be a container for mostly read-only string
algorithms in Redis. The algorithms should have two main
characteristics:

1. They should be non trivial to compute, and often not part of
programming language standard libraries.
2. They should be fast enough that it is a good idea to have optimized C
implementations.

Next thing I would love to see? A small strings compression algorithm.
2020-04-24 16:49:27 +02:00
antirez
f066273907 Tracking: NOLOOP internals implementation. 2020-04-24 10:14:48 +02:00
antirez
e835f0fe0c LCS: allow KEYS / STRINGS to be anywhere.
Initially they needed to be at the end so that we could extend to N
strings in the future, but after further consideration I no longer
believe it's worth it.
2020-04-07 16:52:57 +02:00
antirez
e46275a1dc LCS: get rid of STOREIDX option. Fix get keys helper. 2020-04-07 16:52:57 +02:00
antirez
9682cd452f LCS: fix stale comment. 2020-04-07 16:52:57 +02:00
antirez
28cf335ba8 LCS: output LCS len as well in IDX mode. 2020-04-07 16:52:57 +02:00
antirez
a3690e8af7 LCS: MINMATCHLEN and WITHMATCHLEN options. 2020-04-07 16:52:57 +02:00
antirez
3c9778ce79 LCS: 7x speedup by accessing the array with better locality. 2020-04-07 16:52:57 +02:00
antirez
7ee6ee5982 LCS: implement KEYS option. 2020-04-07 16:52:57 +02:00
antirez
c792f3e165 LCS: other fixes to range emission. 2020-04-07 16:52:57 +02:00
antirez
cd2da01d40 LCS: fix emission of last range starting at index 0. 2020-04-07 16:52:57 +02:00
antirez
a5fffca895 LCS: implement range indexes option. 2020-04-07 16:52:57 +02:00
antirez
087ed099d1 LCS: initial functionality implemented. 2020-04-07 16:52:57 +02:00
Oran Agra
6f54629071 modules don't signalModifiedKey in setKey() since that's done (optionally) in RM_CloseKey 2020-04-07 16:52:04 +02:00
antirez
75687fcf17 Avoid changing setKey() API after #6679 fix. 2019-12-18 11:58:02 +01:00
zhaozhao.zz
5c56f82bc3 incrbyfloat: fix issue #5256 ttl lost after propagate 2019-12-18 15:44:51 +08:00
zhaozhao.zz
746c23419f add a new SET option KEEPTTL that doesn't remove expire time 2019-12-18 15:20:36 +08:00
antirez
c8304b099d RESP3: most null replies converted. 2019-01-09 17:00:29 +01:00
antirez
dabbe41451 RESP3: Use new deferred len API in t_string.c. 2019-01-09 17:00:29 +01:00
antirez
5f9de96d2f Remove useless complexity from MSET implementation. 2018-10-22 12:24:02 +02:00
antirez
27c11df674 Fix incrDecrCommand() to create shared objects when needed.
See #5011.
2018-06-18 16:56:31 +02:00
antirez
86981fce60 Replication: fix the infamous key leakage of writable slaves + EXPIRE.
BACKGROUND AND USE CASEj

Redis slaves are normally write only, however the supprot a "writable"
mode which is very handy when scaling reads on slaves, that actually
need write operations in order to access data. For instance imagine
having slaves replicating certain Sets keys from the master. When
accessing the data on the slave, we want to peform intersections between
such Sets values. However we don't want to intersect each time: to cache
the intersection for some time often is a good idea.

To do so, it is possible to setup a slave as a writable slave, and
perform the intersection on the slave side, perhaps setting a TTL on the
resulting key so that it will expire after some time.

THE BUG

Problem: in order to have a consistent replication, expiring of keys in
Redis replication is up to the master, that synthesize DEL operations to
send in the replication stream. However slaves logically expire keys
by hiding them from read attempts from clients so that if the master did
not promptly sent a DEL, the client still see logically expired keys
as non existing.

Because slaves don't actively expire keys by actually evicting them but
just masking from the POV of read operations, if a key is created in a
writable slave, and an expire is set, the key will be leaked forever:

1. No DEL will be received from the master, which does not know about
such a key at all.

2. No eviction will be performed by the slave, since it needs to disable
eviction because it's up to masters, otherwise consistency of data is
lost.

THE FIX

In order to fix the problem, the slave should be able to tag keys that
were created in the slave side and have an expire set in some way.

My solution involved using an unique additional dictionary created by
the writable slave only if needed. The dictionary is obviously keyed by
the key name that we need to track: all the keys that are set with an
expire directly by a client writing to the slave are tracked.

The value in the dictionary is a bitmap of all the DBs where such a key
name need to be tracked, so that we can use a single dictionary to track
keys in all the DBs used by the slave (actually this limits the solution
to the first 64 DBs, but the default with Redis is to use 16 DBs).

This solution allows to pay both a small complexity and CPU penalty,
which is zero when the feature is not used, actually. The slave-side
eviction is encapsulated in code which is not coupled with the rest of
the Redis core, if not for the hook to track the keys.

TODO

I'm doing the first smoke tests to see if the feature works as expected:
so far so good. Unit tests should be added before merging into the
4.0 branch.
2016-12-13 10:59:54 +01:00
antirez
5cd8e6832f GETRANGE: return empty string with negative, inverted start/end. 2016-06-15 12:48:58 +02:00
antirez
c15cac0d77 RDMF: More consistent define names. 2015-07-27 14:37:58 +02:00
antirez
8a893fa4cf RDMF: REDIS_OK REDIS_ERR -> C_OK C_ERR. 2015-07-26 23:17:55 +02:00
antirez
62b27ebc2a RDMF: OBJ_ macros for object related stuff. 2015-07-26 15:28:00 +02:00
antirez
fa26d3dd63 RDMF: use client instead of redisClient, like Disque. 2015-07-26 15:20:52 +02:00
antirez
6a424b5e36 RDMF (Redis/Disque merge friendlyness) refactoring WIP 1. 2015-07-26 15:17:18 +02:00
Salvatore Sanfilippo
31e8dbbfdc Merge pull request #2050 from mattsta/bitops-no-overalloc
Bitops: Stop overallocating storage space on set
2015-02-25 10:18:07 +01:00
antirez
c0615882ec More obvious indentation in setCommand(). 2015-02-03 14:17:06 +01:00
antirez
87ae6439f2 Merge branch 'unstable' of git://github.com/mihirvj/redis into set-pr 2015-02-03 14:13:30 +01:00
Mihir Joshi
ec0e62d0b6 Stricter options for SET command
- As per Antirez's suggestion, this commit raises an error when mutually
exclusive options are provided. Duplicate options are allowed.
2014-12-14 10:12:58 -05:00
Matt Stancliff
101f0b44a5 Bitops: Stop overallocating storage space on set
Previously the string was created empty then re-sized
to fit the offset, but sds resize causes the sds to
over-allocate by at least 1 MB (which is a lot when
you are operating at bit-level access).

This also improves the speed of initial sets by 2% to 6%
based on quick testing.

Patch logic provided by @oranagra

Fixes #1918
2014-12-11 10:54:21 -05:00
antirez
b81104a288 Use exp format and more precision output for ZSCAN.
Ref: issue #2175
2014-12-02 18:20:09 +01:00
Mihir Joshi
4cd61b4b9b stricter options for SET command
Issue: #2157
As the SET command is parsed, it remembers which options are already set
and if a duplicate option is found, raises an error because it is
essentially an invalid syntax.

It still allows mutually exclusive options like EX and PX because taking
an option over another (precedence) is not essentially a syntactic
error.
2014-11-21 22:35:42 -05:00
antirez
1c6a304605 INCR: Modify incremented object in-place when possible.
However we don't try to do this if the integer is already inside a range
representable with a shared integer.

The performance gain appears to be around ~15% in micro benchmarks,
however in the long run this also helps to improve locality, so should
have more, hard to measure, benefits.
2014-10-03 12:11:13 +01:00
Matt Stancliff
d5731849e1 Return empty string if GETRANGE of empty string
Previously, GETRANGE of a key containing nothing ("")
would allocate a large (size_t)-1 return value causing
crashes on 32bit builds when it tried to allocate the
4 GB return string.
2014-09-02 18:56:28 -04:00
Matt Stancliff
3b1b65c3d8 Increase size of range request in getrange
32 bit builds don't have a big enough long to capture
the same range as a 64 bit build.  If we use "long long"
we get proper size limits everywhere.

Also updates size of unsigned comparison to fit new size of `end`.

Fixes #1981
2014-09-02 18:56:01 -04:00
antirez
8fbf4c2afa Fix invalid expire error for SET family commands. 2014-08-18 11:15:50 +02:00
Jan-Erik Rediger
ea8b1d383f Handle large getrange requests
Previously the end was casted to a smaller type
which resulted in a wrong check and failed
with values larger than handled by unsigned.

Closes #1847, #1844
2014-08-07 12:40:44 +02: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
aa32f92338 Introduction of a new string encoding: EMBSTR
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.
2013-07-22 10:31:38 +02:00
charsyam
d49e0f6807 Support for case unsensitive SET options. 2013-03-29 10:33:52 +01:00
antirez
9e258a4438 Extended SET command implemented (issue #931). 2013-03-28 15:40:19 +01:00
antirez
f28d386cc5 Keyspace events: it is now possible to select subclasses of events.
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.
2013-01-28 13:15:12 +01:00
antirez
f2d1105618 Keyspace events added for more commands. 2013-01-28 13:14:56 +01:00
antirez
ccef29ae2c Initial test events for the new keyspace notification API. 2013-01-28 13:14:46 +01:00