Package redis.clients.jedis

Examples of redis.clients.jedis.Transaction


            if (!conn.sismember(inventory, itemId)){
                conn.unwatch();
                return false;
            }

            Transaction trans = conn.multi();
            trans.zadd("market:", price, item);
            trans.srem(inventory, itemId);
            List<Object> results = trans.exec();
            // null response indicates that the transaction was aborted due to
            // the watched key changing.
            if (results == null){
                continue;
            }
View Full Code Here


            if (price != lprice || price > funds){
                conn.unwatch();
                return false;
            }

            Transaction trans = conn.multi();
            trans.hincrBy(seller, "funds", (int)price);
            trans.hincrBy(buyer, "funds", (int)-price);
            trans.sadd(inventory, itemId);
            trans.zrem("market:", item);
            List<Object> results = trans.exec();
            // null response indicates that the transaction was aborted due to
            // the watched key changing.
            if (results == null){
                continue;
            }
View Full Code Here

     */
    private List<Object> runWithTx(final JedisTransactionalCallback callback) {

        Jedis jedis = jedisPool.getResource();
        try {
            Transaction tx = jedis.multi();
            callback.execute(tx);
            return tx.exec();
        } finally {
            jedisPool.returnResource(jedis);
        }
    }
View Full Code Here

            final String chid = channel.getChannelId();
            if (jedis.sismember(uaidLookupKey(uaid), chid)) {
                return false;
            }
            final String endpointToken = channel.getEndpointToken();
            final Transaction tx = jedis.multi();
            tx.set(endpointToken, Long.toString(channel.getVersion()));
            tx.set(tokenLookupKey(endpointToken), chid);
            tx.hmset(chidLookupKey(chid), mapOf(endpointToken, uaid));
            tx.sadd(uaidLookupKey(uaid), chid);
            tx.exec();
            return true;
        } finally {
            jedisPool.returnResource(jedis);
        }
    }
View Full Code Here

    private void removeChannel(final String channelId) {
        final Jedis jedis = jedisPool.getResource();
        try {
            final Channel channel = getChannel(channelId);
            final String endpointToken = channel.getEndpointToken();
            final Transaction tx = jedis.multi();
            tx.del(endpointToken);
            tx.del(chidLookupKey(channelId));
            tx.del(tokenLookupKey(endpointToken));
            tx.srem(uaidLookupKey(channel.getUAID()), channelId);
            tx.exec();
        } catch (final ChannelNotFoundException e) {
            logger.debug("ChannelId [" + channelId + "] was not found");
        } finally {
            jedisPool.returnResource(jedis);
        }
View Full Code Here

            }
            final long currentVersion = Long.valueOf(versionString);
            if (newVersion <= currentVersion) {
                throw new VersionException("version [" + newVersion + "] must be greater than the current version [" + currentVersion + "]");
            }
            final Transaction tx = jedis.multi();
            tx.set(endpointToken, String.valueOf(newVersion));
            tx.exec();
            logger.debug(tokenLookupKey(endpointToken));
            return jedis.get(tokenLookupKey(endpointToken));
        } finally {
            jedisPool.returnResource(jedis);
        }
View Full Code Here

            if (val == null) {
                this.jedis.unwatch();
                result = val;
                break;
            }
            final Transaction tx = this.jedis.multi();
            tx.lpop(from);
            tx.lpush(to, val);
            if (tx.exec() != null) {
                result = val;
                break;
            }
            // If execution of the transaction failed, this means that 'from'
            // was modified while we were watching it and the transaction was
View Full Code Here

        return isTransactionInProgress;
    }

    Transaction bindResource(Jedis resource)
    {
        Transaction tx = null;
        // Multi not supported.
       
      /*if (resources.isEmpty())
        {*/
            tx = resource.multi();
View Full Code Here

   */
  public JedisConnection(Jedis jedis, Pool<Jedis> pool, int dbIndex) {
    this.jedis = jedis;
    // extract underlying connection for batch operations
    client = (Client) ReflectionUtils.getField(CLIENT_FIELD, jedis);
    transaction = new Transaction(client);

    this.pool = pool;

    this.dbIndex = dbIndex;

View Full Code Here

             j.unwatch();
             throw new SetFailedException();
           }
         }
       }
       Transaction tr = j.multi();
       if (state == null) {
         tr.hdel(queueUrl + "-" + shard + "-" + CQSConstants.REDIS_STATE, CQSConstants.REDIS_STATE);
       } else {
         tr.hset(queueUrl + "-" + shard + "-" + CQSConstants.REDIS_STATE, CQSConstants.REDIS_STATE, state.name());
       }
       List<Object> resp = tr.exec();
       if (resp == null) {
         throw new SetFailedException();
       }
     } catch(JedisException e) {
       brokenJedis = true;
View Full Code Here

TOP

Related Classes of redis.clients.jedis.Transaction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.