Search in sources :

Example 6 with JedisException

use of redis.clients.jedis.exceptions.JedisException in project cachecloud by sohutv.

the class JedisPool method returnResource.

@Override
protected void returnResource(final Jedis resource) {
    if (resource != null) {
        try {
            resource.resetState();
            returnResourceObject(resource);
        } catch (Exception e) {
            returnBrokenResource(resource);
            throw new JedisException("Could not return the resource to the pool", e);
        }
    }
}
Also used : JedisException(redis.clients.jedis.exceptions.JedisException) JedisException(redis.clients.jedis.exceptions.JedisException)

Example 7 with JedisException

use of redis.clients.jedis.exceptions.JedisException in project gitblit by gitblit.

the class RedisTicketService method getTicketImpl.

/**
	 * Retrieves the ticket from the repository.
	 *
	 * @param repository
	 * @param ticketId
	 * @return a ticket, if it exists, otherwise null
	 */
@Override
protected TicketModel getTicketImpl(RepositoryModel repository, long ticketId) {
    Jedis jedis = pool.getResource();
    if (jedis == null) {
        return null;
    }
    try {
        List<Change> changes = getJournal(jedis, repository, ticketId);
        if (ArrayUtils.isEmpty(changes)) {
            log.warn("Empty journal for {}:{}", repository, ticketId);
            return null;
        }
        TicketModel ticket = TicketModel.buildTicket(changes);
        ticket.project = repository.projectPath;
        ticket.repository = repository.name;
        ticket.number = ticketId;
        log.debug("rebuilt ticket {} from Redis @ {}", ticketId, getUrl());
        return ticket;
    } catch (JedisException e) {
        log.error("failed to retrieve ticket from Redis @ " + getUrl(), e);
        pool.returnBrokenResource(jedis);
        jedis = null;
    } finally {
        if (jedis != null) {
            pool.returnResource(jedis);
        }
    }
    return null;
}
Also used : Jedis(redis.clients.jedis.Jedis) JedisException(redis.clients.jedis.exceptions.JedisException) TicketModel(com.gitblit.models.TicketModel) Change(com.gitblit.models.TicketModel.Change)

Example 8 with JedisException

use of redis.clients.jedis.exceptions.JedisException in project gitblit by gitblit.

the class RedisTicketService method renameImpl.

@Override
protected boolean renameImpl(RepositoryModel oldRepository, RepositoryModel newRepository) {
    Jedis jedis = pool.getResource();
    if (jedis == null) {
        return false;
    }
    boolean success = false;
    try {
        Set<String> oldKeys = jedis.keys(oldRepository.name + ":*");
        Transaction t = jedis.multi();
        for (String oldKey : oldKeys) {
            String newKey = newRepository.name + oldKey.substring(oldKey.indexOf(':'));
            t.rename(oldKey, newKey);
        }
        t.exec();
        success = true;
    } catch (JedisException e) {
        log.error("failed to rename tickets in Redis @ " + getUrl(), e);
        pool.returnBrokenResource(jedis);
        jedis = null;
    } finally {
        if (jedis != null) {
            pool.returnResource(jedis);
        }
    }
    return success;
}
Also used : Jedis(redis.clients.jedis.Jedis) JedisException(redis.clients.jedis.exceptions.JedisException) Transaction(redis.clients.jedis.Transaction)

Example 9 with JedisException

use of redis.clients.jedis.exceptions.JedisException in project gitblit by gitblit.

the class RedisTicketService method assignNewId.

/**
	 * Assigns a new ticket id.
	 *
	 * @param repository
	 * @return a new long ticket id
	 */
@Override
public synchronized long assignNewId(RepositoryModel repository) {
    Jedis jedis = pool.getResource();
    try {
        String key = key(repository, KeyType.counter, null);
        String val = jedis.get(key);
        if (isNull(val)) {
            long lastId = 0;
            Set<Long> ids = getIds(repository);
            for (long id : ids) {
                if (id > lastId) {
                    lastId = id;
                }
            }
            jedis.set(key, "" + lastId);
        }
        long ticketNumber = jedis.incr(key);
        return ticketNumber;
    } catch (JedisException e) {
        log.error("failed to assign new ticket id in Redis @ " + getUrl(), e);
        pool.returnBrokenResource(jedis);
        jedis = null;
    } finally {
        if (jedis != null) {
            pool.returnResource(jedis);
        }
    }
    return 0L;
}
Also used : Jedis(redis.clients.jedis.Jedis) JedisException(redis.clients.jedis.exceptions.JedisException)

Example 10 with JedisException

use of redis.clients.jedis.exceptions.JedisException in project gitblit by gitblit.

the class RedisTicketService method getIds.

@Override
public Set<Long> getIds(RepositoryModel repository) {
    Set<Long> ids = new TreeSet<Long>();
    Jedis jedis = pool.getResource();
    try {
        // account for migrated tickets
        Set<String> keys = jedis.keys(key(repository, KeyType.journal, "*"));
        for (String tkey : keys) {
            // {repo}:journal:{id}
            String id = tkey.split(":")[2];
            long ticketId = Long.parseLong(id);
            ids.add(ticketId);
        }
    } catch (JedisException e) {
        log.error("failed to assign new ticket id in Redis @ " + getUrl(), e);
        pool.returnBrokenResource(jedis);
        jedis = null;
    } finally {
        if (jedis != null) {
            pool.returnResource(jedis);
        }
    }
    return ids;
}
Also used : Jedis(redis.clients.jedis.Jedis) JedisException(redis.clients.jedis.exceptions.JedisException) TreeSet(java.util.TreeSet)

Aggregations

JedisException (redis.clients.jedis.exceptions.JedisException)15 Jedis (redis.clients.jedis.Jedis)8 Transaction (redis.clients.jedis.Transaction)4 TicketModel (com.gitblit.models.TicketModel)3 Change (com.gitblit.models.TicketModel.Change)3 IdempotentConfirmer (com.sohu.cache.util.IdempotentConfirmer)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 TreeSet (java.util.TreeSet)1 GenericObjectPoolConfig (org.apache.commons.pool2.impl.GenericObjectPoolConfig)1 JedisPool (redis.clients.jedis.JedisPool)1