Minor changes to BITFIELD_RO PR #6951.

This commit is contained in:
antirez 2020-03-23 11:28:09 +01:00
parent 493a7f9823
commit 38514e3c8d

View File

@ -902,8 +902,8 @@ void bitposCommand(client *c) {
* OVERFLOW [WRAP|SAT|FAIL] * OVERFLOW [WRAP|SAT|FAIL]
*/ */
#define BITFIELD_COMMON (1<<0) #define BITFIELD_FLAG_NONE 0
#define BITFIELD_READONLY (1<<1) #define BITFIELD_FLAG_READONLY (1<<0)
struct bitfieldOp { struct bitfieldOp {
uint64_t offset; /* Bitfield offset. */ uint64_t offset; /* Bitfield offset. */
@ -914,6 +914,9 @@ struct bitfieldOp {
int sign; /* True if signed, otherwise unsigned op. */ int sign; /* True if signed, otherwise unsigned op. */
}; };
/* This implements both the BITFIELD command and the BITFIELD_RO command
* when flags is set to BITFIELD_FLAG_READONLY: in this case only the
* GET subcommand is allowed, other subcommands will return an error. */
void bitfieldGeneric(client *c, int flags) { void bitfieldGeneric(client *c, int flags) {
robj *o; robj *o;
size_t bitoffset; size_t bitoffset;
@ -1002,9 +1005,9 @@ void bitfieldGeneric(client *c, int flags) {
return; return;
} }
} else { } else {
if (flags & BITFIELD_READONLY) { if (flags & BITFIELD_FLAG_READONLY) {
zfree(ops); zfree(ops);
addReplyError(c, "bitfield_ro only support get subcommand"); addReplyError(c, "BITFIELD_RO only support the GET subcommand");
return; return;
} }
@ -1140,9 +1143,9 @@ void bitfieldGeneric(client *c, int flags) {
} }
void bitfieldCommand(client *c) { void bitfieldCommand(client *c) {
bitfieldGeneric(c, BITFIELD_COMMON); bitfieldGeneric(c, BITFIELD_FLAG_NONE);
} }
void bitfieldroCommand(client *c) { void bitfieldroCommand(client *c) {
bitfieldGeneric(c, BITFIELD_READONLY); bitfieldGeneric(c, BITFIELD_FLAG_READONLY);
} }