65 Commits

Author SHA1 Message Date
antirez
5f889001cf Fix BITFIELD i64 type handling, see #7417.
(cherry picked from commit 448a8bb0ed9e970a1c6db594a5dc88ded1036695)
2020-07-20 21:08:26 +03:00
antirez
f066273907 Tracking: NOLOOP internals implementation. 2020-04-24 10:14:48 +02:00
hayleeliu
ebc872725f fix spelling mistake in bitops.c 2020-04-15 16:03:16 +02:00
antirez
4cfceac287 Fix BITFIELD_RO test. 2020-03-25 15:55:24 +01:00
antirez
243b26d97d Minor changes to BITFIELD_RO PR #6951. 2020-03-25 15:55:24 +01:00
bodong.ybd
015d1cb2ff Added BITFIELD_RO variants for read-only operations. 2020-03-25 15:55:24 +01:00
antirez
75687fcf17 Avoid changing setKey() API after #6679 fix. 2019-12-18 11:58:02 +01:00
zhaozhao.zz
746c23419f add a new SET option KEEPTTL that doesn't remove expire time 2019-12-18 15:20:36 +08:00
yongman
36fff343fb Fix memleak in bitfieldCommand 2019-04-09 09:24:22 +08:00
antirez
9640ac19ef RESP3: bitops.c updated. 2019-01-09 17:00:29 +01:00
Jack Drogon
bae1d36e5d Fix typo 2018-07-03 18:19:46 +02:00
Salvatore Sanfilippo
8291a07501 Use ARM unaligned accesses ifdefs for SPARC as well. 2017-02-23 22:39:44 +08:00
Salvatore Sanfilippo
d5fd9f031d Fix BITPOS unaligned memory access. 2017-02-23 22:38:44 +08:00
Salvatore Sanfilippo
98ef4372c9 ARM: Avoid fast path for BITOP.
GCC will produce certain unaligned multi load-store instructions
that will be trapped by the Linux kernel since ARM v6 cannot
handle them with unaligned addresses. Better to use the slower
but safer implementation instead of generating the exception which
should be anyway very slow.
2017-02-19 15:07:08 +00:00
sunhe
c7fc514f03 bitops.c/bitfieldCommand: update higest_write_offset with check 2016-10-22 01:54:46 +08:00
antirez
e096bb424a Minor aesthetic fixes to PR #3264.
Comment format fixed + local var modified from camel case to underscore
separators as Redis code base normally does (camel case is mostly used
for global symbols like structure names, function names, global vars,
...).
2016-06-16 12:54:33 +02:00
Salvatore Sanfilippo
955efc65ca Merge pull request #3264 from oranagra/bitfield_fix2
fix crash in BITFIELD GET on non existing key or wrong type see #3259
2016-06-16 12:52:36 +02:00
antirez
5cd8e6832f GETRANGE: return empty string with negative, inverted start/end. 2016-06-15 12:48:58 +02:00
antirez
185ec271cf Remove additional round brackets from fix for #3282. 2016-06-15 12:16:39 +02:00
Salvatore Sanfilippo
f476cc6e50 Merge pull request #3282 from wenduo/unstable
bitcount bug:return non-zero value when start > end (both negative)
2016-06-15 12:15:34 +02:00
Pierre Chapuis
f0d0231473 fix some compiler warnings 2016-06-05 16:48:45 +02:00
antirez
58b3a27b6d Avoid undefined behavior in BITFIELD implementation.
Probably there is no compiler that will actaully break the code or raise
a signal for unsigned -> signed overflowing conversion, still it was
apparently possible to write it in a more correct way.

All tests passing.
2016-05-31 11:52:07 +02:00
wenduo
386f7f5ae0 bitcount bug:return non-zero value when start > end (both negative) 2016-05-30 16:21:08 +08:00
oranagra
170f9dbc22 check WRONGTYPE in BITFIELD before looping on the operations.
optimization: lookup key only once, and grow at once to the max need
fixes #3259 and #3221, and also an early return if wrongtype is discovered by SET
2016-05-24 23:31:36 +03:00
oranagra
63b1eb3729 fix crash in BITFIELD GET on non existing key or wrong type see #3259
this was a bug in the recent refactoring: cbcee71ccba6766d58d729070ede73d808296193
2016-05-24 14:52:43 +03:00
antirez
cbcee71ccb Code to access object string bytes repeated 3x refactored into 1 function. 2016-05-18 15:35:19 +02:00
oranagra
d69bf84ecf fix crash in BITFIELD GET when key is integer encoded 2016-05-10 11:19:45 +03:00
antirez
53ad30831f BITFIELD: Farest bit set is offset+bits-1. Off by one error fixed. 2016-03-02 16:20:28 +01:00
antirez
bb561c71a7 More BITFIELD fixes. Overflow conditional simplified.
See issue #3114.
2016-03-02 15:13:45 +01:00
Sun He
524b28f864 bitops/bitfield: fix length, overflow condition and *sign 2016-03-02 18:11:30 +08:00
antirez
78a32d7f89 BITFIELD: refactoring & fix of retval on FAIL. 2016-02-29 09:08:46 +01:00
antirez
9d34efb3f5 BITFIELD: Fix #<index> form parsing. 2016-02-26 15:53:29 +01:00
antirez
b722e12f77 BITFIELD: Support #<index> offsets form. 2016-02-26 15:16:24 +01:00
antirez
5b3ab9d132 BITFIELD command initial implementation.
The new bitfield command is an extension to the Redis bit operations,
where not just single bit operations are performed, but the array of
bits composing a string, can be addressed at random, not aligned
offsets, with any width unsigned and signed integers like u8, s5, u10
(up to 64 bit signed integers and 63 bit unsigned integers).

The BITFIELD command supports subcommands that can SET, GET, or INCRBY
those arbitrary bit counters, with multiple overflow semantics.

Trivial and credits:

A similar command was imagined a few times in the past, but for
some reason looked a bit far fetched or not well specified.
Finally the command was proposed again in a clear form by
Yoav Steinberg from Redis Labs, that proposed a set of commands on
arbitrary sized integers stored at bit offsets.

Starting from this proposal I wrote an initial specification of a single
command with sub-commands similar to what Yoav envisioned, using short
names for types definitions, and adding control on the overflow.

This commit is the resulting implementation.

Examples:

    BITFIELD mykey OVERFLOW wrap INCRBY i2 10 -1 GET i2 10
2016-02-26 15:00:19 +01: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
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
Sun He
e03fbdd000 bitops.c/bitopCommand: skip short minlen for FAST PATH 2014-12-03 10:07:58 +08:00
Sun He
38ce5147a5 bitops.c/redisPopcount: little optimization in loop 2014-12-02 14:46:15 +08:00
antirez
2e94ffb1d1 Remove warnings and improve integer sign correctness. 2014-08-13 11:44:38 +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
6fec8e9300 warnigns -> warnings in redisBitpos(). 2014-02-27 13:17:23 +01:00
antirez
a47d73261b More consistent BITPOS behavior with bit=0 and ranges.
With the new behavior it is possible to specify just the start in the
range (the end will be assumed to be the first byte), or it is possible
to specify both start and end.

This is useful to change the behavior of the command when looking for
zeros inside a string.

1) If the user specifies both start and end, and no 0 is found inside
   the range, the command returns -1.

2) If instead no range is specified, or just the start is given, even
   if in the actual string no 0 bit is found, the command returns the
   first bit on the right after the end of the string.

So for example if the string stored at key foo is "\xff\xff":

    BITPOS foo (returns 16)
    BITPOS foo 0 -1 (returns -1)
    BITPOS foo 0 (returns 16)

The idea is that when no end is given the user is just looking for the
first bit that is zero and can be set to 1 with SETBIT, as it is
"available". Instead when a specific range is given, we just look for a
zero within the boundaries of the range.
2014-02-27 12:53:03 +01:00
antirez
eeb949a94f Initial implementation of BITPOS.
It appears to work but more stress testing, and both unit tests and
fuzzy testing, is needed in order to ensure the implementation is sane.
2014-02-27 12:44:27 +01:00
antirez
fd9c925022 Fix misaligned word access in redisPopcount(). 2014-02-27 09:46:20 +01: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
antirez
1065918c36 function renamed: popcount_binary -> redisPopcount. 2013-06-26 15:19:06 +02:00