Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
493a7f98
Unverified
Commit
493a7f98
authored
Mar 23, 2020
by
Salvatore Sanfilippo
Committed by
GitHub
Mar 23, 2020
Browse files
Merge pull request #6951 from yangbodong22011/feature-bitfield-ro
Added BITFIELD_RO variants for read-only operations.
parents
19f5be23
94376f46
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/bitops.c
View file @
493a7f98
...
@@ -902,6 +902,9 @@ void bitposCommand(client *c) {
...
@@ -902,6 +902,9 @@ void bitposCommand(client *c) {
* OVERFLOW [WRAP|SAT|FAIL]
* OVERFLOW [WRAP|SAT|FAIL]
*/
*/
#define BITFIELD_COMMON (1<<0)
#define BITFIELD_READONLY (1<<1)
struct
bitfieldOp
{
struct
bitfieldOp
{
uint64_t
offset
;
/* Bitfield offset. */
uint64_t
offset
;
/* Bitfield offset. */
int64_t
i64
;
/* Increment amount (INCRBY) or SET value */
int64_t
i64
;
/* Increment amount (INCRBY) or SET value */
...
@@ -911,7 +914,7 @@ struct bitfieldOp {
...
@@ -911,7 +914,7 @@ struct bitfieldOp {
int
sign
;
/* True if signed, otherwise unsigned op. */
int
sign
;
/* True if signed, otherwise unsigned op. */
};
};
void
bitfield
Command
(
client
*
c
)
{
void
bitfield
Generic
(
client
*
c
,
int
flags
)
{
robj
*
o
;
robj
*
o
;
size_t
bitoffset
;
size_t
bitoffset
;
int
j
,
numops
=
0
,
changes
=
0
;
int
j
,
numops
=
0
,
changes
=
0
;
...
@@ -999,6 +1002,12 @@ void bitfieldCommand(client *c) {
...
@@ -999,6 +1002,12 @@ void bitfieldCommand(client *c) {
return
;
return
;
}
}
}
else
{
}
else
{
if
(
flags
&
BITFIELD_READONLY
)
{
zfree
(
ops
);
addReplyError
(
c
,
"bitfield_ro only support get subcommand"
);
return
;
}
/* Lookup by making room up to the farest bit reached by
/* Lookup by making room up to the farest bit reached by
* this operation. */
* this operation. */
if
((
o
=
lookupStringForBitCommand
(
c
,
if
((
o
=
lookupStringForBitCommand
(
c
,
...
@@ -1129,3 +1138,11 @@ void bitfieldCommand(client *c) {
...
@@ -1129,3 +1138,11 @@ void bitfieldCommand(client *c) {
}
}
zfree
(
ops
);
zfree
(
ops
);
}
}
void
bitfieldCommand
(
client
*
c
)
{
bitfieldGeneric
(
c
,
BITFIELD_COMMON
);
}
void
bitfieldroCommand
(
client
*
c
)
{
bitfieldGeneric
(
c
,
BITFIELD_READONLY
);
}
src/server.c
View file @
493a7f98
...
@@ -238,6 +238,10 @@ struct redisCommand redisCommandTable[] = {
...
@@ -238,6 +238,10 @@ struct redisCommand redisCommandTable[] = {
"write use-memory @bitmap"
,
"write use-memory @bitmap"
,
0
,
NULL
,
1
,
1
,
1
,
0
,
0
,
0
},
0
,
NULL
,
1
,
1
,
1
,
0
,
0
,
0
},
{
"bitfield_ro"
,
bitfieldroCommand
,
-
2
,
"read-only fast @bitmap"
,
0
,
NULL
,
1
,
1
,
1
,
0
,
0
,
0
},
{
"setrange"
,
setrangeCommand
,
4
,
{
"setrange"
,
setrangeCommand
,
4
,
"write use-memory @string"
,
"write use-memory @string"
,
0
,
NULL
,
1
,
1
,
1
,
0
,
0
,
0
},
0
,
NULL
,
1
,
1
,
1
,
0
,
0
,
0
},
...
...
src/server.h
View file @
493a7f98
...
@@ -2177,6 +2177,7 @@ void existsCommand(client *c);
...
@@ -2177,6 +2177,7 @@ void existsCommand(client *c);
void
setbitCommand
(
client
*
c
);
void
setbitCommand
(
client
*
c
);
void
getbitCommand
(
client
*
c
);
void
getbitCommand
(
client
*
c
);
void
bitfieldCommand
(
client
*
c
);
void
bitfieldCommand
(
client
*
c
);
void
bitfieldroCommand
(
client
*
c
);
void
setrangeCommand
(
client
*
c
);
void
setrangeCommand
(
client
*
c
);
void
getrangeCommand
(
client
*
c
);
void
getrangeCommand
(
client
*
c
);
void
incrCommand
(
client
*
c
);
void
incrCommand
(
client
*
c
);
...
...
tests/unit/bitfield.tcl
View file @
493a7f98
...
@@ -199,3 +199,34 @@ start_server {tags {"bitops"}} {
...
@@ -199,3 +199,34 @@ start_server {tags {"bitops"}} {
r del mystring
r del mystring
}
}
}
}
start_server
{
tags
{
"repl"
}}
{
start_server
{}
{
set master
[
srv -1 client
]
set master_host
[
srv -1 host
]
set master_port
[
srv -1 port
]
set slave
[
srv 0 client
]
test
{
setup slave
}
{
$slave slaveof $master_host $master_port
wait_for_condition 50 100
{
[
s 0 master_link_status
]
eq
{
up
}
}
else
{
fail
"Replication not started."
}
}
test
{
write on master, read on slave
}
{
$master del bits
assert_equal 0
[
$master
bitfield bits set u8 0 255
]
assert_equal 255
[
$master
bitfield bits set u8 0 100
]
wait_for_ofs_sync $master $slave
assert_equal 100
[
$slave
bitfield_ro bits get u8 0
]
}
test
{
bitfield_ro with write option
}
{
catch
{
$slave
bitfield_ro bits set u8 0 100 get u8 0
}
err
assert_match
{
*ERR bitfield_ro only support get subcommand*
}
$err
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment