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
6c446631
Commit
6c446631
authored
Nov 24, 2009
by
antirez
Browse files
sorted sets saving fixed
parent
f284d963
Changes
1
Hide whitespace changes
Inline
Side-by-side
redis.c
View file @
6c446631
...
@@ -2451,7 +2451,7 @@ static int rdbSaveDoubleValue(FILE *fp, double val) {
...
@@ -2451,7 +2451,7 @@ static int rdbSaveDoubleValue(FILE *fp, double val) {
buf
[
0
]
=
(
val
<
0
)
?
255
:
254
;
buf
[
0
]
=
(
val
<
0
)
?
255
:
254
;
}
else
{
}
else
{
snprintf
((
char
*
)
buf
+
1
,
sizeof
(
buf
)
-
1
,
"%.17g"
,
val
);
snprintf
((
char
*
)
buf
+
1
,
sizeof
(
buf
)
-
1
,
"%.17g"
,
val
);
buf
[
0
]
=
strlen
((
char
*
)
buf
);
buf
[
0
]
=
strlen
((
char
*
)
buf
+
1
);
len
=
buf
[
0
]
+
1
;
len
=
buf
[
0
]
+
1
;
}
}
if
(
fwrite
(
buf
,
len
,
1
,
fp
)
==
0
)
return
-
1
;
if
(
fwrite
(
buf
,
len
,
1
,
fp
)
==
0
)
return
-
1
;
...
@@ -2976,6 +2976,49 @@ static void mgetCommand(redisClient *c) {
...
@@ -2976,6 +2976,49 @@ static void mgetCommand(redisClient *c) {
}
}
}
}
static
void
msetGenericCommand
(
redisClient
*
c
,
int
nx
)
{
int
j
;
if
((
c
->
argc
%
2
)
==
0
)
{
addReplySds
(
c
,
sdsnew
(
"-ERR wrong number of arguments
\r\n
"
));
return
;
}
/* Handle the NX flag. The MSETNX semantic is to return zero and don't
* set nothing at all if at least one already key exists. */
if
(
nx
)
{
for
(
j
=
1
;
j
<
c
->
argc
;
j
+=
2
)
{
if
(
dictFind
(
c
->
db
->
dict
,
c
->
argv
[
j
])
!=
NULL
)
{
addReply
(
c
,
shared
.
czero
);
return
;
}
}
}
for
(
j
=
1
;
j
<
c
->
argc
;
j
+=
2
)
{
int
retval
;
retval
=
dictAdd
(
c
->
db
->
dict
,
c
->
argv
[
j
],
c
->
argv
[
j
+
1
]);
if
(
retval
==
DICT_ERR
)
{
dictReplace
(
c
->
db
->
dict
,
c
->
argv
[
j
],
c
->
argv
[
j
+
1
]);
incrRefCount
(
c
->
argv
[
j
+
1
]);
}
else
{
incrRefCount
(
c
->
argv
[
j
]);
incrRefCount
(
c
->
argv
[
j
+
1
]);
}
removeExpire
(
c
->
db
,
c
->
argv
[
j
]);
}
server
.
dirty
+=
(
c
->
argc
-
1
)
/
2
;
addReply
(
c
,
nx
?
shared
.
cone
:
shared
.
ok
);
}
static
void
msetCommand
(
redisClient
*
c
)
{
msetGenericCommand
(
c
,
0
);
}
static
void
msetnxCommand
(
redisClient
*
c
)
{
msetGenericCommand
(
c
,
1
);
}
static
void
incrDecrCommand
(
redisClient
*
c
,
long
long
incr
)
{
static
void
incrDecrCommand
(
redisClient
*
c
,
long
long
incr
)
{
long
long
value
;
long
long
value
;
int
retval
;
int
retval
;
...
@@ -5094,49 +5137,6 @@ static void ttlCommand(redisClient *c) {
...
@@ -5094,49 +5137,6 @@ static void ttlCommand(redisClient *c) {
addReplySds
(
c
,
sdscatprintf
(
sdsempty
(),
":%d
\r\n
"
,
ttl
));
addReplySds
(
c
,
sdscatprintf
(
sdsempty
(),
":%d
\r\n
"
,
ttl
));
}
}
static
void
msetGenericCommand
(
redisClient
*
c
,
int
nx
)
{
int
j
;
if
((
c
->
argc
%
2
)
==
0
)
{
addReplySds
(
c
,
sdsnew
(
"-ERR wrong number of arguments
\r\n
"
));
return
;
}
/* Handle the NX flag. The MSETNX semantic is to return zero and don't
* set nothing at all if at least one already key exists. */
if
(
nx
)
{
for
(
j
=
1
;
j
<
c
->
argc
;
j
+=
2
)
{
if
(
dictFind
(
c
->
db
->
dict
,
c
->
argv
[
j
])
!=
NULL
)
{
addReply
(
c
,
shared
.
czero
);
return
;
}
}
}
for
(
j
=
1
;
j
<
c
->
argc
;
j
+=
2
)
{
int
retval
;
retval
=
dictAdd
(
c
->
db
->
dict
,
c
->
argv
[
j
],
c
->
argv
[
j
+
1
]);
if
(
retval
==
DICT_ERR
)
{
dictReplace
(
c
->
db
->
dict
,
c
->
argv
[
j
],
c
->
argv
[
j
+
1
]);
incrRefCount
(
c
->
argv
[
j
+
1
]);
}
else
{
incrRefCount
(
c
->
argv
[
j
]);
incrRefCount
(
c
->
argv
[
j
+
1
]);
}
removeExpire
(
c
->
db
,
c
->
argv
[
j
]);
}
server
.
dirty
+=
(
c
->
argc
-
1
)
/
2
;
addReply
(
c
,
nx
?
shared
.
cone
:
shared
.
ok
);
}
static
void
msetCommand
(
redisClient
*
c
)
{
msetGenericCommand
(
c
,
0
);
}
static
void
msetnxCommand
(
redisClient
*
c
)
{
msetGenericCommand
(
c
,
1
);
}
/* =============================== Replication ============================= */
/* =============================== Replication ============================= */
static
int
syncWrite
(
int
fd
,
char
*
ptr
,
ssize_t
size
,
int
timeout
)
{
static
int
syncWrite
(
int
fd
,
char
*
ptr
,
ssize_t
size
,
int
timeout
)
{
...
...
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