Ok, fair warning, I'm using scala...
Basically the problem occurs when I try to pop more items off a list
than the list contains. My code has different behavior depending on
how many items are on a list, for just a few items I get them one at a
time, if there are more than 200 items on the list then I use a
pipeline to get at least 200 items at a time. The problem happens
when I know that there are at least 200 items in the list but I
pipeline more commands than there are items in the list - I expect a
response of nil for each extra pop after the list is empty, instead I
get an error. If there are 200 items on the list and I pop 200 items
off then everything works. If I know there are at least 200, let's
say there are 201 items on the list for this example, but I ask for
say 205 items (I pipeline 205 pop's) then I get an error.
Working code looks like this (try to get 200 items when we know there
are at least 200):
// get a db connection
val jedis = redisClientConnCore.getResource()
// get the length of the pending list
val numTrans = jedis.llen("trans:1").intValue
// if there are lots of items on the list then get lots of items at
once
if (numTrans >= 200) {
val j = jedis.pipelined()
for (x <- 1 to 200) {
// get a key from the transaction list, move it to the pending
list
j.rpoplpush("trans:1", "trans:2")
}
val results = j.syncAndReturnAll()
}
// return db connection to pool
redisClientConnCore.returnResource(jedis)
Broken code looks like this (try to get 300 items when we know there
are at least 200):
// get a db connection
val jedis = redisClientConnCore.getResource()
// get the length of the pending list
val numTrans = jedis.llen("trans:1").intValue
// if there are lots of items on the list then get lots of items at
once
if (numTrans >= 200) {
val j = jedis.pipelined()
for (x <- 1 to 300) {
// get a key from the transaction list, move it to the pending
list
j.rpoplpush("trans:1", "trans:2")
}
val results = j.syncAndReturnAll()
}
// return db connection to pool
redisClientConnCore.returnResource(jedis)
Hope that helps. Thanks for taking a look.
Regards,
Steve Boyle