Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Turbo码先生
redis
提交
2800d090
R
redis
项目概览
Turbo码先生
/
redis
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
redis
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2800d090
编写于
2月 26, 2016
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
BITFIELD: Support #<index> offsets form.
上级
70af626d
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
23 addition
and
6 deletion
+23
-6
src/bitops.c
src/bitops.c
+23
-6
未找到文件。
src/bitops.c
浏览文件 @
2800d090
...
...
@@ -388,13 +388,30 @@ void printBits(unsigned char *p, unsigned long count) {
/* This helper function used by GETBIT / SETBIT parses the bit offset argument
* making sure an error is returned if it is negative or if it overflows
* Redis 512 MB limit for the string value. */
int
getBitOffsetFromArgument
(
client
*
c
,
robj
*
o
,
size_t
*
offset
)
{
* Redis 512 MB limit for the string value.
*
* If the 'hash' argument is true, and 'bits is positive, then the command
* will also parse bit offsets prefixed by "#". In such a case the offset
* is multiplied by 'bits'. This is useful for the BITFIELD command. */
int
getBitOffsetFromArgument
(
client
*
c
,
robj
*
o
,
size_t
*
offset
,
int
hash
,
int
bits
)
{
long
long
loffset
;
char
*
err
=
"bit offset is not an integer or out of range"
;
char
*
p
=
o
->
ptr
;
size_t
plen
=
sdslen
(
p
);
/* Handle #<offset> form. */
if
(
hash
&&
bits
>
0
)
{
p
++
;
plen
--
;
}
if
(
getLongLongFromObjectOrReply
(
c
,
o
,
&
loffset
,
err
)
!=
C_OK
)
if
(
string2ll
(
p
,
plen
,
&
loffset
)
==
0
)
{
addReplyError
(
c
,
err
);
return
C_ERR
;
}
/* Adjust the offset by 'bits' for #<offset> form. */
if
(
hash
&&
bits
>
0
)
loffset
*=
bits
;
/* Limit offset to 512MB in bytes */
if
((
loffset
<
0
)
||
((
unsigned
long
long
)
loffset
>>
3
)
>=
(
512
*
1024
*
1024
))
...
...
@@ -469,7 +486,7 @@ void setbitCommand(client *c) {
int
byteval
,
bitval
;
long
on
;
if
(
getBitOffsetFromArgument
(
c
,
c
->
argv
[
2
],
&
bitoffset
)
!=
C_OK
)
if
(
getBitOffsetFromArgument
(
c
,
c
->
argv
[
2
],
&
bitoffset
,
0
,
0
)
!=
C_OK
)
return
;
if
(
getLongFromObjectOrReply
(
c
,
c
->
argv
[
3
],
&
on
,
err
)
!=
C_OK
)
...
...
@@ -507,7 +524,7 @@ void getbitCommand(client *c) {
size_t
byte
,
bit
;
size_t
bitval
=
0
;
if
(
getBitOffsetFromArgument
(
c
,
c
->
argv
[
2
],
&
bitoffset
)
!=
C_OK
)
if
(
getBitOffsetFromArgument
(
c
,
c
->
argv
[
2
],
&
bitoffset
,
0
,
0
)
!=
C_OK
)
return
;
if
((
o
=
lookupKeyReadOrReply
(
c
,
c
->
argv
[
1
],
shared
.
czero
))
==
NULL
||
...
...
@@ -908,7 +925,7 @@ void bitfieldCommand(client *c) {
return
;
}
if
(
getBitOffsetFromArgument
(
c
,
c
->
argv
[
j
+
2
],
&
bitoffset
)
!=
C_OK
)
{
if
(
getBitOffsetFromArgument
(
c
,
c
->
argv
[
j
+
2
],
&
bitoffset
,
1
,
bits
)
!=
C_OK
)
{
zfree
(
ops
);
return
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录