List of usage examples for org.springframework.data.redis.core RedisOperations opsForSet
SetOperations<K, V> opsForSet();
From source file:com.mauersu.util.redis.DefaultBoundSetOperations.java
/** * Constructs a new <code>DefaultBoundSetOperations</code> instance. * // w w w .j a va 2s . c om * @param key * @param operations */ DefaultBoundSetOperations(K key, RedisOperations<K, V> operations) { super(key, operations); this.ops = operations.opsForSet(); }
From source file:com.company.project.service.dao.RedisDao.java
/** * 4.9. Redis Transactions - http://docs.spring.io/spring-data/redis/docs/current/reference/html/ * Add value to set. Utilize Session Callback * @param key//from w w w . ja v a 2 s .c o m * @param value * @return */ public long addUsingOpsForSetUsingSesssionCallback(final String key, final Object value) { //execute a transaction List<Object> txResults = redisTemplate.execute(new SessionCallback<List<Object>>() { @Override public List<Object> execute(RedisOperations operations) throws DataAccessException { operations.multi(); operations.opsForSet().add(key, value); // This will contain the results of all ops in the transaction return operations.exec(); } }); if (txResults != null && !txResults.isEmpty()) { System.out.println("Number of items added to set: " + txResults.get(0)); try { int itemsAdded = Integer.parseInt("" + txResults.get(0)); return itemsAdded; } catch (NumberFormatException nfe) { nfe.printStackTrace(); } } return 0; }