List of usage examples for org.springframework.data.redis.connection RedisConnection sRandMember
@Nullable List<byte[]> sRandMember(byte[] key, long count);
From source file:com.mauersu.util.redis.DefaultSetOperations.java
public List<V> randomMembers(K key, final long count) { if (count < 0) { throw new IllegalArgumentException( "Use a positive number for count. " + "This method is already allowing duplicate elements."); }//from w w w . jav a2s . c o m final byte[] rawKey = rawKey(key); List<byte[]> rawValues = execute(new RedisCallback<List<byte[]>>() { public List<byte[]> doInRedis(RedisConnection connection) { connection.select(dbIndex); return connection.sRandMember(rawKey, -count); } }, true); return deserializeValues(rawValues); }
From source file:com.mauersu.util.redis.DefaultSetOperations.java
public Set<V> distinctRandomMembers(K key, final long count) { if (count < 0) { throw new IllegalArgumentException( "Negative count not supported. " + "Use randomMembers to allow duplicate elements."); }//from w w w . j av a 2 s . c om final byte[] rawKey = rawKey(key); Set<byte[]> rawValues = execute(new RedisCallback<Set<byte[]>>() { public Set<byte[]> doInRedis(RedisConnection connection) { connection.select(dbIndex); return new HashSet<byte[]>(connection.sRandMember(rawKey, count)); } }, true); return deserializeValues(rawValues); }
From source file:com.zxy.commons.cache.RedisUtils.java
/** * Get {@code count} random elements from set at {@code key}. * <p>//from w w w.j a v a2s . c o m * See http://redis.io/commands/srandmember * * @param key key * @param count count * @return List<byte[]> */ public static List<byte[]> sRandMember(byte[] key, long count) { return redisTemplate.execute(new RedisCallback<List<byte[]>>() { @Override public List<byte[]> doInRedis(RedisConnection redis) throws DataAccessException { return redis.sRandMember(key, count); } }); }
From source file:com.zxy.commons.cache.RedisHelper.java
/** * Get {@code count} random elements from set at {@code key}. * <p>//from w w w .j ava 2s. co m * See http://redis.io/commands/srandmember * * @param key key * @param count count * @return List<byte[]> */ public List<byte[]> sRandMember(byte[] key, long count) { return redisTemplate.execute(new RedisCallback<List<byte[]>>() { @Override public List<byte[]> doInRedis(RedisConnection redis) throws DataAccessException { return redis.sRandMember(key, count); } }); }