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
697bd567
Commit
697bd567
authored
May 30, 2010
by
Pieter Noordhuis
Browse files
inline support for dual encoding in the LINDEX and LSET commands
parent
d72562f7
Changes
1
Hide whitespace changes
Inline
Side-by-side
redis.c
View file @
697bd567
...
...
@@ -4878,45 +4878,69 @@ static void llenCommand(redisClient *c) {
}
static
void
lindexCommand
(
redisClient
*
c
)
{
robj
*
o
;
robj
*
o
=
lookupKeyReadOrReply
(
c
,
c
->
argv
[
1
],
shared
.
nullbulk
);
if
(
o
==
NULL
||
checkType
(
c
,
o
,
REDIS_LIST
))
return
;
int
index
=
atoi
(
c
->
argv
[
2
]
->
ptr
);
list
*
list
;
listNode
*
ln
;
if
((
o
=
lookupKeyReadOrReply
(
c
,
c
->
argv
[
1
],
shared
.
nullbulk
))
==
NULL
||
checkType
(
c
,
o
,
REDIS_LIST
))
return
;
list
=
o
->
ptr
;
ln
=
listIndex
(
list
,
index
);
if
(
ln
==
NULL
)
{
addReply
(
c
,
shared
.
nullbulk
);
if
(
o
->
encoding
==
REDIS_ENCODING_ZIPLIST
)
{
unsigned
char
*
p
;
char
*
v
;
unsigned
int
vlen
;
long
long
vval
;
p
=
ziplistIndex
(
o
->
ptr
,
index
);
if
(
ziplistGet
(
p
,
&
v
,
&
vlen
,
&
vval
))
{
if
(
v
)
{
addReplySds
(
c
,
sdsnewlen
(
v
,
vlen
));
}
else
{
addReplyLongLong
(
c
,
vval
);
}
}
else
{
addReply
(
c
,
shared
.
nullbulk
);
}
}
else
if
(
o
->
encoding
==
REDIS_ENCODING_LIST
)
{
listNode
*
ln
=
listIndex
(
o
->
ptr
,
index
);
if
(
ln
!=
NULL
)
{
addReply
(
c
,(
robj
*
)
listNodeValue
(
ln
));
}
else
{
addReply
(
c
,
shared
.
nullbulk
);
}
}
else
{
robj
*
ele
=
listNodeValue
(
ln
);
addReplyBulk
(
c
,
ele
);
redisPanic
(
"Unknown list encoding"
);
}
}
static
void
lsetCommand
(
redisClient
*
c
)
{
robj
*
o
;
robj
*
o
=
lookupKeyWriteOrReply
(
c
,
c
->
argv
[
1
],
shared
.
nokeyerr
);
if
(
o
==
NULL
||
checkType
(
c
,
o
,
REDIS_LIST
))
return
;
int
index
=
atoi
(
c
->
argv
[
2
]
->
ptr
);
list
*
list
;
listNode
*
ln
;
robj
*
value
=
c
->
argv
[
3
];
if
((
o
=
lookupKeyWriteOrReply
(
c
,
c
->
argv
[
1
],
shared
.
nokeyerr
))
==
NULL
||
checkType
(
c
,
o
,
REDIS_LIST
))
return
;
list
=
o
->
ptr
;
ln
=
listIndex
(
list
,
index
);
if
(
ln
==
NULL
)
{
addReply
(
c
,
shared
.
outofrangeerr
);
if
(
o
->
encoding
==
REDIS_ENCODING_ZIPLIST
)
{
unsigned
char
*
p
,
*
zl
=
o
->
ptr
;
p
=
ziplistIndex
(
zl
,
index
);
if
(
p
==
NULL
)
{
addReply
(
c
,
shared
.
outofrangeerr
);
}
else
{
o
->
ptr
=
ziplistDelete
(
o
->
ptr
,
&
p
,
ZIPLIST_TAIL
);
value
=
getDecodedObject
(
value
);
o
->
ptr
=
ziplistInsert
(
o
->
ptr
,
p
,
value
->
ptr
,
sdslen
(
value
->
ptr
));
decrRefCount
(
value
);
addReply
(
c
,
shared
.
ok
);
server
.
dirty
++
;
}
}
else
if
(
o
->
encoding
==
REDIS_ENCODING_LIST
)
{
listNode
*
ln
=
listIndex
(
o
->
ptr
,
index
);
if
(
ln
==
NULL
)
{
addReply
(
c
,
shared
.
outofrangeerr
);
}
else
{
decrRefCount
((
robj
*
)
listNodeValue
(
ln
));
listNodeValue
(
ln
)
=
value
;
incrRefCount
(
value
);
addReply
(
c
,
shared
.
ok
);
server
.
dirty
++
;
}
}
else
{
robj
*
ele
=
listNodeValue
(
ln
);
decrRefCount
(
ele
);
listNodeValue
(
ln
)
=
c
->
argv
[
3
];
incrRefCount
(
c
->
argv
[
3
]);
addReply
(
c
,
shared
.
ok
);
server
.
dirty
++
;
redisPanic
(
"Unknown list encoding"
);
}
}
...
...
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