question about nil handling

377 views
Skip to first unread message

SBoyle

unread,
Jul 1, 2011, 2:10:48 PM7/1/11
to Jedis
I'm using Jedis 2.0.0. In the redis command line client, if I do an
rpoplpush list1 list2 and list 1 happens to be empty then the redis
command line client returns a (nil) response. When I do that same
thing in a pipeline through Jedis then Jedis throws the following
error:
[ERROR] [2011-07-01 11:00:43,166] [akka:event-
driven:dispatcher:event:handler-17] a.e.s.Slf4jEventHandler:
[akka.actor.LocalActorRef]
[GetCSETransactions()]
[java.lang.NullPointerException
at java.lang.String.<init>(String.java:515)
at redis.clients.util.SafeEncoder.encode(SafeEncoder.java:28)
at redis.clients.jedis.BuilderFactory$5.build(BuilderFactory.java:55)
at redis.clients.jedis.BuilderFactory$5.build(BuilderFactory.java:58)
at redis.clients.jedis.Response.get(Response.java:27)
at redis.clients.jedis.Pipeline.syncAndReturnAll(Pipeline.java:42)
at CCMRedisActor.getCSETransactions(CCMActorRedis.scala:358)

Either I'm doing something wrong or perhaps Jedis is not handling the
response correctly. Any ideas?

Thank you in advance.

Jonathan Leibiusky

unread,
Jul 6, 2011, 5:32:51 PM7/6/11
to jedis...@googlegroups.com
Hi! probably it is bug in Jedis where it is not handling the response correctly. Can you post a small piece of code that reproduces this so I can test it and fix it?

thanks!

SBoyle

unread,
Jul 7, 2011, 6:13:33 PM7/7/11
to Jedis
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
Reply all
Reply to author
Forward
0 new messages