Commit Graph

65 Commits

Author SHA1 Message Date
antirez
746297314f Fix BITFIELD i64 type handling, see #7417. 2020-06-22 11:41:19 +02:00
antirez
94f2e7f9f9 Tracking: NOLOOP internals implementation. 2020-04-21 10:51:46 +02:00
hayleeliu
51b9de037d
fix spelling mistake in bitops.c 2020-04-08 18:20:32 +08:00
antirez
61de1c1146 Fix BITFIELD_RO test. 2020-03-23 12:02:12 +01:00
antirez
38514e3c8d Minor changes to BITFIELD_RO PR #6951. 2020-03-23 11:28:09 +01:00
bodong.ybd
94376f46ad Added BITFIELD_RO variants for read-only operations. 2020-03-04 20:51:45 +08:00
antirez
5b9d3ac6c6 Avoid changing setKey() API after #6679 fix. 2019-12-18 11:58:02 +01:00
zhaozhao.zz
24044f3356 add a new SET option KEEPTTL that doesn't remove expire time 2019-12-18 15:20:36 +08:00
yongman
d490752d58 Fix memleak in bitfieldCommand 2019-04-09 09:24:22 +08:00
antirez
3a3d806989 RESP3: bitops.c updated. 2019-01-09 17:00:29 +01:00
Jack Drogon
93238575f7 Fix typo 2018-07-03 18:19:46 +02:00
Salvatore Sanfilippo
b3391fd853 Use ARM unaligned accesses ifdefs for SPARC as well. 2017-02-23 22:39:44 +08:00
Salvatore Sanfilippo
d7826823c0 Fix BITPOS unaligned memory access. 2017-02-23 22:38:44 +08:00
Salvatore Sanfilippo
7329cc3981 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
949a274817 bitops.c/bitfieldCommand: update higest_write_offset with check 2016-10-22 01:54:46 +08:00
antirez
2f2fd64c0d 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
33a9836fe3 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
2d86995273 GETRANGE: return empty string with negative, inverted start/end. 2016-06-15 12:48:58 +02:00
antirez
eb45e11496 Remove additional round brackets from fix for #3282. 2016-06-15 12:16:39 +02:00
Salvatore Sanfilippo
001cadc854 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
188d90fc87 fix some compiler warnings 2016-06-05 16:48:45 +02:00
antirez
2503acfc83 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
41dacdbcbe bitcount bug:return non-zero value when start > end (both negative) 2016-05-30 16:21:08 +08:00
oranagra
5d96b7ed4f 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
c4433d2a6a fix crash in BITFIELD GET on non existing key or wrong type see #3259
this was a bug in the recent refactoring: bee963c445
2016-05-24 14:52:43 +03:00
antirez
bee963c445 Code to access object string bytes repeated 3x refactored into 1 function. 2016-05-18 15:35:19 +02:00
oranagra
77a9144245 fix crash in BITFIELD GET when key is integer encoded 2016-05-10 11:19:45 +03:00
antirez
fc843784c3 BITFIELD: Farest bit set is offset+bits-1. Off by one error fixed. 2016-03-02 16:20:28 +01:00
antirez
fe64960ad5 More BITFIELD fixes. Overflow conditional simplified.
See issue #3114.
2016-03-02 15:13:45 +01:00
Sun He
93cc8baf1a bitops/bitfield: fix length, overflow condition and *sign 2016-03-02 18:11:30 +08:00
antirez
32289d5719 BITFIELD: refactoring & fix of retval on FAIL. 2016-02-29 09:08:46 +01:00
antirez
11745e0981 BITFIELD: Fix #<index> form parsing. 2016-02-26 15:53:29 +01:00
antirez
2800d090a7 BITFIELD: Support #<index> offsets form. 2016-02-26 15:16:24 +01:00
antirez
70af626d61 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
32f80e2f1b RDMF: More consistent define names. 2015-07-27 14:37:58 +02:00
antirez
40eb548a80 RDMF: REDIS_OK REDIS_ERR -> C_OK C_ERR. 2015-07-26 23:17:55 +02:00
antirez
14ff572482 RDMF: OBJ_ macros for object related stuff. 2015-07-26 15:28:00 +02:00
antirez
554bd0e7bd RDMF: use client instead of redisClient, like Disque. 2015-07-26 15:20:52 +02:00
antirez
cef054e868 RDMF (Redis/Disque merge friendlyness) refactoring WIP 1. 2015-07-26 15:17:18 +02:00
Matt Stancliff
badf0f008b 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
c98d4f5675 bitops.c/bitopCommand: skip short minlen for FAST PATH 2014-12-03 10:07:58 +08:00
Sun He
0ec7672a5d bitops.c/redisPopcount: little optimization in loop 2014-12-02 14:46:15 +08:00
antirez
edca2b14d2 Remove warnings and improve integer sign correctness. 2014-08-13 11:44:38 +02:00
antirez
543ede03f2 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
76a6e82d89 warnigns -> warnings in redisBitpos(). 2014-02-27 13:17:23 +01:00
antirez
0e31eaa27f 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
38c620b3b5 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
746ce35f5f Fix misaligned word access in redisPopcount(). 2014-02-27 09:46:20 +01:00
antirez
894eba07c8 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
13585dd677 function renamed: popcount_binary -> redisPopcount. 2013-06-26 15:19:06 +02:00