Package redis.clients.jedis

Examples of redis.clients.jedis.Transaction


                        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


            String val = j.get(redisKey);
            if (val != null) {
                j.unwatch();
                return false;
            }
            Transaction tr = j.multi();

            //sentinel expired. kick off new RevisibleProcessor job
            tr.set(redisKey, "Y");
            tr.expire(redisKey, exp); //expire after exp seconds
            // since we have called watch, tr.exec will return null in the case that someone else has modified
            // the redisKey since we started our transaction.  If it doesn't return null, the value hasn't changed out from
            // under us, so we return true since we set it
            List<Object> resp = tr.exec();
            return resp != null;
        } catch (JedisException e) {
            brokenJedis = true;
            throw e;
        } finally {
View Full Code Here

            }
        }

        jedis = pool.getResource();
        try {
            Transaction transaction = jedis.multi();

            byte[] object = RedisSerializationUtil.encode((Serializable) value);
            transaction.set(attributeKey.getBytes(RedisSessionKeys.getEncoding()), object);
            transaction.expireAt(attributeKey.getBytes(RedisSessionKeys.getEncoding()), getUnixTime(currentExpireAtTimeWithReserve));

            transaction.sadd(attrsListKey, name);
            transaction.expireAt(attrsListKey, getUnixTime(currentExpireAtTimeWithReserve));

            transaction.exec();

            pool.returnResource(jedis);
        } catch (Throwable e) {
            pool.returnBrokenResource(jedis);
            throw new RuntimeException(e);
View Full Code Here

            message = new String(Base64Util.encode(bytes));
        }

        jedis = pool.getResource();
        try {
            Transaction transaction = jedis.multi();

            transaction.del(attributeKey.getBytes(RedisSessionKeys.getEncoding()));

            transaction.srem(attrsListKey, name);

            if (!disableListeners) {
                transaction.publish(RedisSessionKeys.getSessionChannel(), message);
            }

            transaction.exec();

            pool.returnResource(jedis);
        } catch (Throwable e) {
            pool.returnBrokenResource(jedis);
            throw new RuntimeException(e);
View Full Code Here

        long expireAtTime = currentTime + (maxInactiveInterval * 1000);
        long expireAtTimeWithReserve = currentTime + (maxInactiveInterval * 1000 * 2);

        Jedis jedis = pool.getResource();
        try {
            Transaction transaction = jedis.multi();

            transaction.set(creationTimeKey, Long.toString(currentTime));
            transaction.set(lastAccessTimeKey, Long.toString(currentTime));
            transaction.set(expiresAtKey, Long.toString(expireAtTimeWithReserve));
            transaction.set(timeoutKey, Integer.toString(maxInactiveInterval));

            transaction.expireAt(creationTimeKey, getUnixTime(expireAtTimeWithReserve));
            transaction.expireAt(lastAccessTimeKey, getUnixTime(expireAtTime));
            transaction.expireAt(expiresAtKey, getUnixTime(expireAtTimeWithReserve));
            transaction.expireAt(timeoutKey, getUnixTime(expireAtTimeWithReserve));

            transaction.zadd(sessionsKey, currentTime, id);

            transaction.exec();

            pool.returnResource(jedis);
        } catch (Throwable e) {
            pool.returnBrokenResource(jedis);
            throw new RuntimeException(e);
View Full Code Here

        long lastAccessTime = getLastAccessedTime();

        Jedis jedis = pool.getResource();
        try {
            Transaction transaction = jedis.multi();

            transaction.rename(oldCreationTimeKey, newCreationTimeKey);
            transaction.rename(oldLastAccessTimeKey, newLastAccessTimeKey);
            transaction.rename(oldExpiresAtKey, newExpiresAtKey);
            transaction.rename(oldTimeoutKey, newTimeoutKey);

            if (attributeNames != null && !attributeNames.isEmpty()) {
                for (String attributeName : attributeNames) {
                    String oldKey = RedisSessionKeys.getAttrKey(this.id, attributeName);
                    String newKey = RedisSessionKeys.getAttrKey(id, attributeName);
                    transaction.rename(oldKey, newKey);
                }

                transaction.rename(oldAttrsKey, newAttrsKey);
            } else {
                transaction.del(oldAttrsKey);
            }

            transaction.zadd(RedisSessionKeys.getSessionsKey(), lastAccessTime, id);
            transaction.zrem(RedisSessionKeys.getSessionsKey(), this.id);

            transaction.exec();

            pool.returnResource(jedis);
        } catch (Throwable e) {
            pool.returnBrokenResource(jedis);
            throw new RuntimeException(e);
View Full Code Here

            attributeNames = getAttributesNames();
        }

        Jedis jedis = pool.getResource();
        try {
            Transaction transaction = jedis.multi();

            if (currentExpireAtTime < expireAtTime) {
                transaction.set(expiresAtKey, Long.toString(expireAtTimeWithReserve));
                transaction.expireAt(expiresAtKey, getUnixTime(expireAtTimeWithReserve));

                transaction.expireAt(creationTimeKey, getUnixTime(expireAtTimeWithReserve));
                transaction.expireAt(timeoutKey, getUnixTime(expireAtTimeWithReserve));

                if (attributeNames != null && !attributeNames.isEmpty()) {
                    for (String attributeName : attributeNames) {
                        String key = RedisSessionKeys.getAttrKey(id, attributeName);
                        transaction.expireAt(key, getUnixTime(expireAtTimeWithReserve));
                    }

                    transaction.expireAt(attrsKey, getUnixTime(expireAtTimeWithReserve));
                }
            }

            transaction.set(lastAccessTimeKey, Long.toString(currentTime));
            transaction.expireAt(lastAccessTimeKey, getUnixTime(expireAtTime));

            transaction.zadd(RedisSessionKeys.getSessionsKey(), currentTime, id);

            transaction.exec();

            pool.returnResource(jedis);
        } catch (Throwable e) {
            pool.returnBrokenResource(jedis);
            throw new RuntimeException(e);
View Full Code Here

        Set<String> attributeNames = getAttributesNames();

        Jedis jedis = pool.getResource();
        try {
            Transaction transaction = jedis.multi();

            transaction.del(creationTimeKey, lastAccessTimeKey, expiresAtKey, timeoutKey, attrsKey);

            if (!attributeNames.isEmpty()) {
                Set<String> keys = new HashSet<String>();
                for (String attributeName : attributeNames) {
                    String key = RedisSessionKeys.getAttrKey(id, attributeName);
                    keys.add(key);
                }

                //noinspection ToArrayCallWithZeroLengthArrayArgument
                transaction.del(keys.toArray(new String[]{}));
            }

            if (!disableListeners) {
                RedisSessionEvent redisSessionEvent = new RedisSessionDestroyedEvent(id);
                byte[] bytes = RedisSerializationUtil.encode(redisSessionEvent);
                String message = new String(Base64Util.encode(bytes));

                transaction.publish(RedisSessionKeys.getSessionChannel(), message);
            }

            transaction.exec();

            pool.returnResource(jedis);
        } catch (Throwable e) {
            pool.returnBrokenResource(jedis);
            throw new RuntimeException(e);
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.