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
14ff5724
Commit
14ff5724
authored
Jul 26, 2015
by
antirez
Browse files
RDMF: OBJ_ macros for object related stuff.
parent
554bd0e7
Changes
23
Expand all
Hide whitespace changes
Inline
Side-by-side
src/t_set.c
View file @
14ff5724
...
...
@@ -52,12 +52,12 @@ robj *setTypeCreate(robj *value) {
* returned, otherwise the new element is added and 1 is returned. */
int
setTypeAdd
(
robj
*
subject
,
robj
*
value
)
{
long
long
llval
;
if
(
subject
->
encoding
==
REDIS
_ENCODING_HT
)
{
if
(
subject
->
encoding
==
OBJ
_ENCODING_HT
)
{
if
(
dictAdd
(
subject
->
ptr
,
value
,
NULL
)
==
DICT_OK
)
{
incrRefCount
(
value
);
return
1
;
}
}
else
if
(
subject
->
encoding
==
REDIS
_ENCODING_INTSET
)
{
}
else
if
(
subject
->
encoding
==
OBJ
_ENCODING_INTSET
)
{
if
(
isObjectRepresentableAsLongLong
(
value
,
&
llval
)
==
REDIS_OK
)
{
uint8_t
success
=
0
;
subject
->
ptr
=
intsetAdd
(
subject
->
ptr
,
llval
,
&
success
);
...
...
@@ -65,12 +65,12 @@ int setTypeAdd(robj *subject, robj *value) {
/* Convert to regular set when the intset contains
* too many entries. */
if
(
intsetLen
(
subject
->
ptr
)
>
server
.
set_max_intset_entries
)
setTypeConvert
(
subject
,
REDIS
_ENCODING_HT
);
setTypeConvert
(
subject
,
OBJ
_ENCODING_HT
);
return
1
;
}
}
else
{
/* Failed to get integer from object, convert to regular set. */
setTypeConvert
(
subject
,
REDIS
_ENCODING_HT
);
setTypeConvert
(
subject
,
OBJ
_ENCODING_HT
);
/* The set *was* an intset and this value is not integer
* encodable, so dictAdd should always work. */
...
...
@@ -87,12 +87,12 @@ int setTypeAdd(robj *subject, robj *value) {
int
setTypeRemove
(
robj
*
setobj
,
robj
*
value
)
{
long
long
llval
;
if
(
setobj
->
encoding
==
REDIS
_ENCODING_HT
)
{
if
(
setobj
->
encoding
==
OBJ
_ENCODING_HT
)
{
if
(
dictDelete
(
setobj
->
ptr
,
value
)
==
DICT_OK
)
{
if
(
htNeedsResize
(
setobj
->
ptr
))
dictResize
(
setobj
->
ptr
);
return
1
;
}
}
else
if
(
setobj
->
encoding
==
REDIS
_ENCODING_INTSET
)
{
}
else
if
(
setobj
->
encoding
==
OBJ
_ENCODING_INTSET
)
{
if
(
isObjectRepresentableAsLongLong
(
value
,
&
llval
)
==
REDIS_OK
)
{
int
success
;
setobj
->
ptr
=
intsetRemove
(
setobj
->
ptr
,
llval
,
&
success
);
...
...
@@ -106,9 +106,9 @@ int setTypeRemove(robj *setobj, robj *value) {
int
setTypeIsMember
(
robj
*
subject
,
robj
*
value
)
{
long
long
llval
;
if
(
subject
->
encoding
==
REDIS
_ENCODING_HT
)
{
if
(
subject
->
encoding
==
OBJ
_ENCODING_HT
)
{
return
dictFind
((
dict
*
)
subject
->
ptr
,
value
)
!=
NULL
;
}
else
if
(
subject
->
encoding
==
REDIS
_ENCODING_INTSET
)
{
}
else
if
(
subject
->
encoding
==
OBJ
_ENCODING_INTSET
)
{
if
(
isObjectRepresentableAsLongLong
(
value
,
&
llval
)
==
REDIS_OK
)
{
return
intsetFind
((
intset
*
)
subject
->
ptr
,
llval
);
}
...
...
@@ -122,9 +122,9 @@ setTypeIterator *setTypeInitIterator(robj *subject) {
setTypeIterator
*
si
=
zmalloc
(
sizeof
(
setTypeIterator
));
si
->
subject
=
subject
;
si
->
encoding
=
subject
->
encoding
;
if
(
si
->
encoding
==
REDIS
_ENCODING_HT
)
{
if
(
si
->
encoding
==
OBJ
_ENCODING_HT
)
{
si
->
di
=
dictGetIterator
(
subject
->
ptr
);
}
else
if
(
si
->
encoding
==
REDIS
_ENCODING_INTSET
)
{
}
else
if
(
si
->
encoding
==
OBJ
_ENCODING_INTSET
)
{
si
->
ii
=
0
;
}
else
{
redisPanic
(
"Unknown set encoding"
);
...
...
@@ -133,7 +133,7 @@ setTypeIterator *setTypeInitIterator(robj *subject) {
}
void
setTypeReleaseIterator
(
setTypeIterator
*
si
)
{
if
(
si
->
encoding
==
REDIS
_ENCODING_HT
)
if
(
si
->
encoding
==
OBJ
_ENCODING_HT
)
dictReleaseIterator
(
si
->
di
);
zfree
(
si
);
}
...
...
@@ -154,12 +154,12 @@ void setTypeReleaseIterator(setTypeIterator *si) {
* Returned objects ref count is not incremented, so this function is
* copy on write friendly. */
int
setTypeNext
(
setTypeIterator
*
si
,
robj
**
objele
,
int64_t
*
llele
)
{
if
(
si
->
encoding
==
REDIS
_ENCODING_HT
)
{
if
(
si
->
encoding
==
OBJ
_ENCODING_HT
)
{
dictEntry
*
de
=
dictNext
(
si
->
di
);
if
(
de
==
NULL
)
return
-
1
;
*
objele
=
dictGetKey
(
de
);
*
llele
=
-
123456789
;
/* Not needed. Defensive. */
}
else
if
(
si
->
encoding
==
REDIS
_ENCODING_INTSET
)
{
}
else
if
(
si
->
encoding
==
OBJ
_ENCODING_INTSET
)
{
if
(
!
intsetGet
(
si
->
subject
->
ptr
,
si
->
ii
++
,
llele
))
return
-
1
;
*
objele
=
NULL
;
/* Not needed. Defensive. */
...
...
@@ -184,9 +184,9 @@ robj *setTypeNextObject(setTypeIterator *si) {
encoding
=
setTypeNext
(
si
,
&
objele
,
&
intele
);
switch
(
encoding
)
{
case
-
1
:
return
NULL
;
case
REDIS
_ENCODING_INTSET
:
case
OBJ
_ENCODING_INTSET
:
return
createStringObjectFromLongLong
(
intele
);
case
REDIS
_ENCODING_HT
:
case
OBJ
_ENCODING_HT
:
incrRefCount
(
objele
);
return
objele
;
default:
...
...
@@ -213,11 +213,11 @@ robj *setTypeNextObject(setTypeIterator *si) {
* of the object is not incremented so this function can be considered
* copy on write friendly. */
int
setTypeRandomElement
(
robj
*
setobj
,
robj
**
objele
,
int64_t
*
llele
)
{
if
(
setobj
->
encoding
==
REDIS
_ENCODING_HT
)
{
if
(
setobj
->
encoding
==
OBJ
_ENCODING_HT
)
{
dictEntry
*
de
=
dictGetRandomKey
(
setobj
->
ptr
);
*
objele
=
dictGetKey
(
de
);
*
llele
=
-
123456789
;
/* Not needed. Defensive. */
}
else
if
(
setobj
->
encoding
==
REDIS
_ENCODING_INTSET
)
{
}
else
if
(
setobj
->
encoding
==
OBJ
_ENCODING_INTSET
)
{
*
llele
=
intsetRandom
(
setobj
->
ptr
);
*
objele
=
NULL
;
/* Not needed. Defensive. */
}
else
{
...
...
@@ -227,9 +227,9 @@ int setTypeRandomElement(robj *setobj, robj **objele, int64_t *llele) {
}
unsigned
long
setTypeSize
(
robj
*
subject
)
{
if
(
subject
->
encoding
==
REDIS
_ENCODING_HT
)
{
if
(
subject
->
encoding
==
OBJ
_ENCODING_HT
)
{
return
dictSize
((
dict
*
)
subject
->
ptr
);
}
else
if
(
subject
->
encoding
==
REDIS
_ENCODING_INTSET
)
{
}
else
if
(
subject
->
encoding
==
OBJ
_ENCODING_INTSET
)
{
return
intsetLen
((
intset
*
)
subject
->
ptr
);
}
else
{
redisPanic
(
"Unknown set encoding"
);
...
...
@@ -241,10 +241,10 @@ unsigned long setTypeSize(robj *subject) {
* set. */
void
setTypeConvert
(
robj
*
setobj
,
int
enc
)
{
setTypeIterator
*
si
;
redisAssertWithInfo
(
NULL
,
setobj
,
setobj
->
type
==
REDIS
_SET
&&
setobj
->
encoding
==
REDIS
_ENCODING_INTSET
);
redisAssertWithInfo
(
NULL
,
setobj
,
setobj
->
type
==
OBJ
_SET
&&
setobj
->
encoding
==
OBJ
_ENCODING_INTSET
);
if
(
enc
==
REDIS
_ENCODING_HT
)
{
if
(
enc
==
OBJ
_ENCODING_HT
)
{
int64_t
intele
;
dict
*
d
=
dictCreate
(
&
setDictType
,
NULL
);
robj
*
element
;
...
...
@@ -261,7 +261,7 @@ void setTypeConvert(robj *setobj, int enc) {
}
setTypeReleaseIterator
(
si
);
setobj
->
encoding
=
REDIS
_ENCODING_HT
;
setobj
->
encoding
=
OBJ
_ENCODING_HT
;
zfree
(
setobj
->
ptr
);
setobj
->
ptr
=
d
;
}
else
{
...
...
@@ -278,7 +278,7 @@ void saddCommand(client *c) {
set
=
setTypeCreate
(
c
->
argv
[
2
]);
dbAdd
(
c
->
db
,
c
->
argv
[
1
],
set
);
}
else
{
if
(
set
->
type
!=
REDIS
_SET
)
{
if
(
set
->
type
!=
OBJ
_SET
)
{
addReply
(
c
,
shared
.
wrongtypeerr
);
return
;
}
...
...
@@ -301,7 +301,7 @@ void sremCommand(client *c) {
int
j
,
deleted
=
0
,
keyremoved
=
0
;
if
((
set
=
lookupKeyWriteOrReply
(
c
,
c
->
argv
[
1
],
shared
.
czero
))
==
NULL
||
checkType
(
c
,
set
,
REDIS
_SET
))
return
;
checkType
(
c
,
set
,
OBJ
_SET
))
return
;
for
(
j
=
2
;
j
<
c
->
argc
;
j
++
)
{
if
(
setTypeRemove
(
set
,
c
->
argv
[
j
]))
{
...
...
@@ -338,8 +338,8 @@ void smoveCommand(client *c) {
/* If the source key has the wrong type, or the destination key
* is set and has the wrong type, return with an error. */
if
(
checkType
(
c
,
srcset
,
REDIS
_SET
)
||
(
dstset
&&
checkType
(
c
,
dstset
,
REDIS
_SET
)))
return
;
if
(
checkType
(
c
,
srcset
,
OBJ
_SET
)
||
(
dstset
&&
checkType
(
c
,
dstset
,
OBJ
_SET
)))
return
;
/* If srcset and dstset are equal, SMOVE is a no-op */
if
(
srcset
==
dstset
)
{
...
...
@@ -381,7 +381,7 @@ void sismemberCommand(client *c) {
robj
*
set
;
if
((
set
=
lookupKeyReadOrReply
(
c
,
c
->
argv
[
1
],
shared
.
czero
))
==
NULL
||
checkType
(
c
,
set
,
REDIS
_SET
))
return
;
checkType
(
c
,
set
,
OBJ
_SET
))
return
;
c
->
argv
[
2
]
=
tryObjectEncoding
(
c
->
argv
[
2
]);
if
(
setTypeIsMember
(
set
,
c
->
argv
[
2
]))
...
...
@@ -394,7 +394,7 @@ void scardCommand(client *c) {
robj
*
o
;
if
((
o
=
lookupKeyReadOrReply
(
c
,
c
->
argv
[
1
],
shared
.
czero
))
==
NULL
||
checkType
(
c
,
o
,
REDIS
_SET
))
return
;
checkType
(
c
,
o
,
OBJ
_SET
))
return
;
addReplyLongLong
(
c
,
setTypeSize
(
o
));
}
...
...
@@ -424,7 +424,7 @@ void spopWithCountCommand(client *c) {
/* Make sure a key with the name inputted exists, and that it's type is
* indeed a set. Otherwise, return nil */
if
((
set
=
lookupKeyReadOrReply
(
c
,
c
->
argv
[
1
],
shared
.
emptymultibulk
))
==
NULL
||
checkType
(
c
,
set
,
REDIS
_SET
))
return
;
==
NULL
||
checkType
(
c
,
set
,
OBJ
_SET
))
return
;
/* If count is zero, serve an empty multibulk ASAP to avoid special
* cases later. */
...
...
@@ -481,7 +481,7 @@ void spopWithCountCommand(client *c) {
if
(
remaining
*
SPOP_MOVE_STRATEGY_MUL
>
count
)
{
while
(
count
--
)
{
encoding
=
setTypeRandomElement
(
set
,
&
objele
,
&
llele
);
if
(
encoding
==
REDIS
_ENCODING_INTSET
)
{
if
(
encoding
==
OBJ
_ENCODING_INTSET
)
{
objele
=
createStringObjectFromLongLong
(
llele
);
}
else
{
incrRefCount
(
objele
);
...
...
@@ -511,7 +511,7 @@ void spopWithCountCommand(client *c) {
/* Create a new set with just the remaining elements. */
while
(
remaining
--
)
{
encoding
=
setTypeRandomElement
(
set
,
&
objele
,
&
llele
);
if
(
encoding
==
REDIS
_ENCODING_INTSET
)
{
if
(
encoding
==
OBJ
_ENCODING_INTSET
)
{
objele
=
createStringObjectFromLongLong
(
llele
);
}
else
{
incrRefCount
(
objele
);
...
...
@@ -530,7 +530,7 @@ void spopWithCountCommand(client *c) {
setTypeIterator
*
si
;
si
=
setTypeInitIterator
(
set
);
while
((
encoding
=
setTypeNext
(
si
,
&
objele
,
&
llele
))
!=
-
1
)
{
if
(
encoding
==
REDIS
_ENCODING_INTSET
)
{
if
(
encoding
==
OBJ
_ENCODING_INTSET
)
{
objele
=
createStringObjectFromLongLong
(
llele
);
}
else
{
incrRefCount
(
objele
);
...
...
@@ -572,13 +572,13 @@ void spopCommand(client *c) {
/* Make sure a key with the name inputted exists, and that it's type is
* indeed a set */
if
((
set
=
lookupKeyWriteOrReply
(
c
,
c
->
argv
[
1
],
shared
.
nullbulk
))
==
NULL
||
checkType
(
c
,
set
,
REDIS
_SET
))
return
;
checkType
(
c
,
set
,
OBJ
_SET
))
return
;
/* Get a random element from the set */
encoding
=
setTypeRandomElement
(
set
,
&
ele
,
&
llele
);
/* Remove the element from the set */
if
(
encoding
==
REDIS
_ENCODING_INTSET
)
{
if
(
encoding
==
OBJ
_ENCODING_INTSET
)
{
ele
=
createStringObjectFromLongLong
(
llele
);
set
->
ptr
=
intsetRemove
(
set
->
ptr
,
llele
,
NULL
);
}
else
{
...
...
@@ -637,7 +637,7 @@ void srandmemberWithCountCommand(client *c) {
}
if
((
set
=
lookupKeyReadOrReply
(
c
,
c
->
argv
[
1
],
shared
.
emptymultibulk
))
==
NULL
||
checkType
(
c
,
set
,
REDIS
_SET
))
return
;
==
NULL
||
checkType
(
c
,
set
,
OBJ
_SET
))
return
;
size
=
setTypeSize
(
set
);
/* If count is zero, serve it ASAP to avoid special cases later. */
...
...
@@ -654,7 +654,7 @@ void srandmemberWithCountCommand(client *c) {
addReplyMultiBulkLen
(
c
,
count
);
while
(
count
--
)
{
encoding
=
setTypeRandomElement
(
set
,
&
ele
,
&
llele
);
if
(
encoding
==
REDIS
_ENCODING_INTSET
)
{
if
(
encoding
==
OBJ
_ENCODING_INTSET
)
{
addReplyBulkLongLong
(
c
,
llele
);
}
else
{
addReplyBulk
(
c
,
ele
);
...
...
@@ -691,7 +691,7 @@ void srandmemberWithCountCommand(client *c) {
while
((
encoding
=
setTypeNext
(
si
,
&
ele
,
&
llele
))
!=
-
1
)
{
int
retval
=
DICT_ERR
;
if
(
encoding
==
REDIS
_ENCODING_INTSET
)
{
if
(
encoding
==
OBJ
_ENCODING_INTSET
)
{
retval
=
dictAdd
(
d
,
createStringObjectFromLongLong
(
llele
),
NULL
);
}
else
{
retval
=
dictAdd
(
d
,
dupStringObject
(
ele
),
NULL
);
...
...
@@ -720,7 +720,7 @@ void srandmemberWithCountCommand(client *c) {
while
(
added
<
count
)
{
encoding
=
setTypeRandomElement
(
set
,
&
ele
,
&
llele
);
if
(
encoding
==
REDIS
_ENCODING_INTSET
)
{
if
(
encoding
==
OBJ
_ENCODING_INTSET
)
{
ele
=
createStringObjectFromLongLong
(
llele
);
}
else
{
ele
=
dupStringObject
(
ele
);
...
...
@@ -763,10 +763,10 @@ void srandmemberCommand(client *c) {
}
if
((
set
=
lookupKeyReadOrReply
(
c
,
c
->
argv
[
1
],
shared
.
nullbulk
))
==
NULL
||
checkType
(
c
,
set
,
REDIS
_SET
))
return
;
checkType
(
c
,
set
,
OBJ
_SET
))
return
;
encoding
=
setTypeRandomElement
(
set
,
&
ele
,
&
llele
);
if
(
encoding
==
REDIS
_ENCODING_INTSET
)
{
if
(
encoding
==
OBJ
_ENCODING_INTSET
)
{
addReplyBulkLongLong
(
c
,
llele
);
}
else
{
addReplyBulk
(
c
,
ele
);
...
...
@@ -812,7 +812,7 @@ void sinterGenericCommand(client *c, robj **setkeys,
}
return
;
}
if
(
checkType
(
c
,
setobj
,
REDIS
_SET
))
{
if
(
checkType
(
c
,
setobj
,
OBJ
_SET
))
{
zfree
(
sets
);
return
;
}
...
...
@@ -842,16 +842,16 @@ void sinterGenericCommand(client *c, robj **setkeys,
while
((
encoding
=
setTypeNext
(
si
,
&
eleobj
,
&
intobj
))
!=
-
1
)
{
for
(
j
=
1
;
j
<
setnum
;
j
++
)
{
if
(
sets
[
j
]
==
sets
[
0
])
continue
;
if
(
encoding
==
REDIS
_ENCODING_INTSET
)
{
if
(
encoding
==
OBJ
_ENCODING_INTSET
)
{
/* intset with intset is simple... and fast */
if
(
sets
[
j
]
->
encoding
==
REDIS
_ENCODING_INTSET
&&
if
(
sets
[
j
]
->
encoding
==
OBJ
_ENCODING_INTSET
&&
!
intsetFind
((
intset
*
)
sets
[
j
]
->
ptr
,
intobj
))
{
break
;
/* in order to compare an integer with an object we
* have to use the generic function, creating an object
* for this */
}
else
if
(
sets
[
j
]
->
encoding
==
REDIS
_ENCODING_HT
)
{
}
else
if
(
sets
[
j
]
->
encoding
==
OBJ
_ENCODING_HT
)
{
eleobj
=
createStringObjectFromLongLong
(
intobj
);
if
(
!
setTypeIsMember
(
sets
[
j
],
eleobj
))
{
decrRefCount
(
eleobj
);
...
...
@@ -859,12 +859,12 @@ void sinterGenericCommand(client *c, robj **setkeys,
}
decrRefCount
(
eleobj
);
}
}
else
if
(
encoding
==
REDIS
_ENCODING_HT
)
{
}
else
if
(
encoding
==
OBJ
_ENCODING_HT
)
{
/* Optimization... if the source object is integer
* encoded AND the target set is an intset, we can get
* a much faster path. */
if
(
eleobj
->
encoding
==
REDIS
_ENCODING_INT
&&
sets
[
j
]
->
encoding
==
REDIS
_ENCODING_INTSET
&&
if
(
eleobj
->
encoding
==
OBJ
_ENCODING_INT
&&
sets
[
j
]
->
encoding
==
OBJ
_ENCODING_INTSET
&&
!
intsetFind
((
intset
*
)
sets
[
j
]
->
ptr
,(
long
)
eleobj
->
ptr
))
{
break
;
...
...
@@ -879,13 +879,13 @@ void sinterGenericCommand(client *c, robj **setkeys,
/* Only take action when all sets contain the member */
if
(
j
==
setnum
)
{
if
(
!
dstkey
)
{
if
(
encoding
==
REDIS
_ENCODING_HT
)
if
(
encoding
==
OBJ
_ENCODING_HT
)
addReplyBulk
(
c
,
eleobj
);
else
addReplyBulkLongLong
(
c
,
intobj
);
cardinality
++
;
}
else
{
if
(
encoding
==
REDIS
_ENCODING_INTSET
)
{
if
(
encoding
==
OBJ
_ENCODING_INTSET
)
{
eleobj
=
createStringObjectFromLongLong
(
intobj
);
setTypeAdd
(
dstset
,
eleobj
);
decrRefCount
(
eleobj
);
...
...
@@ -949,7 +949,7 @@ void sunionDiffGenericCommand(client *c, robj **setkeys, int setnum,
sets
[
j
]
=
NULL
;
continue
;
}
if
(
checkType
(
c
,
setobj
,
REDIS
_SET
))
{
if
(
checkType
(
c
,
setobj
,
OBJ
_SET
))
{
zfree
(
sets
);
return
;
}
...
...
@@ -1114,6 +1114,6 @@ void sscanCommand(client *c) {
if
(
parseScanCursorOrReply
(
c
,
c
->
argv
[
2
],
&
cursor
)
==
REDIS_ERR
)
return
;
if
((
set
=
lookupKeyReadOrReply
(
c
,
c
->
argv
[
1
],
shared
.
emptyscan
))
==
NULL
||
checkType
(
c
,
set
,
REDIS
_SET
))
return
;
checkType
(
c
,
set
,
OBJ
_SET
))
return
;
scanGenericCommand
(
c
,
set
,
cursor
);
}
src/t_string.c
View file @
14ff5724
...
...
@@ -58,11 +58,11 @@ static int checkStringLength(client *c, long long size) {
* If ok_reply is NULL "+OK" is used.
* If abort_reply is NULL, "$-1" is used. */
#define
REDIS
_SET_NO_FLAGS 0
#define
REDIS
_SET_NX (1<<0)
/* Set if key not exists. */
#define
REDIS
_SET_XX (1<<1)
/* Set if key exists. */
#define
REDIS
_SET_EX (1<<2)
/* Set if time in seconds is given */
#define
REDIS
_SET_PX (1<<3)
/* Set if time in ms in given */
#define
OBJ
_SET_NO_FLAGS 0
#define
OBJ
_SET_NX (1<<0)
/* Set if key not exists. */
#define
OBJ
_SET_XX (1<<1)
/* Set if key exists. */
#define
OBJ
_SET_EX (1<<2)
/* Set if time in seconds is given */
#define
OBJ
_SET_PX (1<<3)
/* Set if time in ms in given */
void
setGenericCommand
(
client
*
c
,
int
flags
,
robj
*
key
,
robj
*
val
,
robj
*
expire
,
int
unit
,
robj
*
ok_reply
,
robj
*
abort_reply
)
{
long
long
milliseconds
=
0
;
/* initialized to avoid any harmness warning */
...
...
@@ -77,8 +77,8 @@ void setGenericCommand(client *c, int flags, robj *key, robj *val, robj *expire,
if
(
unit
==
UNIT_SECONDS
)
milliseconds
*=
1000
;
}
if
((
flags
&
REDIS
_SET_NX
&&
lookupKeyWrite
(
c
->
db
,
key
)
!=
NULL
)
||
(
flags
&
REDIS
_SET_XX
&&
lookupKeyWrite
(
c
->
db
,
key
)
==
NULL
))
if
((
flags
&
OBJ
_SET_NX
&&
lookupKeyWrite
(
c
->
db
,
key
)
!=
NULL
)
||
(
flags
&
OBJ
_SET_XX
&&
lookupKeyWrite
(
c
->
db
,
key
)
==
NULL
))
{
addReply
(
c
,
abort_reply
?
abort_reply
:
shared
.
nullbulk
);
return
;
...
...
@@ -97,7 +97,7 @@ void setCommand(client *c) {
int
j
;
robj
*
expire
=
NULL
;
int
unit
=
UNIT_SECONDS
;
int
flags
=
REDIS
_SET_NO_FLAGS
;
int
flags
=
OBJ
_SET_NO_FLAGS
;
for
(
j
=
3
;
j
<
c
->
argc
;
j
++
)
{
char
*
a
=
c
->
argv
[
j
]
->
ptr
;
...
...
@@ -105,27 +105,27 @@ void setCommand(client *c) {
if
((
a
[
0
]
==
'n'
||
a
[
0
]
==
'N'
)
&&
(
a
[
1
]
==
'x'
||
a
[
1
]
==
'X'
)
&&
a
[
2
]
==
'\0'
&&
!
(
flags
&
REDIS
_SET_XX
))
!
(
flags
&
OBJ
_SET_XX
))
{
flags
|=
REDIS
_SET_NX
;
flags
|=
OBJ
_SET_NX
;
}
else
if
((
a
[
0
]
==
'x'
||
a
[
0
]
==
'X'
)
&&
(
a
[
1
]
==
'x'
||
a
[
1
]
==
'X'
)
&&
a
[
2
]
==
'\0'
&&
!
(
flags
&
REDIS
_SET_NX
))
!
(
flags
&
OBJ
_SET_NX
))
{
flags
|=
REDIS
_SET_XX
;
flags
|=
OBJ
_SET_XX
;
}
else
if
((
a
[
0
]
==
'e'
||
a
[
0
]
==
'E'
)
&&
(
a
[
1
]
==
'x'
||
a
[
1
]
==
'X'
)
&&
a
[
2
]
==
'\0'
&&
!
(
flags
&
REDIS
_SET_PX
)
&&
next
)
!
(
flags
&
OBJ
_SET_PX
)
&&
next
)
{
flags
|=
REDIS
_SET_EX
;
flags
|=
OBJ
_SET_EX
;
unit
=
UNIT_SECONDS
;
expire
=
next
;
j
++
;
}
else
if
((
a
[
0
]
==
'p'
||
a
[
0
]
==
'P'
)
&&
(
a
[
1
]
==
'x'
||
a
[
1
]
==
'X'
)
&&
a
[
2
]
==
'\0'
&&
!
(
flags
&
REDIS
_SET_EX
)
&&
next
)
!
(
flags
&
OBJ
_SET_EX
)
&&
next
)
{
flags
|=
REDIS
_SET_PX
;
flags
|=
OBJ
_SET_PX
;
unit
=
UNIT_MILLISECONDS
;
expire
=
next
;
j
++
;
...
...
@@ -141,17 +141,17 @@ void setCommand(client *c) {
void
setnxCommand
(
client
*
c
)
{
c
->
argv
[
2
]
=
tryObjectEncoding
(
c
->
argv
[
2
]);
setGenericCommand
(
c
,
REDIS
_SET_NX
,
c
->
argv
[
1
],
c
->
argv
[
2
],
NULL
,
0
,
shared
.
cone
,
shared
.
czero
);
setGenericCommand
(
c
,
OBJ
_SET_NX
,
c
->
argv
[
1
],
c
->
argv
[
2
],
NULL
,
0
,
shared
.
cone
,
shared
.
czero
);
}
void
setexCommand
(
client
*
c
)
{
c
->
argv
[
3
]
=
tryObjectEncoding
(
c
->
argv
[
3
]);
setGenericCommand
(
c
,
REDIS
_SET_NO_FLAGS
,
c
->
argv
[
1
],
c
->
argv
[
3
],
c
->
argv
[
2
],
UNIT_SECONDS
,
NULL
,
NULL
);
setGenericCommand
(
c
,
OBJ
_SET_NO_FLAGS
,
c
->
argv
[
1
],
c
->
argv
[
3
],
c
->
argv
[
2
],
UNIT_SECONDS
,
NULL
,
NULL
);
}
void
psetexCommand
(
client
*
c
)
{
c
->
argv
[
3
]
=
tryObjectEncoding
(
c
->
argv
[
3
]);
setGenericCommand
(
c
,
REDIS
_SET_NO_FLAGS
,
c
->
argv
[
1
],
c
->
argv
[
3
],
c
->
argv
[
2
],
UNIT_MILLISECONDS
,
NULL
,
NULL
);
setGenericCommand
(
c
,
OBJ
_SET_NO_FLAGS
,
c
->
argv
[
1
],
c
->
argv
[
3
],
c
->
argv
[
2
],
UNIT_MILLISECONDS
,
NULL
,
NULL
);
}
int
getGenericCommand
(
client
*
c
)
{
...
...
@@ -160,7 +160,7 @@ int getGenericCommand(client *c) {
if
((
o
=
lookupKeyReadOrReply
(
c
,
c
->
argv
[
1
],
shared
.
nullbulk
))
==
NULL
)
return
REDIS_OK
;
if
(
o
->
type
!=
REDIS
_STRING
)
{
if
(
o
->
type
!=
OBJ
_STRING
)
{
addReply
(
c
,
shared
.
wrongtypeerr
);
return
REDIS_ERR
;
}
else
{
...
...
@@ -206,13 +206,13 @@ void setrangeCommand(client *c) {
if
(
checkStringLength
(
c
,
offset
+
sdslen
(
value
))
!=
REDIS_OK
)
return
;
o
=
createObject
(
REDIS
_STRING
,
sdsnewlen
(
NULL
,
offset
+
sdslen
(
value
)));
o
=
createObject
(
OBJ
_STRING
,
sdsnewlen
(
NULL
,
offset
+
sdslen
(
value
)));
dbAdd
(
c
->
db
,
c
->
argv
[
1
],
o
);
}
else
{
size_t
olen
;
/* Key exists, check type */
if
(
checkType
(
c
,
o
,
REDIS
_STRING
))
if
(
checkType
(
c
,
o
,
OBJ
_STRING
))
return
;
/* Return existing string length when setting nothing */
...
...
@@ -252,9 +252,9 @@ void getrangeCommand(client *c) {
if
(
getLongLongFromObjectOrReply
(
c
,
c
->
argv
[
3
],
&
end
,
NULL
)
!=
REDIS_OK
)
return
;
if
((
o
=
lookupKeyReadOrReply
(
c
,
c
->
argv
[
1
],
shared
.
emptybulk
))
==
NULL
||
checkType
(
c
,
o
,
REDIS
_STRING
))
return
;
checkType
(
c
,
o
,
OBJ
_STRING
))
return
;
if
(
o
->
encoding
==
REDIS
_ENCODING_INT
)
{
if
(
o
->
encoding
==
OBJ
_ENCODING_INT
)
{
str
=
llbuf
;
strlen
=
ll2string
(
llbuf
,
sizeof
(
llbuf
),(
long
)
o
->
ptr
);
}
else
{
...
...
@@ -287,7 +287,7 @@ void mgetCommand(client *c) {
if
(
o
==
NULL
)
{
addReply
(
c
,
shared
.
nullbulk
);
}
else
{
if
(
o
->
type
!=
REDIS
_STRING
)
{
if
(
o
->
type
!=
OBJ
_STRING
)
{
addReply
(
c
,
shared
.
nullbulk
);
}
else
{
addReplyBulk
(
c
,
o
);
...
...
@@ -339,7 +339,7 @@ void incrDecrCommand(client *c, long long incr) {
robj
*
o
,
*
new
;
o
=
lookupKeyWrite
(
c
->
db
,
c
->
argv
[
1
]);
if
(
o
!=
NULL
&&
checkType
(
c
,
o
,
REDIS
_STRING
))
return
;
if
(
o
!=
NULL
&&
checkType
(
c
,
o
,
OBJ
_STRING
))
return
;
if
(
getLongLongFromObjectOrReply
(
c
,
o
,
&
value
,
NULL
)
!=
REDIS_OK
)
return
;
oldvalue
=
value
;
...
...
@@ -350,7 +350,7 @@ void incrDecrCommand(client *c, long long incr) {
}
value
+=
incr
;
if
(
o
&&
o
->
refcount
==
1
&&
o
->
encoding
==
REDIS
_ENCODING_INT
&&
if
(
o
&&
o
->
refcount
==
1
&&
o
->
encoding
==
OBJ
_ENCODING_INT
&&
(
value
<
0
||
value
>=
REDIS_SHARED_INTEGERS
)
&&
value
>=
LONG_MIN
&&
value
<=
LONG_MAX
)
{
...
...
@@ -399,7 +399,7 @@ void incrbyfloatCommand(client *c) {
robj
*
o
,
*
new
,
*
aux
;
o
=
lookupKeyWrite
(
c
->
db
,
c
->
argv
[
1
]);
if
(
o
!=
NULL
&&
checkType
(
c
,
o
,
REDIS
_STRING
))
return
;
if
(
o
!=
NULL
&&
checkType
(
c
,
o
,
OBJ
_STRING
))
return
;
if
(
getLongDoubleFromObjectOrReply
(
c
,
o
,
&
value
,
NULL
)
!=
REDIS_OK
||
getLongDoubleFromObjectOrReply
(
c
,
c
->
argv
[
2
],
&
incr
,
NULL
)
!=
REDIS_OK
)
return
;
...
...
@@ -441,7 +441,7 @@ void appendCommand(client *c) {
totlen
=
stringObjectLen
(
c
->
argv
[
2
]);
}
else
{
/* Key exists, check type */
if
(
checkType
(
c
,
o
,
REDIS
_STRING
))
if
(
checkType
(
c
,
o
,
OBJ
_STRING
))
return
;
/* "append" is an argument, so always an sds */
...
...
@@ -464,6 +464,6 @@ void appendCommand(client *c) {
void
strlenCommand
(
client
*
c
)
{
robj
*
o
;
if
((
o
=
lookupKeyReadOrReply
(
c
,
c
->
argv
[
1
],
shared
.
czero
))
==
NULL
||
checkType
(
c
,
o
,
REDIS
_STRING
))
return
;
checkType
(
c
,
o
,
OBJ
_STRING
))
return
;
addReplyLongLong
(
c
,
stringObjectLen
(
o
));
}
src/t_zset.c
View file @
14ff5724
This diff is collapsed.
Click to expand it.
Prev
1
2
Next
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