Posted by Colin Howe on Mon 27 Apr 18:09
report abuse | download | new post
- import java.util.Random;
- import org.jredis.JRedis;
- import org.jredis.RedisException;
- import org.jredis.ri.alphazero.JRedisClient;
- public class Redis {
- private static final int THREAD_COUNT = 2;
- private static final int SETS_PER_THREAD = 100;
- private static final int RANDOM_GETS_PER_THREAD = 500;
- public static void main(String[] args) throws InstantiationException, IllegalAccessException, ClassNotFoundException, InterruptedException {
- benchmarkSets();
- benchmarkGets();
- }
- /**
- * Benchmark the desired number of sets across the specified number of threads.
- *
- * @throws InterruptedException
- */
- // -- Create the threads to do the writing...
- //
- for (int i = 0; i < THREAD_COUNT; i++) {
- }
- // -- Start all the threads...
- //
- for (int i = 0; i < THREAD_COUNT; i++) {
- writeThreads[i].start();
- }
- // -- Wait for all the threads to finish...
- //
- for (int i = 0; i < THREAD_COUNT; i++) {
- writeThreads[i].join();
- }
- }
- /**
- * Benchmark the desired number of gets across the specified number of threads.
- *
- * @throws InterruptedException
- */
- // -- Create the threads to do the GETTING...
- //
- for (int i = 0; i < THREAD_COUNT; i++) {
- }
- // -- Start all the threads...
- //
- for (int i = 0; i < THREAD_COUNT; i++) {
- getThreads[i].start();
- }
- // -- Wait for all the threads to finish...
- //
- for (int i = 0; i < THREAD_COUNT; i++) {
- getThreads[i].join();
- }
- }
- /**
- * Thread that handles the writing of X items to the database.
- */
- private JRedis jredis = null;
- this.keyPrefix = keyPrefix;
- // -- Connect to the Redis server...
- //
- try {
- jredis = new JRedisClient("localhost", 6379);
- e.printStackTrace();
- }
- }
- /**
- * @see java.lang.Thread#run()
- */
- @Override
- public void run() {
- try {
- // Perform the desired number of sets
- for (int i = 0; i < SETS_PER_THREAD; i++) {
- }
- // Close the connection
- jredis.quit();
- } catch (RedisException e) {
- e.printStackTrace();
- }
- }
- }
- /**
- * Thread that handles the getting of X random items from Redis.
- */
- private JRedis jredis = null;
- this.keyPrefix = keyPrefix;
- // -- Connect to the Redis server...
- //
- try {
- jredis = new JRedisClient("localhost", 6379);
- e.printStackTrace();
- }
- }
- /**
- * @see java.lang.Thread#run()
- */
- @Override
- public void run() {
- try {
- // Perform the desired number of gets and verify the value is correct
- for (int i = 0; i < RANDOM_GETS_PER_THREAD; i++) {
- int keyNum = rand.nextInt(SETS_PER_THREAD);
- }
- // Close the connection
- jredis.quit();
- } catch (RedisException e) {
- e.printStackTrace();
- }
- }
- }
- }
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.