Created
April 14, 2015 12:51
-
-
Save bobmeliev/7e9e659c9f44d647aefa to your computer and use it in GitHub Desktop.
JMeter Redis Beanshell script
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 java.util.ArrayList; | |
import java.util.List; | |
import redis.clients.jedis.Jedis; | |
import redis.clients.jedis.JedisPool; | |
import redis.clients.jedis.JedisPoolConfig; | |
import redis.clients.jedis.Protocol; | |
// Connect to Redis server | |
String redisHost = vars.get("redis.host"); | |
JedisPoolConfig config = new JedisPoolConfig(); | |
JedisPool pool = new JedisPool(config, redisHost); | |
Jedis jedis = null; | |
jedis = pool.getResource(); | |
System.out.println("Redis running... " + jedis.ping()); | |
//Methods to work with Redis keys | |
redisGetRandomSetsByList(List keysList) { | |
/* | |
Method to retrieve SETS by LIST. Returns keys listed in LIST. | |
*/ | |
for(int i=0; i<keysList.size(); i++) { | |
vars.put("R_"+keysList.get(i), jedis.srandmember(keysList.get(i))); | |
System.out.println("Keys: " + keysList.get(i) + "equal to " + jedis.srandmember(keysList.get(i))); | |
} | |
} | |
redisGetRandomSetsByPrefix(String keyPrefix) { | |
/* | |
Method to retrieve key values by prefix. Returns all keys matching prefix. | |
*/ | |
Set list = jedis.keys(keyPrefix + "*"); | |
Object[] listArray = list.toArray(); | |
for (int i=0; i<listArray.length; i++) { | |
vars.put("R_"+listArray[i], jedis.srandmember(listArray[i])); | |
System.out.println("Keys: " + listArray[i]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good job!