mirror of
https://github.com/fluencelabs/redis
synced 2025-06-13 01:01:22 +00:00
Merge pull request #6951 from yangbodong22011/feature-bitfield-ro
Added BITFIELD_RO variants for read-only operations.
This commit is contained in:
19
src/bitops.c
19
src/bitops.c
@ -902,6 +902,9 @@ void bitposCommand(client *c) {
|
||||
* OVERFLOW [WRAP|SAT|FAIL]
|
||||
*/
|
||||
|
||||
#define BITFIELD_COMMON (1<<0)
|
||||
#define BITFIELD_READONLY (1<<1)
|
||||
|
||||
struct bitfieldOp {
|
||||
uint64_t offset; /* Bitfield offset. */
|
||||
int64_t i64; /* Increment amount (INCRBY) or SET value */
|
||||
@ -911,7 +914,7 @@ struct bitfieldOp {
|
||||
int sign; /* True if signed, otherwise unsigned op. */
|
||||
};
|
||||
|
||||
void bitfieldCommand(client *c) {
|
||||
void bitfieldGeneric(client *c, int flags) {
|
||||
robj *o;
|
||||
size_t bitoffset;
|
||||
int j, numops = 0, changes = 0;
|
||||
@ -999,6 +1002,12 @@ void bitfieldCommand(client *c) {
|
||||
return;
|
||||
}
|
||||
} 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
|
||||
* this operation. */
|
||||
if ((o = lookupStringForBitCommand(c,
|
||||
@ -1129,3 +1138,11 @@ void bitfieldCommand(client *c) {
|
||||
}
|
||||
zfree(ops);
|
||||
}
|
||||
|
||||
void bitfieldCommand(client *c) {
|
||||
bitfieldGeneric(c, BITFIELD_COMMON);
|
||||
}
|
||||
|
||||
void bitfieldroCommand(client *c) {
|
||||
bitfieldGeneric(c, BITFIELD_READONLY);
|
||||
}
|
||||
|
@ -238,6 +238,10 @@ struct redisCommand redisCommandTable[] = {
|
||||
"write use-memory @bitmap",
|
||||
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,
|
||||
"write use-memory @string",
|
||||
0,NULL,1,1,1,0,0,0},
|
||||
|
@ -2177,6 +2177,7 @@ void existsCommand(client *c);
|
||||
void setbitCommand(client *c);
|
||||
void getbitCommand(client *c);
|
||||
void bitfieldCommand(client *c);
|
||||
void bitfieldroCommand(client *c);
|
||||
void setrangeCommand(client *c);
|
||||
void getrangeCommand(client *c);
|
||||
void incrCommand(client *c);
|
||||
|
Reference in New Issue
Block a user