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
554bd0e7
Commit
554bd0e7
authored
Jul 26, 2015
by
antirez
Browse files
RDMF: use client instead of redisClient, like Disque.
parent
424fe9af
Changes
29
Hide whitespace changes
Inline
Side-by-side
src/aof.c
View file @
554bd0e7
...
...
@@ -550,8 +550,8 @@ void feedAppendOnlyFile(struct redisCommand *cmd, int dictid, robj **argv, int a
/* In Redis commands are always executed in the context of a client, so in
* order to load the append only file we need to create a fake client. */
struct
redisC
lient
*
createFakeClient
(
void
)
{
struct
redisC
lient
*
c
=
zmalloc
(
sizeof
(
*
c
));
struct
c
lient
*
createFakeClient
(
void
)
{
struct
c
lient
*
c
=
zmalloc
(
sizeof
(
*
c
));
selectDb
(
c
,
0
);
c
->
fd
=
-
1
;
...
...
@@ -577,7 +577,7 @@ struct redisClient *createFakeClient(void) {
return
c
;
}
void
freeFakeClientArgv
(
struct
redisC
lient
*
c
)
{
void
freeFakeClientArgv
(
struct
c
lient
*
c
)
{
int
j
;
for
(
j
=
0
;
j
<
c
->
argc
;
j
++
)
...
...
@@ -585,7 +585,7 @@ void freeFakeClientArgv(struct redisClient *c) {
zfree
(
c
->
argv
);
}
void
freeFakeClient
(
struct
redisC
lient
*
c
)
{
void
freeFakeClient
(
struct
c
lient
*
c
)
{
sdsfree
(
c
->
querybuf
);
listRelease
(
c
->
reply
);
listRelease
(
c
->
watched_keys
);
...
...
@@ -597,7 +597,7 @@ void freeFakeClient(struct redisClient *c) {
* error (the append only file is zero-length) REDIS_ERR is returned. On
* fatal error an error message is logged and the program exists. */
int
loadAppendOnlyFile
(
char
*
filename
)
{
struct
redisC
lient
*
fakeClient
;
struct
c
lient
*
fakeClient
;
FILE
*
fp
=
fopen
(
filename
,
"r"
);
struct
redis_stat
sb
;
int
old_aof_state
=
server
.
aof_state
;
...
...
@@ -1297,7 +1297,7 @@ int rewriteAppendOnlyFileBackground(void) {
return
REDIS_OK
;
/* unreached */
}
void
bgrewriteaofCommand
(
redisC
lient
*
c
)
{
void
bgrewriteaofCommand
(
c
lient
*
c
)
{
if
(
server
.
aof_child_pid
!=
-
1
)
{
addReplyError
(
c
,
"Background append only file rewriting already in progress"
);
}
else
if
(
server
.
rdb_child_pid
!=
-
1
)
{
...
...
src/bitops.c
View file @
554bd0e7
...
...
@@ -37,7 +37,7 @@
/* 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. */
static
int
getBitOffsetFromArgument
(
redisC
lient
*
c
,
robj
*
o
,
size_t
*
offset
)
{
static
int
getBitOffsetFromArgument
(
c
lient
*
c
,
robj
*
o
,
size_t
*
offset
)
{
long
long
loffset
;
char
*
err
=
"bit offset is not an integer or out of range"
;
...
...
@@ -209,7 +209,7 @@ long redisBitpos(void *s, unsigned long count, int bit) {
#define BITOP_NOT 3
/* SETBIT key offset bitvalue */
void
setbitCommand
(
redisC
lient
*
c
)
{
void
setbitCommand
(
c
lient
*
c
)
{
robj
*
o
;
char
*
err
=
"bit is not an integer or out of range"
;
size_t
bitoffset
;
...
...
@@ -256,7 +256,7 @@ void setbitCommand(redisClient *c) {
}
/* GETBIT key offset */
void
getbitCommand
(
redisC
lient
*
c
)
{
void
getbitCommand
(
c
lient
*
c
)
{
robj
*
o
;
char
llbuf
[
32
];
size_t
bitoffset
;
...
...
@@ -283,7 +283,7 @@ void getbitCommand(redisClient *c) {
}
/* BITOP op_name target_key src_key1 src_key2 src_key3 ... src_keyN */
void
bitopCommand
(
redisC
lient
*
c
)
{
void
bitopCommand
(
c
lient
*
c
)
{
char
*
opname
=
c
->
argv
[
1
]
->
ptr
;
robj
*
o
,
*
targetkey
=
c
->
argv
[
2
];
unsigned
long
op
,
j
,
numkeys
;
...
...
@@ -457,7 +457,7 @@ void bitopCommand(redisClient *c) {
}
/* BITCOUNT key [start end] */
void
bitcountCommand
(
redisC
lient
*
c
)
{
void
bitcountCommand
(
c
lient
*
c
)
{
robj
*
o
;
long
start
,
end
,
strlen
;
unsigned
char
*
p
;
...
...
@@ -511,7 +511,7 @@ void bitcountCommand(redisClient *c) {
}
/* BITPOS key bit [start [end]] */
void
bitposCommand
(
redisC
lient
*
c
)
{
void
bitposCommand
(
c
lient
*
c
)
{
robj
*
o
;
long
bit
,
start
,
end
,
strlen
;
unsigned
char
*
p
;
...
...
src/blocked.c
View file @
554bd0e7
...
...
@@ -73,7 +73,7 @@
* Note that if the timeout is zero (usually from the point of view of
* commands API this means no timeout) the value stored into 'timeout'
* is zero. */
int
getTimeoutFromObjectOrReply
(
redisC
lient
*
c
,
robj
*
object
,
mstime_t
*
timeout
,
int
unit
)
{
int
getTimeoutFromObjectOrReply
(
c
lient
*
c
,
robj
*
object
,
mstime_t
*
timeout
,
int
unit
)
{
long
long
tval
;
if
(
getLongLongFromObjectOrReply
(
c
,
object
,
&
tval
,
...
...
@@ -97,7 +97,7 @@ int getTimeoutFromObjectOrReply(redisClient *c, robj *object, mstime_t *timeout,
/* Block a client for the specific operation type. Once the REDIS_BLOCKED
* flag is set client query buffer is not longer processed, but accumulated,
* and will be processed when the client is unblocked. */
void
blockClient
(
redisC
lient
*
c
,
int
btype
)
{
void
blockClient
(
c
lient
*
c
,
int
btype
)
{
c
->
flags
|=
REDIS_BLOCKED
;
c
->
btype
=
btype
;
server
.
bpop_blocked_clients
++
;
...
...
@@ -108,7 +108,7 @@ void blockClient(redisClient *c, int btype) {
* unblocked after a blocking operation. */
void
processUnblockedClients
(
void
)
{
listNode
*
ln
;
redisC
lient
*
c
;
c
lient
*
c
;
while
(
listLength
(
server
.
unblocked_clients
))
{
ln
=
listFirst
(
server
.
unblocked_clients
);
...
...
@@ -131,7 +131,7 @@ void processUnblockedClients(void) {
/* Unblock a client calling the right function depending on the kind
* of operation the client is blocking for. */
void
unblockClient
(
redisC
lient
*
c
)
{
void
unblockClient
(
c
lient
*
c
)
{
if
(
c
->
btype
==
REDIS_BLOCKED_LIST
)
{
unblockClientWaitingData
(
c
);
}
else
if
(
c
->
btype
==
REDIS_BLOCKED_WAIT
)
{
...
...
@@ -154,7 +154,7 @@ void unblockClient(redisClient *c) {
/* This function gets called when a blocked client timed out in order to
* send it a reply of some kind. */
void
replyToBlockedClientTimedOut
(
redisC
lient
*
c
)
{
void
replyToBlockedClientTimedOut
(
c
lient
*
c
)
{
if
(
c
->
btype
==
REDIS_BLOCKED_LIST
)
{
addReply
(
c
,
shared
.
nullmultibulk
);
}
else
if
(
c
->
btype
==
REDIS_BLOCKED_WAIT
)
{
...
...
@@ -177,7 +177,7 @@ void disconnectAllBlockedClients(void) {
listRewind
(
server
.
clients
,
&
li
);
while
((
ln
=
listNext
(
&
li
)))
{
redisC
lient
*
c
=
listNodeValue
(
ln
);
c
lient
*
c
=
listNodeValue
(
ln
);
if
(
c
->
flags
&
REDIS_BLOCKED
)
{
addReplySds
(
c
,
sdsnew
(
...
...
src/cluster.c
View file @
554bd0e7
...
...
@@ -3722,7 +3722,7 @@ sds clusterGenNodesDescription(int filter) {
* CLUSTER command
* -------------------------------------------------------------------------- */
int
getSlotOrReply
(
redisC
lient
*
c
,
robj
*
o
)
{
int
getSlotOrReply
(
c
lient
*
c
,
robj
*
o
)
{
long
long
slot
;
if
(
getLongLongFromObject
(
o
,
&
slot
)
!=
REDIS_OK
||
...
...
@@ -3734,7 +3734,7 @@ int getSlotOrReply(redisClient *c, robj *o) {
return
(
int
)
slot
;
}
void
clusterReplyMultiBulkSlots
(
redisC
lient
*
c
)
{
void
clusterReplyMultiBulkSlots
(
c
lient
*
c
)
{
/* Format: 1) 1) start slot
* 2) end slot
* 3) 1) master IP
...
...
@@ -3804,7 +3804,7 @@ void clusterReplyMultiBulkSlots(redisClient *c) {
setDeferredMultiBulkLength
(
c
,
slot_replylen
,
num_masters
);
}
void
clusterCommand
(
redisC
lient
*
c
)
{
void
clusterCommand
(
c
lient
*
c
)
{
if
(
server
.
cluster_enabled
==
0
)
{
addReplyError
(
c
,
"This instance has cluster support disabled"
);
return
;
...
...
@@ -4363,7 +4363,7 @@ int verifyDumpPayload(unsigned char *p, size_t len) {
/* DUMP keyname
* DUMP is actually not used by Redis Cluster but it is the obvious
* complement of RESTORE and can be useful for different applications. */
void
dumpCommand
(
redisC
lient
*
c
)
{
void
dumpCommand
(
c
lient
*
c
)
{
robj
*
o
,
*
dumpobj
;
rio
payload
;
...
...
@@ -4384,7 +4384,7 @@ void dumpCommand(redisClient *c) {
}
/* RESTORE key ttl serialized-value [REPLACE] */
void
restoreCommand
(
redisC
lient
*
c
)
{
void
restoreCommand
(
c
lient
*
c
)
{
long
long
ttl
;
rio
payload
;
int
j
,
type
,
replace
=
0
;
...
...
@@ -4466,7 +4466,7 @@ typedef struct migrateCachedSocket {
* If the caller detects an error while using the socket, migrateCloseSocket()
* should be called so that the connection will be created from scratch
* the next time. */
migrateCachedSocket
*
migrateGetSocket
(
redisC
lient
*
c
,
robj
*
host
,
robj
*
port
,
long
timeout
)
{
migrateCachedSocket
*
migrateGetSocket
(
c
lient
*
c
,
robj
*
host
,
robj
*
port
,
long
timeout
)
{
int
fd
;
sds
name
=
sdsempty
();
migrateCachedSocket
*
cs
;
...
...
@@ -4558,7 +4558,7 @@ void migrateCloseTimedoutSockets(void) {
}
/* MIGRATE host port key dbid timeout [COPY | REPLACE] */
void
migrateCommand
(
redisC
lient
*
c
)
{
void
migrateCommand
(
c
lient
*
c
)
{
migrateCachedSocket
*
cs
;
int
copy
,
replace
,
j
;
long
timeout
;
...
...
@@ -4723,7 +4723,7 @@ socket_rd_err:
* The client should issue ASKING before to actually send the command to
* the target instance. See the Redis Cluster specification for more
* information. */
void
askingCommand
(
redisC
lient
*
c
)
{
void
askingCommand
(
c
lient
*
c
)
{
if
(
server
.
cluster_enabled
==
0
)
{
addReplyError
(
c
,
"This instance has cluster support disabled"
);
return
;
...
...
@@ -4735,7 +4735,7 @@ void askingCommand(redisClient *c) {
/* The READONLY command is used by clients to enter the read-only mode.
* In this mode slaves will not redirect clients as long as clients access
* with read-only commands to keys that are served by the slave's master. */
void
readonlyCommand
(
redisC
lient
*
c
)
{
void
readonlyCommand
(
c
lient
*
c
)
{
if
(
server
.
cluster_enabled
==
0
)
{
addReplyError
(
c
,
"This instance has cluster support disabled"
);
return
;
...
...
@@ -4745,7 +4745,7 @@ void readonlyCommand(redisClient *c) {
}
/* The READWRITE command just clears the READONLY command state. */
void
readwriteCommand
(
redisC
lient
*
c
)
{
void
readwriteCommand
(
c
lient
*
c
)
{
c
->
flags
&=
~
REDIS_READONLY
;
addReply
(
c
,
shared
.
ok
);
}
...
...
@@ -4779,7 +4779,7 @@ void readwriteCommand(redisClient *c) {
* not bound to any node. In this case the cluster global state should be
* already "down" but it is fragile to rely on the update of the global state,
* so we also handle it here. */
clusterNode
*
getNodeByQuery
(
redisC
lient
*
c
,
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
hashslot
,
int
*
error_code
)
{
clusterNode
*
getNodeByQuery
(
c
lient
*
c
,
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
hashslot
,
int
*
error_code
)
{
clusterNode
*
n
=
NULL
;
robj
*
firstkey
=
NULL
;
int
multiple_keys
=
0
;
...
...
@@ -4940,7 +4940,7 @@ clusterNode *getNodeByQuery(redisClient *c, struct redisCommand *cmd, robj **arg
* are used, then the node 'n' should not be NULL, but should be the
* node we want to mention in the redirection. Moreover hashslot should
* be set to the hash slot that caused the redirection. */
void
clusterRedirectClient
(
redisC
lient
*
c
,
clusterNode
*
n
,
int
hashslot
,
int
error_code
)
{
void
clusterRedirectClient
(
c
lient
*
c
,
clusterNode
*
n
,
int
hashslot
,
int
error_code
)
{
if
(
error_code
==
REDIS_CLUSTER_REDIR_CROSS_SLOT
)
{
addReplySds
(
c
,
sdsnew
(
"-CROSSSLOT Keys in request don't hash to the same slot
\r\n
"
));
}
else
if
(
error_code
==
REDIS_CLUSTER_REDIR_UNSTABLE
)
{
...
...
@@ -4975,7 +4975,7 @@ void clusterRedirectClient(redisClient *c, clusterNode *n, int hashslot, int err
* If the client is found to be blocked into an hash slot this node no
* longer handles, the client is sent a redirection error, and the function
* returns 1. Otherwise 0 is returned and no operation is performed. */
int
clusterRedirectBlockedClientIfNeeded
(
redisC
lient
*
c
)
{
int
clusterRedirectBlockedClientIfNeeded
(
c
lient
*
c
)
{
if
(
c
->
flags
&
REDIS_BLOCKED
&&
c
->
btype
==
REDIS_BLOCKED_LIST
)
{
dictEntry
*
de
;
dictIterator
*
di
;
...
...
src/cluster.h
View file @
554bd0e7
...
...
@@ -249,8 +249,8 @@ typedef struct {
master is up. */
/* ---------------------- API exported outside cluster.c -------------------- */
clusterNode
*
getNodeByQuery
(
redisC
lient
*
c
,
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
hashslot
,
int
*
ask
);
int
clusterRedirectBlockedClientIfNeeded
(
redisC
lient
*
c
);
void
clusterRedirectClient
(
redisC
lient
*
c
,
clusterNode
*
n
,
int
hashslot
,
int
error_code
);
clusterNode
*
getNodeByQuery
(
c
lient
*
c
,
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
hashslot
,
int
*
ask
);
int
clusterRedirectBlockedClientIfNeeded
(
c
lient
*
c
);
void
clusterRedirectClient
(
c
lient
*
c
,
clusterNode
*
n
,
int
hashslot
,
int
error_code
);
#endif
/* __REDIS_CLUSTER_H */
src/config.c
View file @
554bd0e7
...
...
@@ -699,7 +699,7 @@ void loadServerConfig(char *filename, char *options) {
#define config_set_else } else
void
configSetCommand
(
redisC
lient
*
c
)
{
void
configSetCommand
(
c
lient
*
c
)
{
robj
*
o
;
long
long
ll
;
int
err
;
...
...
@@ -1024,7 +1024,7 @@ badfmt: /* Bad format errors */
} \
} while(0);
void
configGetCommand
(
redisC
lient
*
c
)
{
void
configGetCommand
(
c
lient
*
c
)
{
robj
*
o
=
c
->
argv
[
2
];
void
*
replylen
=
addDeferredMultiBulkLength
(
c
);
char
*
pattern
=
o
->
ptr
;
...
...
@@ -1843,7 +1843,7 @@ int rewriteConfig(char *path) {
* CONFIG command entry point
*----------------------------------------------------------------------------*/
void
configCommand
(
redisC
lient
*
c
)
{
void
configCommand
(
c
lient
*
c
)
{
if
(
!
strcasecmp
(
c
->
argv
[
1
]
->
ptr
,
"set"
))
{
if
(
c
->
argc
!=
4
)
goto
badarity
;
configSetCommand
(
c
);
...
...
src/db.c
View file @
554bd0e7
...
...
@@ -99,13 +99,13 @@ robj *lookupKeyWrite(redisDb *db, robj *key) {
return
lookupKey
(
db
,
key
);
}
robj
*
lookupKeyReadOrReply
(
redisC
lient
*
c
,
robj
*
key
,
robj
*
reply
)
{
robj
*
lookupKeyReadOrReply
(
c
lient
*
c
,
robj
*
key
,
robj
*
reply
)
{
robj
*
o
=
lookupKeyRead
(
c
->
db
,
key
);
if
(
!
o
)
addReply
(
c
,
reply
);
return
o
;
}
robj
*
lookupKeyWriteOrReply
(
redisC
lient
*
c
,
robj
*
key
,
robj
*
reply
)
{
robj
*
lookupKeyWriteOrReply
(
c
lient
*
c
,
robj
*
key
,
robj
*
reply
)
{
robj
*
o
=
lookupKeyWrite
(
c
->
db
,
key
);
if
(
!
o
)
addReply
(
c
,
reply
);
return
o
;
...
...
@@ -247,7 +247,7 @@ long long emptyDb(void(callback)(void*)) {
return
removed
;
}
int
selectDb
(
redisC
lient
*
c
,
int
id
)
{
int
selectDb
(
c
lient
*
c
,
int
id
)
{
if
(
id
<
0
||
id
>=
server
.
dbnum
)
return
REDIS_ERR
;
c
->
db
=
&
server
.
db
[
id
];
...
...
@@ -275,7 +275,7 @@ void signalFlushedDb(int dbid) {
* Type agnostic commands operating on the key space
*----------------------------------------------------------------------------*/
void
flushdbCommand
(
redisC
lient
*
c
)
{
void
flushdbCommand
(
c
lient
*
c
)
{
server
.
dirty
+=
dictSize
(
c
->
db
->
dict
);
signalFlushedDb
(
c
->
db
->
id
);
dictEmpty
(
c
->
db
->
dict
,
NULL
);
...
...
@@ -284,7 +284,7 @@ void flushdbCommand(redisClient *c) {
addReply
(
c
,
shared
.
ok
);
}
void
flushallCommand
(
redisC
lient
*
c
)
{
void
flushallCommand
(
c
lient
*
c
)
{
signalFlushedDb
(
-
1
);
server
.
dirty
+=
emptyDb
(
NULL
);
addReply
(
c
,
shared
.
ok
);
...
...
@@ -302,7 +302,7 @@ void flushallCommand(redisClient *c) {
server
.
dirty
++
;
}
void
delCommand
(
redisC
lient
*
c
)
{
void
delCommand
(
c
lient
*
c
)
{
int
deleted
=
0
,
j
;
for
(
j
=
1
;
j
<
c
->
argc
;
j
++
)
{
...
...
@@ -320,7 +320,7 @@ void delCommand(redisClient *c) {
/* EXISTS key1 key2 ... key_N.
* Return value is the number of keys existing. */
void
existsCommand
(
redisC
lient
*
c
)
{
void
existsCommand
(
c
lient
*
c
)
{
long
long
count
=
0
;
int
j
;
...
...
@@ -331,7 +331,7 @@ void existsCommand(redisClient *c) {
addReplyLongLong
(
c
,
count
);
}
void
selectCommand
(
redisC
lient
*
c
)
{
void
selectCommand
(
c
lient
*
c
)
{
long
id
;
if
(
getLongFromObjectOrReply
(
c
,
c
->
argv
[
1
],
&
id
,
...
...
@@ -349,7 +349,7 @@ void selectCommand(redisClient *c) {
}
}
void
randomkeyCommand
(
redisC
lient
*
c
)
{
void
randomkeyCommand
(
c
lient
*
c
)
{
robj
*
key
;
if
((
key
=
dbRandomKey
(
c
->
db
))
==
NULL
)
{
...
...
@@ -361,7 +361,7 @@ void randomkeyCommand(redisClient *c) {
decrRefCount
(
key
);
}
void
keysCommand
(
redisC
lient
*
c
)
{
void
keysCommand
(
c
lient
*
c
)
{
dictIterator
*
di
;
dictEntry
*
de
;
sds
pattern
=
c
->
argv
[
1
]
->
ptr
;
...
...
@@ -423,7 +423,7 @@ void scanCallback(void *privdata, const dictEntry *de) {
* if the cursor is valid, store it as unsigned integer into *cursor and
* returns REDIS_OK. Otherwise return REDIS_ERR and send an error to the
* client. */
int
parseScanCursorOrReply
(
redisC
lient
*
c
,
robj
*
o
,
unsigned
long
*
cursor
)
{
int
parseScanCursorOrReply
(
c
lient
*
c
,
robj
*
o
,
unsigned
long
*
cursor
)
{
char
*
eptr
;
/* Use strtoul() because we need an *unsigned* long, so
...
...
@@ -449,7 +449,7 @@ int parseScanCursorOrReply(redisClient *c, robj *o, unsigned long *cursor) {
*
* In the case of a Hash object the function returns both the field and value
* of every element on the Hash. */
void
scanGenericCommand
(
redisC
lient
*
c
,
robj
*
o
,
unsigned
long
cursor
)
{
void
scanGenericCommand
(
c
lient
*
c
,
robj
*
o
,
unsigned
long
cursor
)
{
int
i
,
j
;
list
*
keys
=
listCreate
();
listNode
*
node
,
*
nextnode
;
...
...
@@ -627,21 +627,21 @@ cleanup:
}
/* The SCAN command completely relies on scanGenericCommand. */
void
scanCommand
(
redisC
lient
*
c
)
{
void
scanCommand
(
c
lient
*
c
)
{
unsigned
long
cursor
;
if
(
parseScanCursorOrReply
(
c
,
c
->
argv
[
1
],
&
cursor
)
==
REDIS_ERR
)
return
;
scanGenericCommand
(
c
,
NULL
,
cursor
);
}
void
dbsizeCommand
(
redisC
lient
*
c
)
{
void
dbsizeCommand
(
c
lient
*
c
)
{
addReplyLongLong
(
c
,
dictSize
(
c
->
db
->
dict
));
}
void
lastsaveCommand
(
redisC
lient
*
c
)
{
void
lastsaveCommand
(
c
lient
*
c
)
{
addReplyLongLong
(
c
,
server
.
lastsave
);
}
void
typeCommand
(
redisC
lient
*
c
)
{
void
typeCommand
(
c
lient
*
c
)
{
robj
*
o
;
char
*
type
;
...
...
@@ -661,7 +661,7 @@ void typeCommand(redisClient *c) {
addReplyStatus
(
c
,
type
);
}
void
shutdownCommand
(
redisC
lient
*
c
)
{
void
shutdownCommand
(
c
lient
*
c
)
{
int
flags
=
0
;
if
(
c
->
argc
>
2
)
{
...
...
@@ -689,7 +689,7 @@ void shutdownCommand(redisClient *c) {
addReplyError
(
c
,
"Errors trying to SHUTDOWN. Check logs."
);
}
void
renameGenericCommand
(
redisC
lient
*
c
,
int
nx
)
{
void
renameGenericCommand
(
c
lient
*
c
,
int
nx
)
{
robj
*
o
;
long
long
expire
;
int
samekey
=
0
;
...
...
@@ -731,15 +731,15 @@ void renameGenericCommand(redisClient *c, int nx) {
addReply
(
c
,
nx
?
shared
.
cone
:
shared
.
ok
);
}
void
renameCommand
(
redisC
lient
*
c
)
{
void
renameCommand
(
c
lient
*
c
)
{
renameGenericCommand
(
c
,
0
);
}
void
renamenxCommand
(
redisC
lient
*
c
)
{
void
renamenxCommand
(
c
lient
*
c
)
{
renameGenericCommand
(
c
,
1
);
}
void
moveCommand
(
redisC
lient
*
c
)
{
void
moveCommand
(
c
lient
*
c
)
{
robj
*
o
;
redisDb
*
src
,
*
dst
;
int
srcid
;
...
...
@@ -899,7 +899,7 @@ int expireIfNeeded(redisDb *db, robj *key) {
*
* unit is either UNIT_SECONDS or UNIT_MILLISECONDS, and is only used for
* the argv[2] parameter. The basetime is always specified in milliseconds. */
void
expireGenericCommand
(
redisC
lient
*
c
,
long
long
basetime
,
int
unit
)
{
void
expireGenericCommand
(
c
lient
*
c
,
long
long
basetime
,
int
unit
)
{
robj
*
key
=
c
->
argv
[
1
],
*
param
=
c
->
argv
[
2
];
long
long
when
;
/* unix time in milliseconds when the key will expire. */
...
...
@@ -945,23 +945,23 @@ void expireGenericCommand(redisClient *c, long long basetime, int unit) {
}
}
void
expireCommand
(
redisC
lient
*
c
)
{
void
expireCommand
(
c
lient
*
c
)
{
expireGenericCommand
(
c
,
mstime
(),
UNIT_SECONDS
);
}
void
expireatCommand
(
redisC
lient
*
c
)
{
void
expireatCommand
(
c
lient
*
c
)
{
expireGenericCommand
(
c
,
0
,
UNIT_SECONDS
);
}
void
pexpireCommand
(
redisC
lient
*
c
)
{
void
pexpireCommand
(
c
lient
*
c
)
{
expireGenericCommand
(
c
,
mstime
(),
UNIT_MILLISECONDS
);
}
void
pexpireatCommand
(
redisC
lient
*
c
)
{
void
pexpireatCommand
(
c
lient
*
c
)
{
expireGenericCommand
(
c
,
0
,
UNIT_MILLISECONDS
);
}
void
ttlGenericCommand
(
redisC
lient
*
c
,
int
output_ms
)
{
void
ttlGenericCommand
(
c
lient
*
c
,
int
output_ms
)
{
long
long
expire
,
ttl
=
-
1
;
/* If the key does not exist at all, return -2 */
...
...
@@ -983,15 +983,15 @@ void ttlGenericCommand(redisClient *c, int output_ms) {
}
}
void
ttlCommand
(
redisC
lient
*
c
)
{
void
ttlCommand
(
c
lient
*
c
)
{
ttlGenericCommand
(
c
,
0
);
}
void
pttlCommand
(
redisC
lient
*
c
)
{
void
pttlCommand
(
c
lient
*
c
)
{
ttlGenericCommand
(
c
,
1
);
}
void
persistCommand
(
redisC
lient
*
c
)
{
void
persistCommand
(
c
lient
*
c
)
{
dictEntry
*
de
;
de
=
dictFind
(
c
->
db
->
dict
,
c
->
argv
[
1
]
->
ptr
);
...
...
src/debug.c
View file @
554bd0e7
...
...
@@ -258,7 +258,7 @@ void inputCatSds(void *result, const char *str) {
*
info
=
sdscat
(
*
info
,
str
);
}
void
debugCommand
(
redisC
lient
*
c
)
{
void
debugCommand
(
c
lient
*
c
)
{
if
(
!
strcasecmp
(
c
->
argv
[
1
]
->
ptr
,
"segfault"
))
{
*
((
char
*
)
-
1
)
=
'x'
;
}
else
if
(
!
strcasecmp
(
c
->
argv
[
1
]
->
ptr
,
"oom"
))
{
...
...
@@ -483,7 +483,7 @@ void _redisAssert(char *estr, char *file, int line) {
*
((
char
*
)
-
1
)
=
'x'
;
}
void
_redisAssertPrintClientInfo
(
redisC
lient
*
c
)
{
void
_redisAssertPrintClientInfo
(
c
lient
*
c
)
{
int
j
;
bugReportStart
();
...
...
@@ -537,7 +537,7 @@ void _redisAssertPrintObject(robj *o) {
serverLogObjectDebugInfo
(
o
);
}
void
_redisAssertWithInfo
(
redisC
lient
*
c
,
robj
*
o
,
char
*
estr
,
char
*
file
,
int
line
)
{
void
_redisAssertWithInfo
(
c
lient
*
c
,
robj
*
o
,
char
*
estr
,
char
*
file
,
int
line
)
{
if
(
c
)
_redisAssertPrintClientInfo
(
c
);
if
(
o
)
_redisAssertPrintObject
(
o
);
_redisAssert
(
estr
,
file
,
line
);
...
...
@@ -770,7 +770,7 @@ void logStackTrace(ucontext_t *uc) {
void
logCurrentClient
(
void
)
{
if
(
server
.
current_client
==
NULL
)
return
;
redisC
lient
*
cc
=
server
.
current_client
;
c
lient
*
cc
=
server
.
current_client
;
sds
client
;
int
j
;
...
...
src/geo.c
View file @
554bd0e7
...
...
@@ -89,7 +89,7 @@ int decodeGeohash(double bits, double *xy) {
/* Input Argument Helper */
/* Take a pointer to the latitude arg then use the next arg for longitude.
* On parse error REDIS_ERR is returned, otherwise REDIS_OK. */
int
extractLongLatOrReply
(
redisC
lient
*
c
,
robj
**
argv
,
int
extractLongLatOrReply
(
c
lient
*
c
,
robj
**
argv
,
double
*
xy
)
{
for
(
int
i
=
0
;
i
<
2
;
i
++
)
{
if
(
getDoubleFromObjectOrReply
(
c
,
argv
[
i
],
xy
+
i
,
NULL
)
!=
...
...
@@ -123,7 +123,7 @@ int longLatFromMember(robj *zobj, robj *member, double *xy) {
*
* If the unit is not valid, an error is reported to the client, and a value
* less than zero is returned. */
double
extractUnitOrReply
(
redisC
lient
*
c
,
robj
*
unit
)
{
double
extractUnitOrReply
(
c
lient
*
c
,
robj
*
unit
)
{
char
*
u
=
unit
->
ptr
;
if
(
!
strcmp
(
u
,
"m"
))
{
...
...
@@ -148,7 +148,7 @@ double extractUnitOrReply(redisClient *c, robj *unit) {
* to use in order to convert meters to the unit.
*
* On error a value less than zero is returned. */
double
extractDistanceOrReply
(
redisC
lient
*
c
,
robj
**
argv
,
double
extractDistanceOrReply
(
c
lient
*
c
,
robj
**
argv
,
double
*
conversion
)
{
double
distance
;
if
(
getDoubleFromObjectOrReply
(
c
,
argv
[
0
],
&
distance
,
...
...
@@ -168,7 +168,7 @@ double extractDistanceOrReply(redisClient *c, robj **argv,
* than "5.2144992818115 meters away." We provide 4 digits after the dot
* so that the returned value is decently accurate even when the unit is
* the kilometer. */
void
addReplyDoubleDistance
(
redisC
lient
*
c
,
double
d
)
{
void
addReplyDoubleDistance
(
c
lient
*
c
,
double
d
)
{
char
dbuf
[
128
];
int
dlen
=
snprintf
(
dbuf
,
sizeof
(
dbuf
),
"%.4f"
,
d
);
addReplyBulkCBuffer
(
c
,
dbuf
,
dlen
);
...
...
@@ -363,7 +363,7 @@ static int sort_gp_desc(const void *a, const void *b) {
* ==================================================================== */
/* GEOADD key long lat name [long2 lat2 name2 ... longN latN nameN] */
void
geoaddCommand
(
redisC
lient
*
c
)
{
void
geoaddCommand
(
c
lient
*
c
)
{
/* Check arguments number for sanity. */
if
((
c
->
argc
-
2
)
%
3
!=
0
)
{
/* Need an odd number of arguments if we got this far... */
...
...
@@ -419,7 +419,7 @@ void geoaddCommand(redisClient *c) {
/* GEORADIUS key x y radius unit [WITHDIST] [WITHHASH] [WITHCOORD] [ASC|DESC]
* [COUNT count]
* GEORADIUSBYMEMBER key member radius unit ... options ... */
void
georadiusGeneric
(
redisC
lient
*
c
,
int
type
)
{
void
georadiusGeneric
(
c
lient
*
c
,
int
type
)
{
robj
*
key
=
c
->
argv
[
1
];
/* Look up the requested zset */
...
...
@@ -569,12 +569,12 @@ void georadiusGeneric(redisClient *c, int type) {
}
/* GEORADIUS wrapper function. */
void
georadiusCommand
(
redisC
lient
*
c
)
{
void
georadiusCommand
(
c
lient
*
c
)
{
georadiusGeneric
(
c
,
RADIUS_COORDS
);
}
/* GEORADIUSBYMEMBER wrapper function. */
void
georadiusByMemberCommand
(
redisC
lient
*
c
)
{
void
georadiusByMemberCommand
(
c
lient
*
c
)
{
georadiusGeneric
(
c
,
RADIUS_MEMBER
);
}
...
...
@@ -582,7 +582,7 @@ void georadiusByMemberCommand(redisClient *c) {
*
* Returns an array with an 11 characters geohash representation of the
* position of the specified elements. */
void
geohashCommand
(
redisC
lient
*
c
)
{
void
geohashCommand
(
c
lient
*
c
)
{
char
*
geoalphabet
=
"0123456789bcdefghjkmnpqrstuvwxyz"
;
int
j
;
...
...
@@ -637,7 +637,7 @@ void geohashCommand(redisClient *c) {
*
* Returns an array of two-items arrays representing the x,y position of each
* element specified in the arguments. For missing elements NULL is returned. */
void
geoposCommand
(
redisC
lient
*
c
)
{
void
geoposCommand
(
c
lient
*
c
)
{
int
j
;
/* Look up the requested zset */
...
...
@@ -671,7 +671,7 @@ void geoposCommand(redisClient *c) {
* Return the distance, in meters by default, otherwise accordig to "unit",
* between points ele1 and ele2. If one or more elements are missing NULL
* is returned. */
void
geodistCommand
(
redisC
lient
*
c
)
{
void
geodistCommand
(
c
lient
*
c
)
{
double
to_meter
=
1
;
/* Check if there is the unit to extract, otherwise assume meters. */
...
...
src/hyperloglog.c
View file @
554bd0e7
...
...
@@ -1121,7 +1121,7 @@ robj *createHLLObject(void) {
/* Check if the object is a String with a valid HLL representation.
* Return REDIS_OK if this is true, otherwise reply to the client
* with an error and return REDIS_ERR. */
int
isHLLObjectOrReply
(
redisC
lient
*
c
,
robj
*
o
)
{
int
isHLLObjectOrReply
(
c
lient
*
c
,
robj
*
o
)
{
struct
hllhdr
*
hdr
;
/* Key exists, check type */
...
...
@@ -1152,7 +1152,7 @@ invalid:
}
/* PFADD var ele ele ele ... ele => :0 or :1 */
void
pfaddCommand
(
redisC
lient
*
c
)
{
void
pfaddCommand
(
c
lient
*
c
)
{
robj
*
o
=
lookupKeyWrite
(
c
->
db
,
c
->
argv
[
1
]);
struct
hllhdr
*
hdr
;
int
updated
=
0
,
j
;
...
...
@@ -1192,7 +1192,7 @@ void pfaddCommand(redisClient *c) {
}
/* PFCOUNT var -> approximated cardinality of set. */
void
pfcountCommand
(
redisC
lient
*
c
)
{
void
pfcountCommand
(
c
lient
*
c
)
{
robj
*
o
;
struct
hllhdr
*
hdr
;
uint64_t
card
;
...
...
@@ -1282,7 +1282,7 @@ void pfcountCommand(redisClient *c) {
}
/* PFMERGE dest src1 src2 src3 ... srcN => OK */
void
pfmergeCommand
(
redisC
lient
*
c
)
{
void
pfmergeCommand
(
c
lient
*
c
)
{
uint8_t
max
[
HLL_REGISTERS
];
struct
hllhdr
*
hdr
;
int
j
;
...
...
@@ -1348,7 +1348,7 @@ void pfmergeCommand(redisClient *c) {
* This command performs a self-test of the HLL registers implementation.
* Something that is not easy to test from within the outside. */
#define HLL_TEST_CYCLES 1000
void
pfselftestCommand
(
redisC
lient
*
c
)
{
void
pfselftestCommand
(
c
lient
*
c
)
{
unsigned
int
j
,
i
;
sds
bitcounters
=
sdsnewlen
(
NULL
,
HLL_DENSE_SIZE
);
struct
hllhdr
*
hdr
=
(
struct
hllhdr
*
)
bitcounters
,
*
hdr2
;
...
...
@@ -1452,7 +1452,7 @@ cleanup:
/* PFDEBUG <subcommand> <key> ... args ...
* Different debugging related operations about the HLL implementation. */
void
pfdebugCommand
(
redisC
lient
*
c
)
{
void
pfdebugCommand
(
c
lient
*
c
)
{
char
*
cmd
=
c
->
argv
[
1
]
->
ptr
;
struct
hllhdr
*
hdr
;
robj
*
o
;
...
...
src/latency.c
View file @
554bd0e7
...
...
@@ -474,7 +474,7 @@ sds createLatencyReport(void) {
/* latencyCommand() helper to produce a time-delay reply for all the samples
* in memory for the specified time series. */
void
latencyCommandReplyWithSamples
(
redisC
lient
*
c
,
struct
latencyTimeSeries
*
ts
)
{
void
latencyCommandReplyWithSamples
(
c
lient
*
c
,
struct
latencyTimeSeries
*
ts
)
{
void
*
replylen
=
addDeferredMultiBulkLength
(
c
);
int
samples
=
0
,
j
;
...
...
@@ -492,7 +492,7 @@ void latencyCommandReplyWithSamples(redisClient *c, struct latencyTimeSeries *ts
/* latencyCommand() helper to produce the reply for the LATEST subcommand,
* listing the last latency sample for every event type registered so far. */
void
latencyCommandReplyWithLatestEvents
(
redisC
lient
*
c
)
{
void
latencyCommandReplyWithLatestEvents
(
c
lient
*
c
)
{
dictIterator
*
di
;
dictEntry
*
de
;
...
...
@@ -564,7 +564,7 @@ sds latencyCommandGenSparkeline(char *event, struct latencyTimeSeries *ts) {
* LATENCY DOCTOR: returns an human readable analysis of instance latency.
* LATENCY GRAPH: provide an ASCII graph of the latency of the specified event.
*/
void
latencyCommand
(
redisC
lient
*
c
)
{
void
latencyCommand
(
c
lient
*
c
)
{
struct
latencyTimeSeries
*
ts
;
if
(
!
strcasecmp
(
c
->
argv
[
1
]
->
ptr
,
"history"
)
&&
c
->
argc
==
3
)
{
...
...
src/multi.c
View file @
554bd0e7
...
...
@@ -32,13 +32,13 @@
/* ================================ MULTI/EXEC ============================== */
/* Client state initialization for MULTI/EXEC */
void
initClientMultiState
(
redisC
lient
*
c
)
{
void
initClientMultiState
(
c
lient
*
c
)
{
c
->
mstate
.
commands
=
NULL
;
c
->
mstate
.
count
=
0
;
}
/* Release all the resources associated with MULTI/EXEC state */
void
freeClientMultiState
(
redisC
lient
*
c
)
{
void
freeClientMultiState
(
c
lient
*
c
)
{
int
j
;
for
(
j
=
0
;
j
<
c
->
mstate
.
count
;
j
++
)
{
...
...
@@ -53,7 +53,7 @@ void freeClientMultiState(redisClient *c) {
}
/* Add a new command into the MULTI commands queue */
void
queueMultiCommand
(
redisC
lient
*
c
)
{
void
queueMultiCommand
(
c
lient
*
c
)
{
multiCmd
*
mc
;
int
j
;
...
...
@@ -69,7 +69,7 @@ void queueMultiCommand(redisClient *c) {
c
->
mstate
.
count
++
;
}
void
discardTransaction
(
redisC
lient
*
c
)
{
void
discardTransaction
(
c
lient
*
c
)
{
freeClientMultiState
(
c
);
initClientMultiState
(
c
);
c
->
flags
&=
~
(
REDIS_MULTI
|
REDIS_DIRTY_CAS
|
REDIS_DIRTY_EXEC
);
...
...
@@ -78,12 +78,12 @@ void discardTransaction(redisClient *c) {
/* Flag the transacation as DIRTY_EXEC so that EXEC will fail.
* Should be called every time there is an error while queueing a command. */
void
flagTransaction
(
redisC
lient
*
c
)
{
void
flagTransaction
(
c
lient
*
c
)
{
if
(
c
->
flags
&
REDIS_MULTI
)
c
->
flags
|=
REDIS_DIRTY_EXEC
;
}
void
multiCommand
(
redisC
lient
*
c
)
{
void
multiCommand
(
c
lient
*
c
)
{
if
(
c
->
flags
&
REDIS_MULTI
)
{
addReplyError
(
c
,
"MULTI calls can not be nested"
);
return
;
...
...
@@ -92,7 +92,7 @@ void multiCommand(redisClient *c) {
addReply
(
c
,
shared
.
ok
);
}
void
discardCommand
(
redisC
lient
*
c
)
{
void
discardCommand
(
c
lient
*
c
)
{
if
(
!
(
c
->
flags
&
REDIS_MULTI
))
{
addReplyError
(
c
,
"DISCARD without MULTI"
);
return
;
...
...
@@ -103,7 +103,7 @@ void discardCommand(redisClient *c) {
/* Send a MULTI command to all the slaves and AOF file. Check the execCommand
* implementation for more information. */
void
execCommandPropagateMulti
(
redisC
lient
*
c
)
{
void
execCommandPropagateMulti
(
c
lient
*
c
)
{
robj
*
multistring
=
createStringObject
(
"MULTI"
,
5
);
propagate
(
server
.
multiCommand
,
c
->
db
->
id
,
&
multistring
,
1
,
...
...
@@ -111,7 +111,7 @@ void execCommandPropagateMulti(redisClient *c) {
decrRefCount
(
multistring
);
}
void
execCommand
(
redisC
lient
*
c
)
{
void
execCommand
(
c
lient
*
c
)
{
int
j
;
robj
**
orig_argv
;
int
orig_argc
;
...
...
@@ -199,7 +199,7 @@ typedef struct watchedKey {
}
watchedKey
;
/* Watch for the specified key */
void
watchForKey
(
redisC
lient
*
c
,
robj
*
key
)
{
void
watchForKey
(
c
lient
*
c
,
robj
*
key
)
{
list
*
clients
=
NULL
;
listIter
li
;
listNode
*
ln
;
...
...
@@ -230,7 +230,7 @@ void watchForKey(redisClient *c, robj *key) {
/* Unwatch all the keys watched by this client. To clean the EXEC dirty
* flag is up to the caller. */
void
unwatchAllKeys
(
redisC
lient
*
c
)
{
void
unwatchAllKeys
(
c
lient
*
c
)
{
listIter
li
;
listNode
*
ln
;
...
...
@@ -271,7 +271,7 @@ void touchWatchedKey(redisDb *db, robj *key) {
/* Check if we are already watching for this key */
listRewind
(
clients
,
&
li
);
while
((
ln
=
listNext
(
&
li
)))
{
redisC
lient
*
c
=
listNodeValue
(
ln
);
c
lient
*
c
=
listNodeValue
(
ln
);
c
->
flags
|=
REDIS_DIRTY_CAS
;
}
...
...
@@ -288,7 +288,7 @@ void touchWatchedKeysOnFlush(int dbid) {
/* For every client, check all the waited keys */
listRewind
(
server
.
clients
,
&
li1
);
while
((
ln
=
listNext
(
&
li1
)))
{
redisC
lient
*
c
=
listNodeValue
(
ln
);
c
lient
*
c
=
listNodeValue
(
ln
);
listRewind
(
c
->
watched_keys
,
&
li2
);
while
((
ln
=
listNext
(
&
li2
)))
{
watchedKey
*
wk
=
listNodeValue
(
ln
);
...
...
@@ -304,7 +304,7 @@ void touchWatchedKeysOnFlush(int dbid) {
}
}
void
watchCommand
(
redisC
lient
*
c
)
{
void
watchCommand
(
c
lient
*
c
)
{
int
j
;
if
(
c
->
flags
&
REDIS_MULTI
)
{
...
...
@@ -316,7 +316,7 @@ void watchCommand(redisClient *c) {
addReply
(
c
,
shared
.
ok
);
}
void
unwatchCommand
(
redisC
lient
*
c
)
{
void
unwatchCommand
(
c
lient
*
c
)
{
unwatchAllKeys
(
c
);
c
->
flags
&=
(
~
REDIS_DIRTY_CAS
);
addReply
(
c
,
shared
.
ok
);
...
...
src/networking.c
View file @
554bd0e7
...
...
@@ -31,7 +31,7 @@
#include <sys/uio.h>
#include <math.h>
static
void
setProtocolError
(
redisC
lient
*
c
,
int
pos
);
static
void
setProtocolError
(
c
lient
*
c
,
int
pos
);
/* Return the size consumed from the allocator, for the specified SDS string,
* including internal fragmentation. This function is used in order to compute
...
...
@@ -61,8 +61,8 @@ int listMatchObjects(void *a, void *b) {
return
equalStringObjects
(
a
,
b
);
}
redisC
lient
*
createClient
(
int
fd
)
{
redisC
lient
*
c
=
zmalloc
(
sizeof
(
redisC
lient
));
c
lient
*
createClient
(
int
fd
)
{
c
lient
*
c
=
zmalloc
(
sizeof
(
c
lient
));
/* passing -1 as fd it is possible to create a non connected client.
* This is useful since all the Redis commands needs to be executed
...
...
@@ -150,7 +150,7 @@ redisClient *createClient(int fd) {
* Typically gets called every time a reply is built, before adding more
* data to the clients output buffers. If the function returns REDIS_ERR no
* data should be appended to the output buffers. */
int
prepareClientToWrite
(
redisC
lient
*
c
)
{
int
prepareClientToWrite
(
c
lient
*
c
)
{
/* If it's the Lua client we always return ok without installing any
* handler since there is no socket at all. */
if
(
c
->
flags
&
REDIS_LUA_CLIENT
)
return
REDIS_OK
;
...
...
@@ -201,7 +201,7 @@ robj *dupLastObjectIfNeeded(list *reply) {
* Low level functions to add more data to output buffers.
* -------------------------------------------------------------------------- */
int
_addReplyToBuffer
(
redisC
lient
*
c
,
const
char
*
s
,
size_t
len
)
{
int
_addReplyToBuffer
(
c
lient
*
c
,
const
char
*
s
,
size_t
len
)
{
size_t
available
=
sizeof
(
c
->
buf
)
-
c
->
bufpos
;
if
(
c
->
flags
&
REDIS_CLOSE_AFTER_REPLY
)
return
REDIS_OK
;
...
...
@@ -218,7 +218,7 @@ int _addReplyToBuffer(redisClient *c, const char *s, size_t len) {
return
REDIS_OK
;
}
void
_addReplyObjectToList
(
redisC
lient
*
c
,
robj
*
o
)
{
void
_addReplyObjectToList
(
c
lient
*
c
,
robj
*
o
)
{
robj
*
tail
;
if
(
c
->
flags
&
REDIS_CLOSE_AFTER_REPLY
)
return
;
...
...
@@ -250,7 +250,7 @@ void _addReplyObjectToList(redisClient *c, robj *o) {
/* This method takes responsibility over the sds. When it is no longer
* needed it will be free'd, otherwise it ends up in a robj. */
void
_addReplySdsToList
(
redisC
lient
*
c
,
sds
s
)
{
void
_addReplySdsToList
(
c
lient
*
c
,
sds
s
)
{
robj
*
tail
;
if
(
c
->
flags
&
REDIS_CLOSE_AFTER_REPLY
)
{
...
...
@@ -281,7 +281,7 @@ void _addReplySdsToList(redisClient *c, sds s) {
asyncCloseClientOnOutputBufferLimitReached
(
c
);
}
void
_addReplyStringToList
(
redisC
lient
*
c
,
const
char
*
s
,
size_t
len
)
{
void
_addReplyStringToList
(
c
lient
*
c
,
const
char
*
s
,
size_t
len
)
{
robj
*
tail
;
if
(
c
->
flags
&
REDIS_CLOSE_AFTER_REPLY
)
return
;
...
...
@@ -317,7 +317,7 @@ void _addReplyStringToList(redisClient *c, const char *s, size_t len) {
* The following functions are the ones that commands implementations will call.
* -------------------------------------------------------------------------- */
void
addReply
(
redisC
lient
*
c
,
robj
*
obj
)
{
void
addReply
(
c
lient
*
c
,
robj
*
obj
)
{
if
(
prepareClientToWrite
(
c
)
!=
REDIS_OK
)
return
;
/* This is an important place where we can avoid copy-on-write
...
...
@@ -353,7 +353,7 @@ void addReply(redisClient *c, robj *obj) {
}
}
void
addReplySds
(
redisC
lient
*
c
,
sds
s
)
{
void
addReplySds
(
c
lient
*
c
,
sds
s
)
{
if
(
prepareClientToWrite
(
c
)
!=
REDIS_OK
)
{
/* The caller expects the sds to be free'd. */
sdsfree
(
s
);
...
...
@@ -367,23 +367,23 @@ void addReplySds(redisClient *c, sds s) {
}
}
void
addReplyString
(
redisC
lient
*
c
,
const
char
*
s
,
size_t
len
)
{
void
addReplyString
(
c
lient
*
c
,
const
char
*
s
,
size_t
len
)
{
if
(
prepareClientToWrite
(
c
)
!=
REDIS_OK
)
return
;
if
(
_addReplyToBuffer
(
c
,
s
,
len
)
!=
REDIS_OK
)
_addReplyStringToList
(
c
,
s
,
len
);
}
void
addReplyErrorLength
(
redisC
lient
*
c
,
const
char
*
s
,
size_t
len
)
{
void
addReplyErrorLength
(
c
lient
*
c
,
const
char
*
s
,
size_t
len
)
{
addReplyString
(
c
,
"-ERR "
,
5
);
addReplyString
(
c
,
s
,
len
);
addReplyString
(
c
,
"
\r\n
"
,
2
);
}
void
addReplyError
(
redisC
lient
*
c
,
const
char
*
err
)
{
void
addReplyError
(
c
lient
*
c
,
const
char
*
err
)
{
addReplyErrorLength
(
c
,
err
,
strlen
(
err
));
}
void
addReplyErrorFormat
(
redisC
lient
*
c
,
const
char
*
fmt
,
...)
{
void
addReplyErrorFormat
(
c
lient
*
c
,
const
char
*
fmt
,
...)
{
size_t
l
,
j
;
va_list
ap
;
va_start
(
ap
,
fmt
);
...
...
@@ -399,17 +399,17 @@ void addReplyErrorFormat(redisClient *c, const char *fmt, ...) {
sdsfree
(
s
);
}
void
addReplyStatusLength
(
redisC
lient
*
c
,
const
char
*
s
,
size_t
len
)
{
void
addReplyStatusLength
(
c
lient
*
c
,
const
char
*
s
,
size_t
len
)
{
addReplyString
(
c
,
"+"
,
1
);
addReplyString
(
c
,
s
,
len
);
addReplyString
(
c
,
"
\r\n
"
,
2
);
}
void
addReplyStatus
(
redisC
lient
*
c
,
const
char
*
status
)
{
void
addReplyStatus
(
c
lient
*
c
,
const
char
*
status
)
{
addReplyStatusLength
(
c
,
status
,
strlen
(
status
));
}
void
addReplyStatusFormat
(
redisC
lient
*
c
,
const
char
*
fmt
,
...)
{
void
addReplyStatusFormat
(
c
lient
*
c
,
const
char
*
fmt
,
...)
{
va_list
ap
;
va_start
(
ap
,
fmt
);
sds
s
=
sdscatvprintf
(
sdsempty
(),
fmt
,
ap
);
...
...
@@ -420,7 +420,7 @@ void addReplyStatusFormat(redisClient *c, const char *fmt, ...) {
/* Adds an empty object to the reply list that will contain the multi bulk
* length, which is not known when this function is called. */
void
*
addDeferredMultiBulkLength
(
redisC
lient
*
c
)
{
void
*
addDeferredMultiBulkLength
(
c
lient
*
c
)
{
/* Note that we install the write event here even if the object is not
* ready to be sent, since we are sure that before returning to the
* event loop setDeferredMultiBulkLength() will be called. */
...
...
@@ -430,7 +430,7 @@ void *addDeferredMultiBulkLength(redisClient *c) {
}
/* Populate the length object and try gluing it to the next chunk. */
void
setDeferredMultiBulkLength
(
redisC
lient
*
c
,
void
*
node
,
long
length
)
{
void
setDeferredMultiBulkLength
(
c
lient
*
c
,
void
*
node
,
long
length
)
{
listNode
*
ln
=
(
listNode
*
)
node
;
robj
*
len
,
*
next
;
...
...
@@ -457,7 +457,7 @@ void setDeferredMultiBulkLength(redisClient *c, void *node, long length) {
}
/* Add a double as a bulk reply */
void
addReplyDouble
(
redisC
lient
*
c
,
double
d
)
{
void
addReplyDouble
(
c
lient
*
c
,
double
d
)
{
char
dbuf
[
128
],
sbuf
[
128
];
int
dlen
,
slen
;
if
(
isinf
(
d
))
{
...
...
@@ -473,7 +473,7 @@ void addReplyDouble(redisClient *c, double d) {
/* Add a long long as integer reply or bulk len / multi bulk count.
* Basically this is used to output <prefix><long long><crlf>. */
void
addReplyLongLongWithPrefix
(
redisC
lient
*
c
,
long
long
ll
,
char
prefix
)
{
void
addReplyLongLongWithPrefix
(
c
lient
*
c
,
long
long
ll
,
char
prefix
)
{
char
buf
[
128
];
int
len
;
...
...
@@ -495,7 +495,7 @@ void addReplyLongLongWithPrefix(redisClient *c, long long ll, char prefix) {
addReplyString
(
c
,
buf
,
len
+
3
);
}
void
addReplyLongLong
(
redisC
lient
*
c
,
long
long
ll
)
{
void
addReplyLongLong
(
c
lient
*
c
,
long
long
ll
)
{
if
(
ll
==
0
)
addReply
(
c
,
shared
.
czero
);
else
if
(
ll
==
1
)
...
...
@@ -504,7 +504,7 @@ void addReplyLongLong(redisClient *c, long long ll) {
addReplyLongLongWithPrefix
(
c
,
ll
,
':'
);
}
void
addReplyMultiBulkLen
(
redisC
lient
*
c
,
long
length
)
{
void
addReplyMultiBulkLen
(
c
lient
*
c
,
long
length
)
{
if
(
length
<
REDIS_SHARED_BULKHDR_LEN
)
addReply
(
c
,
shared
.
mbulkhdr
[
length
]);
else
...
...
@@ -512,7 +512,7 @@ void addReplyMultiBulkLen(redisClient *c, long length) {
}
/* Create the length prefix of a bulk reply, example: $2234 */
void
addReplyBulkLen
(
redisC
lient
*
c
,
robj
*
obj
)
{
void
addReplyBulkLen
(
c
lient
*
c
,
robj
*
obj
)
{
size_t
len
;
if
(
sdsEncodedObject
(
obj
))
{
...
...
@@ -538,21 +538,21 @@ void addReplyBulkLen(redisClient *c, robj *obj) {
}
/* Add a Redis Object as a bulk reply */
void
addReplyBulk
(
redisC
lient
*
c
,
robj
*
obj
)
{
void
addReplyBulk
(
c
lient
*
c
,
robj
*
obj
)
{
addReplyBulkLen
(
c
,
obj
);
addReply
(
c
,
obj
);
addReply
(
c
,
shared
.
crlf
);
}
/* Add a C buffer as bulk reply */
void
addReplyBulkCBuffer
(
redisC
lient
*
c
,
const
void
*
p
,
size_t
len
)
{
void
addReplyBulkCBuffer
(
c
lient
*
c
,
const
void
*
p
,
size_t
len
)
{
addReplyLongLongWithPrefix
(
c
,
len
,
'$'
);
addReplyString
(
c
,
p
,
len
);
addReply
(
c
,
shared
.
crlf
);
}
/* Add sds to reply (takes ownership of sds and frees it) */
void
addReplyBulkSds
(
redisC
lient
*
c
,
sds
s
)
{
void
addReplyBulkSds
(
c
lient
*
c
,
sds
s
)
{
addReplySds
(
c
,
sdscatfmt
(
sdsempty
(),
"$%u
\r\n
"
,
(
unsigned
long
)
sdslen
(
s
)));
addReplySds
(
c
,
s
);
...
...
@@ -560,7 +560,7 @@ void addReplyBulkSds(redisClient *c, sds s) {
}
/* Add a C nul term string as bulk reply */
void
addReplyBulkCString
(
redisC
lient
*
c
,
const
char
*
s
)
{
void
addReplyBulkCString
(
c
lient
*
c
,
const
char
*
s
)
{
if
(
s
==
NULL
)
{
addReply
(
c
,
shared
.
nullbulk
);
}
else
{
...
...
@@ -569,7 +569,7 @@ void addReplyBulkCString(redisClient *c, const char *s) {
}
/* Add a long long as a bulk reply */
void
addReplyBulkLongLong
(
redisC
lient
*
c
,
long
long
ll
)
{
void
addReplyBulkLongLong
(
c
lient
*
c
,
long
long
ll
)
{
char
buf
[
64
];
int
len
;
...
...
@@ -580,7 +580,7 @@ void addReplyBulkLongLong(redisClient *c, long long ll) {
/* Copy 'src' client output buffers into 'dst' client output buffers.
* The function takes care of freeing the old output buffers of the
* destination client. */
void
copyClientOutputBuffer
(
redisC
lient
*
dst
,
redisC
lient
*
src
)
{
void
copyClientOutputBuffer
(
c
lient
*
dst
,
c
lient
*
src
)
{
listRelease
(
dst
->
reply
);
dst
->
reply
=
listDup
(
src
->
reply
);
memcpy
(
dst
->
buf
,
src
->
buf
,
src
->
bufpos
);
...
...
@@ -590,7 +590,7 @@ void copyClientOutputBuffer(redisClient *dst, redisClient *src) {
#define MAX_ACCEPTS_PER_CALL 1000
static
void
acceptCommonHandler
(
int
fd
,
int
flags
)
{
redisC
lient
*
c
;
c
lient
*
c
;
if
((
c
=
createClient
(
fd
))
==
NULL
)
{
serverLog
(
REDIS_WARNING
,
"Error registering fd event for the new client: %s (fd=%d)"
,
...
...
@@ -656,7 +656,7 @@ void acceptUnixHandler(aeEventLoop *el, int fd, void *privdata, int mask) {
}
}
static
void
freeClientArgv
(
redisC
lient
*
c
)
{
static
void
freeClientArgv
(
c
lient
*
c
)
{
int
j
;
for
(
j
=
0
;
j
<
c
->
argc
;
j
++
)
decrRefCount
(
c
->
argv
[
j
]);
...
...
@@ -670,7 +670,7 @@ static void freeClientArgv(redisClient *c) {
void
disconnectSlaves
(
void
)
{
while
(
listLength
(
server
.
slaves
))
{
listNode
*
ln
=
listFirst
(
server
.
slaves
);
freeClient
((
redisC
lient
*
)
ln
->
value
);
freeClient
((
c
lient
*
)
ln
->
value
);
}
}
...
...
@@ -688,7 +688,7 @@ void replicationHandleMasterDisconnection(void) {
if
(
server
.
masterhost
!=
NULL
)
disconnectSlaves
();
}
void
freeClient
(
redisC
lient
*
c
)
{
void
freeClient
(
c
lient
*
c
)
{
listNode
*
ln
;
/* If this is marked as current client unset it */
...
...
@@ -804,7 +804,7 @@ void freeClient(redisClient *c) {
* This function is useful when we need to terminate a client but we are in
* a context where calling freeClient() is not possible, because the client
* should be valid for the continuation of the flow of the program. */
void
freeClientAsync
(
redisC
lient
*
c
)
{
void
freeClientAsync
(
c
lient
*
c
)
{
if
(
c
->
flags
&
REDIS_CLOSE_ASAP
||
c
->
flags
&
REDIS_LUA_CLIENT
)
return
;
c
->
flags
|=
REDIS_CLOSE_ASAP
;
listAddNodeTail
(
server
.
clients_to_close
,
c
);
...
...
@@ -813,7 +813,7 @@ void freeClientAsync(redisClient *c) {
void
freeClientsInAsyncFreeQueue
(
void
)
{
while
(
listLength
(
server
.
clients_to_close
))
{
listNode
*
ln
=
listFirst
(
server
.
clients_to_close
);
redisC
lient
*
c
=
listNodeValue
(
ln
);
c
lient
*
c
=
listNodeValue
(
ln
);
c
->
flags
&=
~
REDIS_CLOSE_ASAP
;
freeClient
(
c
);
...
...
@@ -822,7 +822,7 @@ void freeClientsInAsyncFreeQueue(void) {
}
void
sendReplyToClient
(
aeEventLoop
*
el
,
int
fd
,
void
*
privdata
,
int
mask
)
{
redisC
lient
*
c
=
privdata
;
c
lient
*
c
=
privdata
;
ssize_t
nwritten
=
0
,
totwritten
=
0
;
size_t
objlen
;
size_t
objmem
;
...
...
@@ -906,7 +906,7 @@ void sendReplyToClient(aeEventLoop *el, int fd, void *privdata, int mask) {
}
/* resetClient prepare the client to process the next command */
void
resetClient
(
redisC
lient
*
c
)
{
void
resetClient
(
c
lient
*
c
)
{
redisCommandProc
*
prevcmd
=
c
->
cmd
?
c
->
cmd
->
proc
:
NULL
;
freeClientArgv
(
c
);
...
...
@@ -919,7 +919,7 @@ void resetClient(redisClient *c) {
c
->
flags
&=
(
~
REDIS_ASKING
);
}
int
processInlineBuffer
(
redisC
lient
*
c
)
{
int
processInlineBuffer
(
c
lient
*
c
)
{
char
*
newline
;
int
argc
,
j
;
sds
*
argv
,
aux
;
...
...
@@ -982,7 +982,7 @@ int processInlineBuffer(redisClient *c) {
/* Helper function. Trims query buffer to make the function that processes
* multi bulk requests idempotent. */
static
void
setProtocolError
(
redisC
lient
*
c
,
int
pos
)
{
static
void
setProtocolError
(
c
lient
*
c
,
int
pos
)
{
if
(
server
.
verbosity
<=
REDIS_VERBOSE
)
{
sds
client
=
catClientInfoString
(
sdsempty
(),
c
);
serverLog
(
REDIS_VERBOSE
,
...
...
@@ -993,7 +993,7 @@ static void setProtocolError(redisClient *c, int pos) {
sdsrange
(
c
->
querybuf
,
pos
,
-
1
);
}
int
processMultibulkBuffer
(
redisC
lient
*
c
)
{
int
processMultibulkBuffer
(
c
lient
*
c
)
{
char
*
newline
=
NULL
;
int
pos
=
0
,
ok
;
long
long
ll
;
...
...
@@ -1131,7 +1131,7 @@ int processMultibulkBuffer(redisClient *c) {
return
REDIS_ERR
;
}
void
processInputBuffer
(
redisC
lient
*
c
)
{
void
processInputBuffer
(
c
lient
*
c
)
{
server
.
current_client
=
c
;
/* Keep processing while there is something in the input buffer */
while
(
sdslen
(
c
->
querybuf
))
{
...
...
@@ -1176,7 +1176,7 @@ void processInputBuffer(redisClient *c) {
}
void
readQueryFromClient
(
aeEventLoop
*
el
,
int
fd
,
void
*
privdata
,
int
mask
)
{
redisC
lient
*
c
=
(
redisC
lient
*
)
privdata
;
c
lient
*
c
=
(
c
lient
*
)
privdata
;
int
nread
,
readlen
;
size_t
qblen
;
REDIS_NOTUSED
(
el
);
...
...
@@ -1234,7 +1234,7 @@ void readQueryFromClient(aeEventLoop *el, int fd, void *privdata, int mask) {
void
getClientsMaxBuffers
(
unsigned
long
*
longest_output_list
,
unsigned
long
*
biggest_input_buffer
)
{
redisC
lient
*
c
;
c
lient
*
c
;
listNode
*
ln
;
listIter
li
;
unsigned
long
lol
=
0
,
bib
=
0
;
...
...
@@ -1261,7 +1261,7 @@ void getClientsMaxBuffers(unsigned long *longest_output_list,
* On failure the function still populates 'peerid' with the "?:0" string
* in case you want to relax error checking or need to display something
* anyway (see anetPeerToString implementation for more info). */
void
genClientPeerId
(
redisC
lient
*
client
,
char
*
peerid
,
void
genClientPeerId
(
c
lient
*
client
,
char
*
peerid
,
size_t
peerid_len
)
{
if
(
client
->
flags
&
REDIS_UNIX_SOCKET
)
{
/* Unix socket client. */
...
...
@@ -1276,7 +1276,7 @@ void genClientPeerId(redisClient *client, char *peerid,
* if client->peerid is NULL, otherwise returning the cached value.
* The Peer ID never changes during the life of the client, however it
* is expensive to compute. */
char
*
getClientPeerId
(
redisC
lient
*
c
)
{
char
*
getClientPeerId
(
c
lient
*
c
)
{
char
peerid
[
REDIS_PEER_ID_LEN
];
if
(
c
->
peerid
==
NULL
)
{
...
...
@@ -1288,7 +1288,7 @@ char *getClientPeerId(redisClient *c) {
/* Concatenate a string representing the state of a client in an human
* readable format, into the sds string 's'. */
sds
catClientInfoString
(
sds
s
,
redisC
lient
*
client
)
{
sds
catClientInfoString
(
sds
s
,
c
lient
*
client
)
{
char
flags
[
16
],
events
[
3
],
*
p
;
int
emask
;
...
...
@@ -1341,7 +1341,7 @@ sds catClientInfoString(sds s, redisClient *client) {
sds
getAllClientsInfoString
(
void
)
{
listNode
*
ln
;
listIter
li
;
redisC
lient
*
client
;
c
lient
*
client
;
sds
o
=
sdsempty
();
o
=
sdsMakeRoomFor
(
o
,
200
*
listLength
(
server
.
clients
));
...
...
@@ -1354,10 +1354,10 @@ sds getAllClientsInfoString(void) {
return
o
;
}
void
clientCommand
(
redisC
lient
*
c
)
{
void
clientCommand
(
c
lient
*
c
)
{
listNode
*
ln
;
listIter
li
;
redisC
lient
*
client
;
c
lient
*
client
;
if
(
!
strcasecmp
(
c
->
argv
[
1
]
->
ptr
,
"list"
)
&&
c
->
argc
==
2
)
{
/* CLIENT LIST */
...
...
@@ -1500,7 +1500,7 @@ void clientCommand(redisClient *c) {
/* Rewrite the command vector of the client. All the new objects ref count
* is incremented. The old command vector is freed, and the old objects
* ref count is decremented. */
void
rewriteClientCommandVector
(
redisC
lient
*
c
,
int
argc
,
...)
{
void
rewriteClientCommandVector
(
c
lient
*
c
,
int
argc
,
...)
{
va_list
ap
;
int
j
;
robj
**
argv
;
/* The new argument vector */
...
...
@@ -1528,7 +1528,7 @@ void rewriteClientCommandVector(redisClient *c, int argc, ...) {
}
/* Completely replace the client command vector with the provided one. */
void
replaceClientCommandVector
(
redisC
lient
*
c
,
int
argc
,
robj
**
argv
)
{
void
replaceClientCommandVector
(
c
lient
*
c
,
int
argc
,
robj
**
argv
)
{
freeClientArgv
(
c
);
zfree
(
c
->
argv
);
c
->
argv
=
argv
;
...
...
@@ -1539,7 +1539,7 @@ void replaceClientCommandVector(redisClient *c, int argc, robj **argv) {
/* Rewrite a single item in the command vector.
* The new val ref count is incremented, and the old decremented. */
void
rewriteClientCommandArgument
(
redisC
lient
*
c
,
int
i
,
robj
*
newval
)
{
void
rewriteClientCommandArgument
(
c
lient
*
c
,
int
i
,
robj
*
newval
)
{
robj
*
oldval
;
redisAssertWithInfo
(
c
,
NULL
,
i
<
c
->
argc
);
...
...
@@ -1568,7 +1568,7 @@ void rewriteClientCommandArgument(redisClient *c, int i, robj *newval) {
* Note: this function is very fast so can be called as many time as
* the caller wishes. The main usage of this function currently is
* enforcing the client output length limits. */
unsigned
long
getClientOutputBufferMemoryUsage
(
redisC
lient
*
c
)
{
unsigned
long
getClientOutputBufferMemoryUsage
(
c
lient
*
c
)
{
unsigned
long
list_item_size
=
sizeof
(
listNode
)
+
sizeof
(
robj
);
return
c
->
reply_bytes
+
(
list_item_size
*
listLength
(
c
->
reply
));
...
...
@@ -1582,7 +1582,7 @@ unsigned long getClientOutputBufferMemoryUsage(redisClient *c) {
* REDIS_CLIENT_TYPE_SLAVE -> Slave or client executing MONITOR command
* REDIS_CLIENT_TYPE_PUBSUB -> Client subscribed to Pub/Sub channels
*/
int
getClientType
(
redisC
lient
*
c
)
{
int
getClientType
(
c
lient
*
c
)
{
if
((
c
->
flags
&
REDIS_SLAVE
)
&&
!
(
c
->
flags
&
REDIS_MONITOR
))
return
REDIS_CLIENT_TYPE_SLAVE
;
if
(
c
->
flags
&
REDIS_PUBSUB
)
...
...
@@ -1612,7 +1612,7 @@ char *getClientTypeName(int class) {
*
* Return value: non-zero if the client reached the soft or the hard limit.
* Otherwise zero is returned. */
int
checkClientOutputBufferLimits
(
redisC
lient
*
c
)
{
int
checkClientOutputBufferLimits
(
c
lient
*
c
)
{
int
soft
=
0
,
hard
=
0
,
class
;
unsigned
long
used_mem
=
getClientOutputBufferMemoryUsage
(
c
);
...
...
@@ -1653,7 +1653,7 @@ int checkClientOutputBufferLimits(redisClient *c) {
* Note: we need to close the client asynchronously because this function is
* called from contexts where the client can't be freed safely, i.e. from the
* lower level functions pushing data inside the client output buffers. */
void
asyncCloseClientOnOutputBufferLimitReached
(
redisC
lient
*
c
)
{
void
asyncCloseClientOnOutputBufferLimitReached
(
c
lient
*
c
)
{
redisAssert
(
c
->
reply_bytes
<
SIZE_MAX
-
(
1024
*
64
));
if
(
c
->
reply_bytes
==
0
||
c
->
flags
&
REDIS_CLOSE_ASAP
)
return
;
if
(
checkClientOutputBufferLimits
(
c
))
{
...
...
@@ -1673,7 +1673,7 @@ void flushSlavesOutputBuffers(void) {
listRewind
(
server
.
slaves
,
&
li
);
while
((
ln
=
listNext
(
&
li
)))
{
redisC
lient
*
slave
=
listNodeValue
(
ln
);
c
lient
*
slave
=
listNodeValue
(
ln
);
int
events
;
events
=
aeGetFileEvents
(
server
.
el
,
slave
->
fd
);
...
...
@@ -1717,7 +1717,7 @@ int clientsArePaused(void) {
{
listNode
*
ln
;
listIter
li
;
redisC
lient
*
c
;
c
lient
*
c
;
server
.
clients_paused
=
0
;
...
...
src/object.c
View file @
554bd0e7
...
...
@@ -339,7 +339,7 @@ robj *resetRefCount(robj *obj) {
return
obj
;
}
int
checkType
(
redisC
lient
*
c
,
robj
*
o
,
int
type
)
{
int
checkType
(
c
lient
*
c
,
robj
*
o
,
int
type
)
{
if
(
o
->
type
!=
type
)
{
addReply
(
c
,
shared
.
wrongtypeerr
);
return
1
;
...
...
@@ -562,7 +562,7 @@ int getDoubleFromObject(robj *o, double *target) {
return
REDIS_OK
;
}
int
getDoubleFromObjectOrReply
(
redisC
lient
*
c
,
robj
*
o
,
double
*
target
,
const
char
*
msg
)
{
int
getDoubleFromObjectOrReply
(
c
lient
*
c
,
robj
*
o
,
double
*
target
,
const
char
*
msg
)
{
double
value
;
if
(
getDoubleFromObject
(
o
,
&
value
)
!=
REDIS_OK
)
{
if
(
msg
!=
NULL
)
{
...
...
@@ -600,7 +600,7 @@ int getLongDoubleFromObject(robj *o, long double *target) {
return
REDIS_OK
;
}
int
getLongDoubleFromObjectOrReply
(
redisC
lient
*
c
,
robj
*
o
,
long
double
*
target
,
const
char
*
msg
)
{
int
getLongDoubleFromObjectOrReply
(
c
lient
*
c
,
robj
*
o
,
long
double
*
target
,
const
char
*
msg
)
{
long
double
value
;
if
(
getLongDoubleFromObject
(
o
,
&
value
)
!=
REDIS_OK
)
{
if
(
msg
!=
NULL
)
{
...
...
@@ -638,7 +638,7 @@ int getLongLongFromObject(robj *o, long long *target) {
return
REDIS_OK
;
}
int
getLongLongFromObjectOrReply
(
redisC
lient
*
c
,
robj
*
o
,
long
long
*
target
,
const
char
*
msg
)
{
int
getLongLongFromObjectOrReply
(
c
lient
*
c
,
robj
*
o
,
long
long
*
target
,
const
char
*
msg
)
{
long
long
value
;
if
(
getLongLongFromObject
(
o
,
&
value
)
!=
REDIS_OK
)
{
if
(
msg
!=
NULL
)
{
...
...
@@ -652,7 +652,7 @@ int getLongLongFromObjectOrReply(redisClient *c, robj *o, long long *target, con
return
REDIS_OK
;
}
int
getLongFromObjectOrReply
(
redisC
lient
*
c
,
robj
*
o
,
long
*
target
,
const
char
*
msg
)
{
int
getLongFromObjectOrReply
(
c
lient
*
c
,
robj
*
o
,
long
*
target
,
const
char
*
msg
)
{
long
long
value
;
if
(
getLongLongFromObjectOrReply
(
c
,
o
,
&
value
,
msg
)
!=
REDIS_OK
)
return
REDIS_ERR
;
...
...
@@ -696,14 +696,14 @@ unsigned long long estimateObjectIdleTime(robj *o) {
/* This is a helper function for the OBJECT command. We need to lookup keys
* without any modification of LRU or other parameters. */
robj
*
objectCommandLookup
(
redisC
lient
*
c
,
robj
*
key
)
{
robj
*
objectCommandLookup
(
c
lient
*
c
,
robj
*
key
)
{
dictEntry
*
de
;
if
((
de
=
dictFind
(
c
->
db
->
dict
,
key
->
ptr
))
==
NULL
)
return
NULL
;
return
(
robj
*
)
dictGetVal
(
de
);
}
robj
*
objectCommandLookupOrReply
(
redisC
lient
*
c
,
robj
*
key
,
robj
*
reply
)
{
robj
*
objectCommandLookupOrReply
(
c
lient
*
c
,
robj
*
key
,
robj
*
reply
)
{
robj
*
o
=
objectCommandLookup
(
c
,
key
);
if
(
!
o
)
addReply
(
c
,
reply
);
...
...
@@ -712,7 +712,7 @@ robj *objectCommandLookupOrReply(redisClient *c, robj *key, robj *reply) {
/* Object command allows to inspect the internals of an Redis Object.
* Usage: OBJECT <refcount|encoding|idletime> <key> */
void
objectCommand
(
redisC
lient
*
c
)
{
void
objectCommand
(
c
lient
*
c
)
{
robj
*
o
;
if
(
!
strcasecmp
(
c
->
argv
[
1
]
->
ptr
,
"refcount"
)
&&
c
->
argc
==
3
)
{
...
...
src/pubsub.c
View file @
554bd0e7
...
...
@@ -48,14 +48,14 @@ int listMatchPubsubPattern(void *a, void *b) {
}
/* Return the number of channels + patterns a client is subscribed to. */
int
clientSubscriptionsCount
(
redisC
lient
*
c
)
{
int
clientSubscriptionsCount
(
c
lient
*
c
)
{
return
dictSize
(
c
->
pubsub_channels
)
+
listLength
(
c
->
pubsub_patterns
);
}
/* Subscribe a client to a channel. Returns 1 if the operation succeeded, or
* 0 if the client was already subscribed to that channel. */
int
pubsubSubscribeChannel
(
redisC
lient
*
c
,
robj
*
channel
)
{
int
pubsubSubscribeChannel
(
c
lient
*
c
,
robj
*
channel
)
{
dictEntry
*
de
;
list
*
clients
=
NULL
;
int
retval
=
0
;
...
...
@@ -85,7 +85,7 @@ int pubsubSubscribeChannel(redisClient *c, robj *channel) {
/* Unsubscribe a client from a channel. Returns 1 if the operation succeeded, or
* 0 if the client was not subscribed to the specified channel. */
int
pubsubUnsubscribeChannel
(
redisC
lient
*
c
,
robj
*
channel
,
int
notify
)
{
int
pubsubUnsubscribeChannel
(
c
lient
*
c
,
robj
*
channel
,
int
notify
)
{
dictEntry
*
de
;
list
*
clients
;
listNode
*
ln
;
...
...
@@ -124,7 +124,7 @@ int pubsubUnsubscribeChannel(redisClient *c, robj *channel, int notify) {
}
/* Subscribe a client to a pattern. Returns 1 if the operation succeeded, or 0 if the client was already subscribed to that pattern. */
int
pubsubSubscribePattern
(
redisC
lient
*
c
,
robj
*
pattern
)
{
int
pubsubSubscribePattern
(
c
lient
*
c
,
robj
*
pattern
)
{
int
retval
=
0
;
if
(
listSearchKey
(
c
->
pubsub_patterns
,
pattern
)
==
NULL
)
{
...
...
@@ -147,7 +147,7 @@ int pubsubSubscribePattern(redisClient *c, robj *pattern) {
/* Unsubscribe a client from a channel. Returns 1 if the operation succeeded, or
* 0 if the client was not subscribed to the specified channel. */
int
pubsubUnsubscribePattern
(
redisC
lient
*
c
,
robj
*
pattern
,
int
notify
)
{
int
pubsubUnsubscribePattern
(
c
lient
*
c
,
robj
*
pattern
,
int
notify
)
{
listNode
*
ln
;
pubsubPattern
pat
;
int
retval
=
0
;
...
...
@@ -175,7 +175,7 @@ int pubsubUnsubscribePattern(redisClient *c, robj *pattern, int notify) {
/* Unsubscribe from all the channels. Return the number of channels the
* client was subscribed to. */
int
pubsubUnsubscribeAllChannels
(
redisC
lient
*
c
,
int
notify
)
{
int
pubsubUnsubscribeAllChannels
(
c
lient
*
c
,
int
notify
)
{
dictIterator
*
di
=
dictGetSafeIterator
(
c
->
pubsub_channels
);
dictEntry
*
de
;
int
count
=
0
;
...
...
@@ -199,7 +199,7 @@ int pubsubUnsubscribeAllChannels(redisClient *c, int notify) {
/* Unsubscribe from all the patterns. Return the number of patterns the
* client was subscribed from. */
int
pubsubUnsubscribeAllPatterns
(
redisC
lient
*
c
,
int
notify
)
{
int
pubsubUnsubscribeAllPatterns
(
c
lient
*
c
,
int
notify
)
{
listNode
*
ln
;
listIter
li
;
int
count
=
0
;
...
...
@@ -237,7 +237,7 @@ int pubsubPublishMessage(robj *channel, robj *message) {
listRewind
(
list
,
&
li
);
while
((
ln
=
listNext
(
&
li
))
!=
NULL
)
{
redisC
lient
*
c
=
ln
->
value
;
c
lient
*
c
=
ln
->
value
;
addReply
(
c
,
shared
.
mbulkhdr
[
3
]);
addReply
(
c
,
shared
.
messagebulk
);
...
...
@@ -274,7 +274,7 @@ int pubsubPublishMessage(robj *channel, robj *message) {
* Pubsub commands implementation
*----------------------------------------------------------------------------*/
void
subscribeCommand
(
redisC
lient
*
c
)
{
void
subscribeCommand
(
c
lient
*
c
)
{
int
j
;
for
(
j
=
1
;
j
<
c
->
argc
;
j
++
)
...
...
@@ -282,7 +282,7 @@ void subscribeCommand(redisClient *c) {
c
->
flags
|=
REDIS_PUBSUB
;
}
void
unsubscribeCommand
(
redisC
lient
*
c
)
{
void
unsubscribeCommand
(
c
lient
*
c
)
{
if
(
c
->
argc
==
1
)
{
pubsubUnsubscribeAllChannels
(
c
,
1
);
}
else
{
...
...
@@ -294,7 +294,7 @@ void unsubscribeCommand(redisClient *c) {
if
(
clientSubscriptionsCount
(
c
)
==
0
)
c
->
flags
&=
~
REDIS_PUBSUB
;
}
void
psubscribeCommand
(
redisC
lient
*
c
)
{
void
psubscribeCommand
(
c
lient
*
c
)
{
int
j
;
for
(
j
=
1
;
j
<
c
->
argc
;
j
++
)
...
...
@@ -302,7 +302,7 @@ void psubscribeCommand(redisClient *c) {
c
->
flags
|=
REDIS_PUBSUB
;
}
void
punsubscribeCommand
(
redisC
lient
*
c
)
{
void
punsubscribeCommand
(
c
lient
*
c
)
{
if
(
c
->
argc
==
1
)
{
pubsubUnsubscribeAllPatterns
(
c
,
1
);
}
else
{
...
...
@@ -314,7 +314,7 @@ void punsubscribeCommand(redisClient *c) {
if
(
clientSubscriptionsCount
(
c
)
==
0
)
c
->
flags
&=
~
REDIS_PUBSUB
;
}
void
publishCommand
(
redisC
lient
*
c
)
{
void
publishCommand
(
c
lient
*
c
)
{
int
receivers
=
pubsubPublishMessage
(
c
->
argv
[
1
],
c
->
argv
[
2
]);
if
(
server
.
cluster_enabled
)
clusterPropagatePublish
(
c
->
argv
[
1
],
c
->
argv
[
2
]);
...
...
@@ -324,7 +324,7 @@ void publishCommand(redisClient *c) {
}
/* PUBSUB command for Pub/Sub introspection. */
void
pubsubCommand
(
redisC
lient
*
c
)
{
void
pubsubCommand
(
c
lient
*
c
)
{
if
(
!
strcasecmp
(
c
->
argv
[
1
]
->
ptr
,
"channels"
)
&&
(
c
->
argc
==
2
||
c
->
argc
==
3
))
{
...
...
src/rdb.c
View file @
554bd0e7
...
...
@@ -1482,7 +1482,7 @@ void backgroundSaveDoneHandlerSocket(int exitcode, int bysignal) {
listRewind
(
server
.
slaves
,
&
li
);
while
((
ln
=
listNext
(
&
li
)))
{
redisC
lient
*
slave
=
ln
->
value
;
c
lient
*
slave
=
ln
->
value
;
if
(
slave
->
replstate
==
REDIS_REPL_WAIT_BGSAVE_END
)
{
uint64_t
j
;
...
...
@@ -1566,7 +1566,7 @@ int rdbSaveToSlavesSockets(void) {
listRewind
(
server
.
slaves
,
&
li
);
while
((
ln
=
listNext
(
&
li
)))
{
redisC
lient
*
slave
=
ln
->
value
;
c
lient
*
slave
=
ln
->
value
;
if
(
slave
->
replstate
==
REDIS_REPL_WAIT_BGSAVE_START
)
{
clientids
[
numfds
]
=
slave
->
id
;
...
...
@@ -1672,7 +1672,7 @@ int rdbSaveToSlavesSockets(void) {
return
REDIS_OK
;
/* unreached */
}
void
saveCommand
(
redisC
lient
*
c
)
{
void
saveCommand
(
c
lient
*
c
)
{
if
(
server
.
rdb_child_pid
!=
-
1
)
{
addReplyError
(
c
,
"Background save already in progress"
);
return
;
...
...
@@ -1684,7 +1684,7 @@ void saveCommand(redisClient *c) {
}
}
void
bgsaveCommand
(
redisC
lient
*
c
)
{
void
bgsaveCommand
(
c
lient
*
c
)
{
if
(
server
.
rdb_child_pid
!=
-
1
)
{
addReplyError
(
c
,
"Background save already in progress"
);
}
else
if
(
server
.
aof_child_pid
!=
-
1
)
{
...
...
src/replication.c
View file @
554bd0e7
...
...
@@ -40,7 +40,7 @@
void
replicationDiscardCachedMaster
(
void
);
void
replicationResurrectCachedMaster
(
int
newfd
);
void
replicationSendAck
(
void
);
void
putSlaveOnline
(
redisC
lient
*
slave
);
void
putSlaveOnline
(
c
lient
*
slave
);
/* --------------------------- Utility functions ---------------------------- */
...
...
@@ -48,7 +48,7 @@ void putSlaveOnline(redisClient *slave);
* pair. Mostly useful for logging, since we want to log a slave using its
* IP address and it's listening port which is more clear for the user, for
* example: "Closing connection with slave 10.1.2.3:6380". */
char
*
replicationGetSlaveName
(
redisC
lient
*
c
)
{
char
*
replicationGetSlaveName
(
c
lient
*
c
)
{
static
char
buf
[
REDIS_PEER_ID_LEN
];
char
ip
[
REDIS_IP_STR_LEN
];
...
...
@@ -200,7 +200,7 @@ void replicationFeedSlaves(list *slaves, int dictid, robj **argv, int argc) {
/* Send it to slaves. */
listRewind
(
slaves
,
&
li
);
while
((
ln
=
listNext
(
&
li
)))
{
redisC
lient
*
slave
=
ln
->
value
;
c
lient
*
slave
=
ln
->
value
;
addReply
(
slave
,
selectcmd
);
}
...
...
@@ -239,7 +239,7 @@ void replicationFeedSlaves(list *slaves, int dictid, robj **argv, int argc) {
/* Write the command to every slave. */
listRewind
(
server
.
slaves
,
&
li
);
while
((
ln
=
listNext
(
&
li
)))
{
redisC
lient
*
slave
=
ln
->
value
;
c
lient
*
slave
=
ln
->
value
;
/* Don't feed slaves that are still waiting for BGSAVE to start */
if
(
slave
->
replstate
==
REDIS_REPL_WAIT_BGSAVE_START
)
continue
;
...
...
@@ -258,7 +258,7 @@ void replicationFeedSlaves(list *slaves, int dictid, robj **argv, int argc) {
}
}
void
replicationFeedMonitors
(
redisC
lient
*
c
,
list
*
monitors
,
int
dictid
,
robj
**
argv
,
int
argc
)
{
void
replicationFeedMonitors
(
c
lient
*
c
,
list
*
monitors
,
int
dictid
,
robj
**
argv
,
int
argc
)
{
listNode
*
ln
;
listIter
li
;
int
j
;
...
...
@@ -291,7 +291,7 @@ void replicationFeedMonitors(redisClient *c, list *monitors, int dictid, robj **
listRewind
(
monitors
,
&
li
);
while
((
ln
=
listNext
(
&
li
)))
{
redisC
lient
*
monitor
=
ln
->
value
;
c
lient
*
monitor
=
ln
->
value
;
addReply
(
monitor
,
cmdobj
);
}
decrRefCount
(
cmdobj
);
...
...
@@ -299,7 +299,7 @@ void replicationFeedMonitors(redisClient *c, list *monitors, int dictid, robj **
/* Feed the slave 'c' with the replication backlog starting from the
* specified 'offset' up to the end of the backlog. */
long
long
addReplyReplicationBacklog
(
redisC
lient
*
c
,
long
long
offset
)
{
long
long
addReplyReplicationBacklog
(
c
lient
*
c
,
long
long
offset
)
{
long
long
j
,
skip
,
len
;
serverLog
(
REDIS_DEBUG
,
"[PSYNC] Slave request offset: %lld"
,
offset
);
...
...
@@ -354,7 +354,7 @@ long long addReplyReplicationBacklog(redisClient *c, long long offset) {
*
* On success return REDIS_OK, otherwise REDIS_ERR is returned and we proceed
* with the usual full resync. */
int
masterTryPartialResynchronization
(
redisC
lient
*
c
)
{
int
masterTryPartialResynchronization
(
c
lient
*
c
)
{
long
long
psync_offset
,
psync_len
;
char
*
master_runid
=
c
->
argv
[
1
]
->
ptr
;
char
buf
[
128
];
...
...
@@ -460,7 +460,7 @@ int startBgsaveForReplication(void) {
}
/* SYNC and PSYNC command implemenation. */
void
syncCommand
(
redisC
lient
*
c
)
{
void
syncCommand
(
c
lient
*
c
)
{
/* ignore SYNC if already slave or in monitor mode */
if
(
c
->
flags
&
REDIS_SLAVE
)
return
;
...
...
@@ -523,7 +523,7 @@ void syncCommand(redisClient *c) {
/* Ok a background save is in progress. Let's check if it is a good
* one for replication, i.e. if there is another slave that is
* registering differences since the server forked to save. */
redisC
lient
*
slave
;
c
lient
*
slave
;
listNode
*
ln
;
listIter
li
;
...
...
@@ -594,7 +594,7 @@ void syncCommand(redisClient *c) {
* In the future the same command can be used in order to configure
* the replication to initiate an incremental replication instead of a
* full resync. */
void
replconfCommand
(
redisC
lient
*
c
)
{
void
replconfCommand
(
c
lient
*
c
)
{
int
j
;
if
((
c
->
argc
%
2
)
==
0
)
{
...
...
@@ -658,7 +658,7 @@ void replconfCommand(redisClient *c) {
* command disables it, so that we can accumulate output buffer without
* sending it to the slave.
* 3) Update the count of good slaves. */
void
putSlaveOnline
(
redisC
lient
*
slave
)
{
void
putSlaveOnline
(
c
lient
*
slave
)
{
slave
->
replstate
=
REDIS_REPL_ONLINE
;
slave
->
repl_put_online_on_ack
=
0
;
slave
->
repl_ack_time
=
server
.
unixtime
;
/* Prevent false timeout. */
...
...
@@ -674,7 +674,7 @@ void putSlaveOnline(redisClient *slave) {
}
void
sendBulkToSlave
(
aeEventLoop
*
el
,
int
fd
,
void
*
privdata
,
int
mask
)
{
redisC
lient
*
slave
=
privdata
;
c
lient
*
slave
=
privdata
;
REDIS_NOTUSED
(
el
);
REDIS_NOTUSED
(
mask
);
char
buf
[
REDIS_IOBUF_LEN
];
...
...
@@ -750,7 +750,7 @@ void updateSlavesWaitingBgsave(int bgsaveerr, int type) {
listRewind
(
server
.
slaves
,
&
li
);
while
((
ln
=
listNext
(
&
li
)))
{
redisC
lient
*
slave
=
ln
->
value
;
c
lient
*
slave
=
ln
->
value
;
if
(
slave
->
replstate
==
REDIS_REPL_WAIT_BGSAVE_START
)
{
startbgsave
=
1
;
...
...
@@ -808,7 +808,7 @@ void updateSlavesWaitingBgsave(int bgsaveerr, int type) {
listRewind
(
server
.
slaves
,
&
li
);
serverLog
(
REDIS_WARNING
,
"SYNC failed. BGSAVE failed"
);
while
((
ln
=
listNext
(
&
li
)))
{
redisC
lient
*
slave
=
ln
->
value
;
c
lient
*
slave
=
ln
->
value
;
if
(
slave
->
replstate
==
REDIS_REPL_WAIT_BGSAVE_START
)
freeClient
(
slave
);
...
...
@@ -1477,7 +1477,7 @@ void replicationUnsetMaster(void) {
server
.
repl_state
=
REDIS_REPL_NONE
;
}
void
slaveofCommand
(
redisC
lient
*
c
)
{
void
slaveofCommand
(
c
lient
*
c
)
{
/* SLAVEOF is not allowed in cluster mode as replication is automatically
* configured using the current address of the master node. */
if
(
server
.
cluster_enabled
)
{
...
...
@@ -1518,7 +1518,7 @@ void slaveofCommand(redisClient *c) {
/* ROLE command: provide information about the role of the instance
* (master or slave) and additional information related to replication
* in an easy to process format. */
void
roleCommand
(
redisC
lient
*
c
)
{
void
roleCommand
(
c
lient
*
c
)
{
if
(
server
.
masterhost
==
NULL
)
{
listIter
li
;
listNode
*
ln
;
...
...
@@ -1531,7 +1531,7 @@ void roleCommand(redisClient *c) {
mbcount
=
addDeferredMultiBulkLength
(
c
);
listRewind
(
server
.
slaves
,
&
li
);
while
((
ln
=
listNext
(
&
li
)))
{
redisC
lient
*
slave
=
ln
->
value
;
c
lient
*
slave
=
ln
->
value
;
char
ip
[
REDIS_IP_STR_LEN
];
if
(
anetPeerToString
(
slave
->
fd
,
ip
,
sizeof
(
ip
),
NULL
)
==
-
1
)
continue
;
...
...
@@ -1568,7 +1568,7 @@ void roleCommand(redisClient *c) {
* processed offset. If we are not connected with a master, the command has
* no effects. */
void
replicationSendAck
(
void
)
{
redisC
lient
*
c
=
server
.
master
;
c
lient
*
c
=
server
.
master
;
if
(
c
!=
NULL
)
{
c
->
flags
|=
REDIS_MASTER_FORCE_REPLY
;
...
...
@@ -1600,7 +1600,7 @@ void replicationSendAck(void) {
* replicationResurrectCachedMaster() that is used after a successful PSYNC
* handshake in order to reactivate the cached master.
*/
void
replicationCacheMaster
(
redisC
lient
*
c
)
{
void
replicationCacheMaster
(
c
lient
*
c
)
{
listNode
*
ln
;
redisAssert
(
server
.
master
!=
NULL
&&
server
.
cached_master
==
NULL
);
...
...
@@ -1697,7 +1697,7 @@ void refreshGoodSlavesCount(void) {
listRewind
(
server
.
slaves
,
&
li
);
while
((
ln
=
listNext
(
&
li
)))
{
redisC
lient
*
slave
=
ln
->
value
;
c
lient
*
slave
=
ln
->
value
;
time_t
lag
=
server
.
unixtime
-
slave
->
repl_ack_time
;
if
(
slave
->
replstate
==
REDIS_REPL_ONLINE
&&
...
...
@@ -1833,7 +1833,7 @@ int replicationCountAcksByOffset(long long offset) {
listRewind
(
server
.
slaves
,
&
li
);
while
((
ln
=
listNext
(
&
li
)))
{
redisC
lient
*
slave
=
ln
->
value
;
c
lient
*
slave
=
ln
->
value
;
if
(
slave
->
replstate
!=
REDIS_REPL_ONLINE
)
continue
;
if
(
slave
->
repl_ack_off
>=
offset
)
count
++
;
...
...
@@ -1843,7 +1843,7 @@ int replicationCountAcksByOffset(long long offset) {
/* WAIT for N replicas to acknowledge the processing of our latest
* write command (and all the previous commands). */
void
waitCommand
(
redisC
lient
*
c
)
{
void
waitCommand
(
c
lient
*
c
)
{
mstime_t
timeout
;
long
numreplicas
,
ackreplicas
;
long
long
offset
=
c
->
woff
;
...
...
@@ -1878,7 +1878,7 @@ void waitCommand(redisClient *c) {
* specific cleanup. We just remove the client from the list of clients
* waiting for replica acks. Never call it directly, call unblockClient()
* instead. */
void
unblockClientWaitingReplicas
(
redisC
lient
*
c
)
{
void
unblockClientWaitingReplicas
(
c
lient
*
c
)
{
listNode
*
ln
=
listSearchKey
(
server
.
clients_waiting_acks
,
c
);
redisAssert
(
ln
!=
NULL
);
listDelNode
(
server
.
clients_waiting_acks
,
ln
);
...
...
@@ -1895,7 +1895,7 @@ void processClientsWaitingReplicas(void) {
listRewind
(
server
.
clients_waiting_acks
,
&
li
);
while
((
ln
=
listNext
(
&
li
)))
{
redisC
lient
*
c
=
ln
->
value
;
c
lient
*
c
=
ln
->
value
;
/* Every time we find a client that is satisfied for a given
* offset and number of replicas, we remember it so the next client
...
...
@@ -2005,7 +2005,7 @@ void replicationCron(void) {
* last-io timer preventing a timeout. */
listRewind
(
server
.
slaves
,
&
li
);
while
((
ln
=
listNext
(
&
li
)))
{
redisC
lient
*
slave
=
ln
->
value
;
c
lient
*
slave
=
ln
->
value
;
if
(
slave
->
replstate
==
REDIS_REPL_WAIT_BGSAVE_START
||
(
slave
->
replstate
==
REDIS_REPL_WAIT_BGSAVE_END
&&
...
...
@@ -2025,7 +2025,7 @@ void replicationCron(void) {
listRewind
(
server
.
slaves
,
&
li
);
while
((
ln
=
listNext
(
&
li
)))
{
redisC
lient
*
slave
=
ln
->
value
;
c
lient
*
slave
=
ln
->
value
;
if
(
slave
->
replstate
!=
REDIS_REPL_ONLINE
)
continue
;
if
(
slave
->
flags
&
REDIS_PRE_PSYNC
)
continue
;
...
...
@@ -2079,7 +2079,7 @@ void replicationCron(void) {
listRewind
(
server
.
slaves
,
&
li
);
while
((
ln
=
listNext
(
&
li
)))
{
redisC
lient
*
slave
=
ln
->
value
;
c
lient
*
slave
=
ln
->
value
;
if
(
slave
->
replstate
==
REDIS_REPL_WAIT_BGSAVE_START
)
{
idle
=
server
.
unixtime
-
slave
->
lastinteraction
;
if
(
idle
>
max_idle
)
max_idle
=
idle
;
...
...
@@ -2098,7 +2098,7 @@ void replicationCron(void) {
* startBgsaveForReplication(). */
listRewind
(
server
.
slaves
,
&
li
);
while
((
ln
=
listNext
(
&
li
)))
{
redisC
lient
*
slave
=
ln
->
value
;
c
lient
*
slave
=
ln
->
value
;
if
(
slave
->
replstate
==
REDIS_REPL_WAIT_BGSAVE_START
)
slave
->
replstate
=
REDIS_REPL_WAIT_BGSAVE_END
;
}
...
...
src/scripting.c
View file @
554bd0e7
...
...
@@ -206,7 +206,7 @@ void luaSortArray(lua_State *lua) {
int
luaRedisGenericCommand
(
lua_State
*
lua
,
int
raise_error
)
{
int
j
,
argc
=
lua_gettop
(
lua
);
struct
redisCommand
*
cmd
;
redisC
lient
*
c
=
server
.
lua_client
;
c
lient
*
c
=
server
.
lua_client
;
sds
reply
;
/* Cached across calls. */
...
...
@@ -798,7 +798,7 @@ void sha1hex(char *digest, char *script, size_t len) {
digest
[
40
]
=
'\0'
;
}
void
luaReplyToRedisReply
(
redisC
lient
*
c
,
lua_State
*
lua
)
{
void
luaReplyToRedisReply
(
c
lient
*
c
,
lua_State
*
lua
)
{
int
t
=
lua_type
(
lua
,
-
1
);
switch
(
t
)
{
...
...
@@ -884,7 +884,7 @@ void luaSetGlobalArray(lua_State *lua, char *var, robj **elev, int elec) {
* On success REDIS_OK is returned, and nothing is left on the Lua stack.
* On error REDIS_ERR is returned and an appropriate error is set in the
* client context. */
int
luaCreateFunction
(
redisC
lient
*
c
,
lua_State
*
lua
,
char
*
funcname
,
robj
*
body
)
{
int
luaCreateFunction
(
c
lient
*
c
,
lua_State
*
lua
,
char
*
funcname
,
robj
*
body
)
{
sds
funcdef
=
sdsempty
();
funcdef
=
sdscat
(
funcdef
,
"function "
);
...
...
@@ -920,7 +920,7 @@ int luaCreateFunction(redisClient *c, lua_State *lua, char *funcname, robj *body
return
REDIS_OK
;
}
void
evalGenericCommand
(
redisC
lient
*
c
,
int
evalsha
)
{
void
evalGenericCommand
(
c
lient
*
c
,
int
evalsha
)
{
lua_State
*
lua
=
server
.
lua
;
char
funcname
[
43
];
long
long
numkeys
;
...
...
@@ -1090,11 +1090,11 @@ void evalGenericCommand(redisClient *c, int evalsha) {
}
}
void
evalCommand
(
redisC
lient
*
c
)
{
void
evalCommand
(
c
lient
*
c
)
{
evalGenericCommand
(
c
,
0
);
}
void
evalShaCommand
(
redisC
lient
*
c
)
{
void
evalShaCommand
(
c
lient
*
c
)
{
if
(
sdslen
(
c
->
argv
[
1
]
->
ptr
)
!=
40
)
{
/* We know that a match is not possible if the provided SHA is
* not the right length. So we return an error ASAP, this way
...
...
@@ -1149,7 +1149,7 @@ int redis_math_randomseed (lua_State *L) {
* SCRIPT command for script environment introspection and control
* ------------------------------------------------------------------------- */
void
scriptCommand
(
redisC
lient
*
c
)
{
void
scriptCommand
(
c
lient
*
c
)
{
if
(
c
->
argc
==
2
&&
!
strcasecmp
(
c
->
argv
[
1
]
->
ptr
,
"flush"
))
{
scriptingReset
();
addReply
(
c
,
shared
.
ok
);
...
...
src/sentinel.c
View file @
554bd0e7
...
...
@@ -416,11 +416,11 @@ dictType leaderVotesDictType = {
/* =========================== Initialization =============================== */
void
sentinelCommand
(
redisC
lient
*
c
);
void
sentinelInfoCommand
(
redisC
lient
*
c
);
void
sentinelSetCommand
(
redisC
lient
*
c
);
void
sentinelPublishCommand
(
redisC
lient
*
c
);
void
sentinelRoleCommand
(
redisC
lient
*
c
);
void
sentinelCommand
(
c
lient
*
c
);
void
sentinelInfoCommand
(
c
lient
*
c
);
void
sentinelSetCommand
(
c
lient
*
c
);
void
sentinelPublishCommand
(
c
lient
*
c
);
void
sentinelRoleCommand
(
c
lient
*
c
);
struct
redisCommand
sentinelcmds
[]
=
{
{
"ping"
,
pingCommand
,
1
,
""
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
},
...
...
@@ -859,7 +859,7 @@ void sentinelKillTimedoutScripts(void) {
}
/* Implements SENTINEL PENDING-SCRIPTS command. */
void
sentinelPendingScriptsCommand
(
redisC
lient
*
c
)
{
void
sentinelPendingScriptsCommand
(
c
lient
*
c
)
{
listNode
*
ln
;
listIter
li
;
...
...
@@ -2604,7 +2604,7 @@ const char *sentinelFailoverStateStr(int state) {
}
/* Redis instance to Redis protocol representation. */
void
addReplySentinelRedisInstance
(
redisC
lient
*
c
,
sentinelRedisInstance
*
ri
)
{
void
addReplySentinelRedisInstance
(
c
lient
*
c
,
sentinelRedisInstance
*
ri
)
{
char
*
flags
=
sdsempty
();
void
*
mbl
;
int
fields
=
0
;
...
...
@@ -2795,7 +2795,7 @@ void addReplySentinelRedisInstance(redisClient *c, sentinelRedisInstance *ri) {
/* Output a number of instances contained inside a dictionary as
* Redis protocol. */
void
addReplyDictOfRedisInstances
(
redisC
lient
*
c
,
dict
*
instances
)
{
void
addReplyDictOfRedisInstances
(
c
lient
*
c
,
dict
*
instances
)
{
dictIterator
*
di
;
dictEntry
*
de
;
...
...
@@ -2812,7 +2812,7 @@ void addReplyDictOfRedisInstances(redisClient *c, dict *instances) {
/* Lookup the named master into sentinel.masters.
* If the master is not found reply to the client with an error and returns
* NULL. */
sentinelRedisInstance
*
sentinelGetMasterByNameOrReplyError
(
redisC
lient
*
c
,
sentinelRedisInstance
*
sentinelGetMasterByNameOrReplyError
(
c
lient
*
c
,
robj
*
name
)
{
sentinelRedisInstance
*
ri
;
...
...
@@ -2850,7 +2850,7 @@ int sentinelIsQuorumReachable(sentinelRedisInstance *master, int *usableptr) {
return
result
;
}
void
sentinelCommand
(
redisC
lient
*
c
)
{
void
sentinelCommand
(
c
lient
*
c
)
{
if
(
!
strcasecmp
(
c
->
argv
[
1
]
->
ptr
,
"masters"
))
{
/* SENTINEL MASTERS */
if
(
c
->
argc
!=
2
)
goto
numargserr
;
...
...
@@ -3166,7 +3166,7 @@ numargserr:
}
/* SENTINEL INFO [section] */
void
sentinelInfoCommand
(
redisC
lient
*
c
)
{
void
sentinelInfoCommand
(
c
lient
*
c
)
{
if
(
c
->
argc
>
2
)
{
addReply
(
c
,
shared
.
syntaxerr
);
return
;
...
...
@@ -3232,7 +3232,7 @@ void sentinelInfoCommand(redisClient *c) {
/* Implements Sentinel verison of the ROLE command. The output is
* "sentinel" and the list of currently monitored master names. */
void
sentinelRoleCommand
(
redisC
lient
*
c
)
{
void
sentinelRoleCommand
(
c
lient
*
c
)
{
dictIterator
*
di
;
dictEntry
*
de
;
...
...
@@ -3250,7 +3250,7 @@ void sentinelRoleCommand(redisClient *c) {
}
/* SENTINEL SET <mastername> [<option> <value> ...] */
void
sentinelSetCommand
(
redisC
lient
*
c
)
{
void
sentinelSetCommand
(
c
lient
*
c
)
{
sentinelRedisInstance
*
ri
;
int
j
,
changes
=
0
;
char
*
option
,
*
value
;
...
...
@@ -3343,7 +3343,7 @@ badfmt: /* Bad format errors */
*
* Because we have a Sentinel PUBLISH, the code to send hello messages is the same
* for all the three kind of instances: masters, slaves, sentinels. */
void
sentinelPublishCommand
(
redisC
lient
*
c
)
{
void
sentinelPublishCommand
(
c
lient
*
c
)
{
if
(
strcmp
(
c
->
argv
[
1
]
->
ptr
,
SENTINEL_HELLO_CHANNEL
))
{
addReplyError
(
c
,
"Only HELLO messages are accepted by Sentinel instances."
);
return
;
...
...
src/server.c
View file @
554bd0e7
...
...
@@ -915,7 +915,7 @@ long long getInstantaneousMetric(int metric) {
* The function gets the current time in milliseconds as argument since
* it gets called multiple times in a loop, so calling gettimeofday() for
* each iteration would be costly without any actual gain. */
int
clientsCronHandleTimeout
(
redisC
lient
*
c
,
mstime_t
now_ms
)
{
int
clientsCronHandleTimeout
(
c
lient
*
c
,
mstime_t
now_ms
)
{
time_t
now
=
now_ms
/
1000
;
if
(
server
.
maxidletime
&&
...
...
@@ -951,7 +951,7 @@ int clientsCronHandleTimeout(redisClient *c, mstime_t now_ms) {
* free space not used, this function reclaims space if needed.
*
* The function always returns 0 as it never terminates the client. */
int
clientsCronResizeQueryBuffer
(
redisC
lient
*
c
)
{
int
clientsCronResizeQueryBuffer
(
c
lient
*
c
)
{
size_t
querybuf_size
=
sdsAllocSize
(
c
->
querybuf
);
time_t
idletime
=
server
.
unixtime
-
c
->
lastinteraction
;
...
...
@@ -991,7 +991,7 @@ void clientsCron(void) {
numclients
:
CLIENTS_CRON_MIN_ITERATIONS
;
while
(
listLength
(
server
.
clients
)
&&
iterations
--
)
{
redisC
lient
*
c
;
c
lient
*
c
;
listNode
*
head
;
/* Rotate the list, take the current head, process.
...
...
@@ -2071,7 +2071,7 @@ void alsoPropagate(struct redisCommand *cmd, int dbid, robj **argv, int argc,
/* It is possible to call the function forceCommandPropagation() inside a
* Redis command implementation in order to to force the propagation of a
* specific command execution into AOF / Replication. */
void
forceCommandPropagation
(
redisC
lient
*
c
,
int
flags
)
{
void
forceCommandPropagation
(
c
lient
*
c
,
int
flags
)
{
if
(
flags
&
REDIS_PROPAGATE_REPL
)
c
->
flags
|=
REDIS_FORCE_REPL
;
if
(
flags
&
REDIS_PROPAGATE_AOF
)
c
->
flags
|=
REDIS_FORCE_AOF
;
}
...
...
@@ -2079,12 +2079,12 @@ void forceCommandPropagation(redisClient *c, int flags) {
/* Avoid that the executed command is propagated at all. This way we
* are free to just propagate what we want using the alsoPropagate()
* API. */
void
preventCommandPropagation
(
redisC
lient
*
c
)
{
void
preventCommandPropagation
(
c
lient
*
c
)
{
c
->
flags
|=
REDIS_PREVENT_PROP
;
}
/* Call() is the core of Redis execution of a command */
void
call
(
redisC
lient
*
c
,
int
flags
)
{
void
call
(
c
lient
*
c
,
int
flags
)
{
long
long
dirty
,
start
,
duration
;
int
client_old_flags
=
c
->
flags
;
...
...
@@ -2179,7 +2179,7 @@ void call(redisClient *c, int flags) {
* If 1 is returned the client is still alive and valid and
* other operations can be performed by the caller. Otherwise
* if 0 is returned the client was destroyed (i.e. after QUIT). */
int
processCommand
(
redisC
lient
*
c
)
{
int
processCommand
(
c
lient
*
c
)
{
/* The QUIT command is handled separately. Normal command procs will
* go through checking for replication and QUIT will cause trouble
* when FORCE_REPLICATION is enabled and would be implemented in
...
...
@@ -2476,7 +2476,7 @@ int time_independent_strcmp(char *a, char *b) {
return
diff
;
/* If zero strings are the same. */
}
void
authCommand
(
redisC
lient
*
c
)
{
void
authCommand
(
c
lient
*
c
)
{
if
(
!
server
.
requirepass
)
{
addReplyError
(
c
,
"Client sent AUTH, but no password is set"
);
}
else
if
(
!
time_independent_strcmp
(
c
->
argv
[
1
]
->
ptr
,
server
.
requirepass
))
{
...
...
@@ -2490,7 +2490,7 @@ void authCommand(redisClient *c) {
/* The PING command. It works in a different way if the client is in
* in Pub/Sub mode. */
void
pingCommand
(
redisC
lient
*
c
)
{
void
pingCommand
(
c
lient
*
c
)
{
/* The command takes zero or one arguments. */
if
(
c
->
argc
>
2
)
{
addReplyErrorFormat
(
c
,
"wrong number of arguments for '%s' command"
,
...
...
@@ -2513,11 +2513,11 @@ void pingCommand(redisClient *c) {
}
}
void
echoCommand
(
redisC
lient
*
c
)
{
void
echoCommand
(
c
lient
*
c
)
{
addReplyBulk
(
c
,
c
->
argv
[
1
]);
}
void
timeCommand
(
redisC
lient
*
c
)
{
void
timeCommand
(
c
lient
*
c
)
{
struct
timeval
tv
;
/* gettimeofday() can only fail if &tv is a bad address so we
...
...
@@ -2529,7 +2529,7 @@ void timeCommand(redisClient *c) {
}
/* Helper function for addReplyCommand() to output flags. */
int
addReplyCommandFlag
(
redisC
lient
*
c
,
struct
redisCommand
*
cmd
,
int
f
,
char
*
reply
)
{
int
addReplyCommandFlag
(
c
lient
*
c
,
struct
redisCommand
*
cmd
,
int
f
,
char
*
reply
)
{
if
(
cmd
->
flags
&
f
)
{
addReplyStatus
(
c
,
reply
);
return
1
;
...
...
@@ -2538,7 +2538,7 @@ int addReplyCommandFlag(redisClient *c, struct redisCommand *cmd, int f, char *r
}
/* Output the representation of a Redis command. Used by the COMMAND command. */
void
addReplyCommand
(
redisC
lient
*
c
,
struct
redisCommand
*
cmd
)
{
void
addReplyCommand
(
c
lient
*
c
,
struct
redisCommand
*
cmd
)
{
if
(
!
cmd
)
{
addReply
(
c
,
shared
.
nullbulk
);
}
else
{
...
...
@@ -2575,7 +2575,7 @@ void addReplyCommand(redisClient *c, struct redisCommand *cmd) {
}
/* COMMAND <subcommand> <args> */
void
commandCommand
(
redisC
lient
*
c
)
{
void
commandCommand
(
c
lient
*
c
)
{
dictIterator
*
di
;
dictEntry
*
de
;
...
...
@@ -3010,7 +3010,7 @@ sds genRedisInfoString(char *section) {
listRewind
(
server
.
slaves
,
&
li
);
while
((
ln
=
listNext
(
&
li
)))
{
redisC
lient
*
slave
=
listNodeValue
(
ln
);
c
lient
*
slave
=
listNodeValue
(
ln
);
char
*
state
=
NULL
;
char
ip
[
REDIS_IP_STR_LEN
];
int
port
;
...
...
@@ -3113,7 +3113,7 @@ sds genRedisInfoString(char *section) {
return
info
;
}
void
infoCommand
(
redisC
lient
*
c
)
{
void
infoCommand
(
c
lient
*
c
)
{
char
*
section
=
c
->
argc
==
2
?
c
->
argv
[
1
]
->
ptr
:
"default"
;
if
(
c
->
argc
>
2
)
{
...
...
@@ -3123,7 +3123,7 @@ void infoCommand(redisClient *c) {
addReplyBulkSds
(
c
,
genRedisInfoString
(
section
));
}
void
monitorCommand
(
redisC
lient
*
c
)
{
void
monitorCommand
(
c
lient
*
c
)
{
/* ignore MONITOR if already slave or in monitor mode */
if
(
c
->
flags
&
REDIS_SLAVE
)
return
;
...
...
@@ -3274,7 +3274,7 @@ int freeMemoryIfNeeded(void) {
listRewind
(
server
.
slaves
,
&
li
);
while
((
ln
=
listNext
(
&
li
)))
{
redisC
lient
*
slave
=
listNodeValue
(
ln
);
c
lient
*
slave
=
listNodeValue
(
ln
);
unsigned
long
obuf_bytes
=
getClientOutputBufferMemoryUsage
(
slave
);
if
(
obuf_bytes
>
mem_used
)
mem_used
=
0
;
...
...
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