Skip to content

Instantly share code, notes, and snippets.

@xetorthio
Last active August 29, 2015 13:56
Show Gist options
  • Save xetorthio/8807079 to your computer and use it in GitHub Desktop.
Save xetorthio/8807079 to your computer and use it in GitHub Desktop.
package lalala;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.SortingParams;
public class Test {
public static void main(String[] args) throws InterruptedException {
final JedisPool jedisPool = new JedisPool("localhost");
ExecutorService executor = Executors.newFixedThreadPool(10);
final AtomicBoolean ended = new AtomicBoolean(false);
for (int n = 0; n < 10; n++) {
executor.execute(new Runnable() {
@Override
public void run() {
while (!ended.get()) {
Jedis jedis = jedisPool.getResource();
SortingParams sortingParameters = new SortingParams();
String sortBy = "1:2:*->status";// assume key is 1:2:
String filterSetName = "1:2:jobIds";
sortingParameters.get("a", "b", "c");// assume that
// col1,
// col2, col3 are
// defined
sortingParameters.by(sortBy);
List<String> filteredAndsortedList = null;
try {
filteredAndsortedList = jedis.sort(filterSetName,
sortingParameters);
System.out.println("Thread "
+ Thread.currentThread().getName()
+ " - Sorted List size "
+ filteredAndsortedList.size());
for (String str : filteredAndsortedList) {
// System.out.println(str);
}
} catch (Exception e) {
System.out.println("-----Exception thrown-----");
System.out.println(e);
System.out.println(" returned value is "
+ filteredAndsortedList);
e.printStackTrace();
} finally {
jedisPool.returnResource(jedis);
}
}
}
});
}
Thread.sleep(10000);
ended.set(true);
executor.shutdown();
executor.awaitTermination(10, TimeUnit.SECONDS);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment