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);
}
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
}
Aggregations