java - Jedis Returning same value even though the lua script removes it -
i using jedis , jedis connection pooling in app. using redis sorted set collection store data. in app using lua script poping data (remove). lua script contains 5 6 commands. app in multithreaded 1 used akka actor , attached jedis pool it. each thread have own jedis instance. @ point jedis returns same data more 1 akka thread.
here code,
public class xoredissortedsetcache<t> extends xorediscollectioncache<t> { private static final string zpop = "local function zpop(tempkey) local val = redis.pcall('zrevrangebyscore', tempkey, 1, 0, 'withscores' , 'limit' , '0' , '1' ) if val redis.call('zrem', tempkey, val[1]) end return val end return zpop(keys[1])"; private static final byte[] zpop_bytes = zpop.getbytes(); private static final string zrandom_weighted_pop = "local function zrandomweightedpop(tempkey) local totalsize = redis.pcall('zcard', tempkey) if totalsize > 0 local maxscore = redis.pcall('zrevrange', tempkey, 0, 0, 'withscores') local minscore = redis.pcall('zrange', tempkey, 0, 0, 'withscores') local c = math.randomseed(redis.pcall('time')[1]) local randomindex = math.random(0, totalsize) local val = redis.pcall('zrangebyscore', tempkey, minscore[2], maxscore[2], 'withscores' , 'limit' , randomindex , 1) if val redis.pcall('zrem', tempkey, val[1]) end return val end end return zrandomweightedpop(keys[1])"; private static final byte[] zrandom_weighted_pop_bytes = zrandom_weighted_pop.getbytes(); final byte[] binclusiveb = { 0x5b, 0x0b }; final byte[] bexclusivec = { 0x28, 0x0c }; final byte[] blexminusinf = { 0x2d }; final byte[] blexplusinf = { 0x2b }; private static final jedispool jedis_pool = ((redisplugin)xoutil.getpluginbyclass(redisplugin.class)).jedispool(); private final serializer<t> serializer; private byte[] collectionname; private string namespace; private final random randomgenerator; private int maxthreshold; public xoredissortedsetcache(string namespace, string collectionname, class<t> persistentclass, int maxthreshold) { super(namespace, collectionname, persistentclass); randomgenerator = new random(); this.maxthreshold = maxthreshold; } public final t pop() { jedis jedis = null; t value = null; try{ int randscore = randomgenerator.nextint(100); collection<byte[]> valuebytes = null; byte[] valuebyte = null; jedis = jedis_pool.getresource(); if(randscore <= this.maxthreshold) { valuebytes = (collection<byte[]>) jedis.eval(zpop_bytes, 1, this.collectionname); } else { valuebytes = (collection<byte[]>) jedis.eval(zrandom_weighted_pop_bytes, 1, this.collectionname); } if(valuebytes != null && valuebytes.size() > 0) { valuebyte = valuebytes.iterator().next(); } if(valuebyte != null) { value = (t) this.deserialize(valuebyte); } } catch(exception e) { logger.error("error while popping value set.", e); } finally{ if(jedis != null) { jedis.close(); } } logger.info("poped value : " + value); return value; }
}
is because of lua script contains more commands? please give suggestion fix this.
here logs,
2015-07-23 18:39:04,159 - [info] - application in play-akka.actor.default-dispatcher-14
poped value : 1315406::2349091862155::n/a
2015-07-23 18:39:04,333 - [info] - application in play-akka.actor.default-dispatcher-12 poped value : 1315406::2349091862155::n/a
2015-07-23 18:39:04,560 - [info] - application in play-akka.actor.default-dispatcher-11 poped value : 1315406::2349091862155::n/a
2015-07-23 18:39:04,560 - [info] - application in play-akka.actor.default-dispatcher-16 poped value : 1315406::2349091862155::n/a
2015-07-23 18:39:04,888 - [info] - application in play-akka.actor.default-dispatcher-12 poped value : 1315406::2349091862155::n/a
2015-07-23 18:39:04,891 - [info] - application in play-akka.actor.default-dispatcher-11 poped value : 1315406::2349091862155::n/a
also please mention mistake have done here.
Comments
Post a Comment