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
e3c51c4b
Commit
e3c51c4b
authored
Nov 09, 2010
by
Damian Janowski & Michel Martens
Committed by
Michel Martens
Nov 29, 2010
Browse files
Rename bstate to bpop.
parent
59bd44d1
Changes
3
Show whitespace changes
Inline
Side-by-side
src/networking.c
View file @
e3c51c4b
...
...
@@ -41,10 +41,10 @@ redisClient *createClient(int fd) {
c
->
reply
=
listCreate
();
listSetFreeMethod
(
c
->
reply
,
decrRefCount
);
listSetDupMethod
(
c
->
reply
,
dupClientReplyValue
);
c
->
b
state
.
keys
=
NULL
;
c
->
b
state
.
count
=
0
;
c
->
b
state
.
timeout
=
0
;
c
->
b
state
.
target
=
NULL
;
c
->
b
pop
.
keys
=
NULL
;
c
->
b
pop
.
count
=
0
;
c
->
b
pop
.
timeout
=
0
;
c
->
b
pop
.
target
=
NULL
;
c
->
io_keys
=
listCreate
();
c
->
watched_keys
=
listCreate
();
listSetFreeMethod
(
c
->
io_keys
,
decrRefCount
);
...
...
@@ -679,7 +679,7 @@ void closeTimedoutClients(void) {
redisLog
(
REDIS_VERBOSE
,
"Closing idle client"
);
freeClient
(
c
);
}
else
if
(
c
->
flags
&
REDIS_BLOCKED
)
{
if
(
c
->
b
state
.
timeout
!=
0
&&
c
->
b
state
.
timeout
<
now
)
{
if
(
c
->
b
pop
.
timeout
!=
0
&&
c
->
b
pop
.
timeout
<
now
)
{
addReply
(
c
,
shared
.
nullmultibulk
);
unblockClientWaitingData
(
c
);
}
...
...
src/redis.h
View file @
e3c51c4b
...
...
@@ -326,7 +326,7 @@ typedef struct redisClient {
long
repldboff
;
/* replication DB file offset */
off_t
repldbsize
;
/* replication DB file size */
multiState
mstate
;
/* MULTI/EXEC state */
blockingState
b
state
;
/* blocking state */
blockingState
b
pop
;
/* blocking state */
list
*
io_keys
;
/* Keys this client is waiting to be loaded from the
* swap file in order to continue. */
list
*
watched_keys
;
/* Keys WATCHED for MULTI/EXEC CAS */
...
...
src/t_list.c
View file @
e3c51c4b
...
...
@@ -694,10 +694,10 @@ void blockForKeys(redisClient *c, robj **keys, int numkeys, time_t timeout, robj
list
*
l
;
int
j
;
c
->
b
state
.
keys
=
zmalloc
(
sizeof
(
robj
*
)
*
numkeys
);
c
->
b
state
.
count
=
numkeys
;
c
->
b
state
.
timeout
=
timeout
;
c
->
b
state
.
target
=
target
;
c
->
b
pop
.
keys
=
zmalloc
(
sizeof
(
robj
*
)
*
numkeys
);
c
->
b
pop
.
count
=
numkeys
;
c
->
b
pop
.
timeout
=
timeout
;
c
->
b
pop
.
target
=
target
;
if
(
target
!=
NULL
)
{
incrRefCount
(
target
);
...
...
@@ -705,7 +705,7 @@ void blockForKeys(redisClient *c, robj **keys, int numkeys, time_t timeout, robj
for
(
j
=
0
;
j
<
numkeys
;
j
++
)
{
/* Add the key in the client structure, to map clients -> keys */
c
->
b
state
.
keys
[
j
]
=
keys
[
j
];
c
->
b
pop
.
keys
[
j
]
=
keys
[
j
];
incrRefCount
(
keys
[
j
]);
/* And in the other "side", to map keys -> clients */
...
...
@@ -734,28 +734,28 @@ void unblockClientWaitingData(redisClient *c) {
list
*
l
;
int
j
;
redisAssert
(
c
->
b
state
.
keys
!=
NULL
);
redisAssert
(
c
->
b
pop
.
keys
!=
NULL
);
/* The client may wait for multiple keys, so unblock it for every key. */
for
(
j
=
0
;
j
<
c
->
b
state
.
count
;
j
++
)
{
for
(
j
=
0
;
j
<
c
->
b
pop
.
count
;
j
++
)
{
/* Remove this client from the list of clients waiting for this key. */
de
=
dictFind
(
c
->
db
->
blocking_keys
,
c
->
b
state
.
keys
[
j
]);
de
=
dictFind
(
c
->
db
->
blocking_keys
,
c
->
b
pop
.
keys
[
j
]);
redisAssert
(
de
!=
NULL
);
l
=
dictGetEntryVal
(
de
);
listDelNode
(
l
,
listSearchKey
(
l
,
c
));
/* If the list is empty we need to remove it to avoid wasting memory */
if
(
listLength
(
l
)
==
0
)
dictDelete
(
c
->
db
->
blocking_keys
,
c
->
b
state
.
keys
[
j
]);
decrRefCount
(
c
->
b
state
.
keys
[
j
]);
dictDelete
(
c
->
db
->
blocking_keys
,
c
->
b
pop
.
keys
[
j
]);
decrRefCount
(
c
->
b
pop
.
keys
[
j
]);
}
if
(
c
->
b
state
.
target
!=
NULL
)
{
decrRefCount
(
c
->
b
state
.
target
);
if
(
c
->
b
pop
.
target
!=
NULL
)
{
decrRefCount
(
c
->
b
pop
.
target
);
}
/* Cleanup the client structure */
zfree
(
c
->
b
state
.
keys
);
c
->
b
state
.
keys
=
NULL
;
c
->
b
state
.
target
=
NULL
;
zfree
(
c
->
b
pop
.
keys
);
c
->
b
pop
.
keys
=
NULL
;
c
->
b
pop
.
target
=
NULL
;
c
->
flags
&=
(
~
REDIS_BLOCKED
);
server
.
blpop_blocked_clients
--
;
/* We want to process data if there is some command waiting
...
...
@@ -789,7 +789,7 @@ int handleClientsWaitingListPush(redisClient *c, robj *key, robj *ele) {
redisAssert
(
ln
!=
NULL
);
receiver
=
ln
->
value
;
if
(
receiver
->
b
state
.
target
==
NULL
)
{
if
(
receiver
->
b
pop
.
target
==
NULL
)
{
/* BRPOP/BLPOP return a multi-bulk with the name
* of the popped list */
addReplyMultiBulkLen
(
receiver
,
2
);
...
...
@@ -798,16 +798,16 @@ int handleClientsWaitingListPush(redisClient *c, robj *key, robj *ele) {
}
else
{
/* BRPOPLPUSH */
robj
*
dobj
=
lookupKeyWrite
(
receiver
->
db
,
receiver
->
b
state
.
target
);
robj
*
dobj
=
lookupKeyWrite
(
receiver
->
db
,
receiver
->
b
pop
.
target
);
if
(
dobj
&&
checkType
(
receiver
,
dobj
,
REDIS_LIST
))
return
0
;
addReplyBulk
(
receiver
,
ele
);
if
(
!
handleClientsWaitingListPush
(
receiver
,
receiver
->
b
state
.
target
,
ele
))
{
if
(
!
handleClientsWaitingListPush
(
receiver
,
receiver
->
b
pop
.
target
,
ele
))
{
/* Create the list if the key does not exist */
if
(
!
dobj
)
{
dobj
=
createZiplistObject
();
dbAdd
(
receiver
->
db
,
receiver
->
b
state
.
target
,
dobj
);
dbAdd
(
receiver
->
db
,
receiver
->
b
pop
.
target
,
dobj
);
}
listTypePush
(
dobj
,
ele
,
REDIS_HEAD
);
...
...
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