Search in sources :

Example 46 with Transaction

use of redis.clients.jedis.Transaction in project vertigo by KleeGroup.

the class RedisAccountCachePlugin method setPhoto.

/**
 * {@inheritDoc}
 */
@Override
public void setPhoto(final URI<Account> accountURI, final VFile photo) {
    Assertion.checkNotNull(accountURI);
    Assertion.checkNotNull(photo);
    // -----
    final Map<String, String> vFileMapPhoto = photoCodec.vFile2Map(photo);
    try (final Jedis jedis = redisConnector.getResource()) {
        try (final Transaction tx = jedis.multi()) {
            tx.hmset(HPHOTO_BY_ACCOUNT_START_KEY + accountURI.getId(), vFileMapPhoto);
            tx.exec();
        } catch (final IOException ex) {
            throw WrappedException.wrap(ex);
        }
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) Transaction(redis.clients.jedis.Transaction) IOException(java.io.IOException)

Example 47 with Transaction

use of redis.clients.jedis.Transaction in project vertigo by KleeGroup.

the class RedisAccountCachePlugin method putAccount.

/**
 * {@inheritDoc}
 */
@Override
public void putAccount(final Account account) {
    Assertion.checkNotNull(account);
    // -----
    try (final Jedis jedis = redisConnector.getResource()) {
        try (final Transaction tx = jedis.multi()) {
            tx.hmset(HACCOUNT_START_KEY + account.getId(), account2Map(account));
            tx.hset(HAUTHTOKEN_INDEX_KEY, account.getAuthToken(), account.getId());
            tx.sadd(SACCOUNTS_KEY, account.getId());
            tx.exec();
        } catch (final IOException ex) {
            throw WrappedException.wrap(ex);
        }
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) Transaction(redis.clients.jedis.Transaction) IOException(java.io.IOException)

Example 48 with Transaction

use of redis.clients.jedis.Transaction in project vertigo by KleeGroup.

the class RedisAccountCachePlugin method attach.

/*
	@Override
	public Collection<AccountGroup> getAllGroups() {
		final List<Response<Map<String, String>>> responses = new ArrayList<>();
		try (final Jedis jedis = redisConnector.getResource()) {
			final Set<String> ids = jedis.smembers(SACCOUNTS_KEY);
			try (final Transaction tx = jedis.multi()) {
				for (final String id : ids) {
					responses.add(tx.hgetAll(HACCOUNT_START_KEY + id));
				}
				tx.exec();
			} catch (final IOException ex) {
				throw WrappedException.wrap(ex);
			}
	
		}
		//----- we are using tx to avoid roundtrips
		final List<AccountGroup> groups = new ArrayList<>();
		for (final Response<Map<String, String>> response : responses) {
			final Map<String, String> data = response.get();
			if (!data.isEmpty()) {
				groups.add(map2Group(data));
			}
		}
		return groups;
	}*/
/**
 * {@inheritDoc}
 */
@Override
public void attach(final Set<URI<Account>> accountsURI, final URI<AccountGroup> groupURI) {
    Assertion.checkNotNull(accountsURI);
    Assertion.checkNotNull(groupURI);
    // -----
    try (final Jedis jedis = redisConnector.getResource()) {
        try (final Transaction tx = jedis.multi()) {
            for (final URI<Account> accountURI : accountsURI) {
                tx.sadd(SACCOUNTS_BY_GROUP_START_KEY + groupURI.getId(), accountURI.getId().toString());
                tx.sadd(SGROUPS_BY_ACCOUNT_START_KEY + accountURI.getId(), groupURI.getId().toString());
            }
            tx.exec();
        } catch (final IOException ex) {
            throw WrappedException.wrap(ex);
        }
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) Account(io.vertigo.account.account.Account) Transaction(redis.clients.jedis.Transaction) IOException(java.io.IOException)

Example 49 with Transaction

use of redis.clients.jedis.Transaction in project vertigo by KleeGroup.

the class RedisAccountCachePlugin method putGroup.

/**
 * {@inheritDoc}
 */
@Override
public void putGroup(final AccountGroup group) {
    Assertion.checkNotNull(group);
    // ----
    try (final Jedis jedis = redisConnector.getResource()) {
        try (final Transaction tx = jedis.multi()) {
            tx.hmset(HGROUP_START_KEY + group.getId(), group2Map(group));
            tx.sadd(SGROUPS_KEY, group.getId());
            tx.exec();
        } catch (final IOException ex) {
            throw WrappedException.wrap(ex);
        }
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) Transaction(redis.clients.jedis.Transaction) IOException(java.io.IOException)

Example 50 with Transaction

use of redis.clients.jedis.Transaction in project vertigo by KleeGroup.

the class RedisNodeRegistryPlugin method unregister.

@Override
public void unregister(final Node node) {
    try (final Jedis jedis = redisConnector.getResource()) {
        try (final Transaction tx = jedis.multi()) {
            tx.del(VERTIGO_NODE + node.getId());
            tx.srem(VERTIGO_NODES, node.getId());
            tx.exec();
        } catch (final IOException e) {
            throw WrappedException.wrap(e);
        }
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) Transaction(redis.clients.jedis.Transaction) IOException(java.io.IOException)

Aggregations

Transaction (redis.clients.jedis.Transaction)149 Test (org.junit.Test)90 Jedis (redis.clients.jedis.Jedis)57 JedisDataException (redis.clients.jedis.exceptions.JedisDataException)15 Set (java.util.Set)14 ArrayList (java.util.ArrayList)11 IOException (java.io.IOException)8 List (java.util.List)8 JedisConnectionException (redis.clients.jedis.exceptions.JedisConnectionException)7 GenericObjectPoolConfig (org.apache.commons.pool2.impl.GenericObjectPoolConfig)6 Protocol (redis.clients.jedis.Protocol)4 Response (redis.clients.jedis.Response)4 JedisException (redis.clients.jedis.exceptions.JedisException)4 Header (redis.clients.jedis.graph.Header)4 Record (redis.clients.jedis.graph.Record)4 ResultSet (redis.clients.jedis.graph.ResultSet)4 Node (redis.clients.jedis.graph.entities.Node)4 Property (redis.clients.jedis.graph.entities.Property)4 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3