Created
September 1, 2014 07:43
-
-
Save honux77/9cc407e34118dfd36d60 to your computer and use it in GitHub Desktop.
Jedis Sample Test code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import redis.clients.jedis.Jedis; | |
| public class Test { | |
| private static long time; | |
| private static Jedis jedis = new Jedis("localhost"); | |
| public static void main(String[] args) { | |
| /* | |
| jedis.set("hoyoung", "tired"); | |
| String str = jedis.get("hoyoung"); | |
| System.out.println(str); | |
| */ | |
| int count = 50000; | |
| insertTest(count); | |
| searchTest(count); | |
| jedis.close(); | |
| } | |
| public static void printProgress(int current, int total) { | |
| if (current == 0) { | |
| time = System.currentTimeMillis(); | |
| System.out.println("Start"); | |
| } | |
| else if ( current * 10 % total == 0) | |
| System.out.print("*"); | |
| else if (current == (total - 1)) { | |
| time = System.currentTimeMillis() - time; | |
| System.out.printf("\nFinished. Time: %d QPS: %d\n", time, total * 1000 / (time+1)); | |
| } | |
| } | |
| public static void insertTest(int count) { | |
| for(int i = 0; i < count ; i++) { | |
| jedis.set(i+"", i+""); | |
| printProgress(i, count); | |
| } | |
| } | |
| public static void searchTest(int count) { | |
| for(int i = 0; i < count ; i++) { | |
| String str = jedis.get(i+""); | |
| printProgress(i, count); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment