Jmeter as a very popular interface testing and performance testing tool, is very widely used in the enterprise, and Redis as a cache database, is also widely used in the enterprise, how to use Jmeter to test the Redis database? Today we will talk about how to use JMeter to call Redis.

Jmeter to prepare

Since JMeter itself does not have a Redis test portal, we need to install the Redis plug-in.

First, we downloaded the jmeter-plugins-manager-1.6.jar file, placed it in the Ext folder in jMeter’s lib, and then restarted JMeter.

Then, under the ‘Options’ menu, click on’ Plugin Manager ‘, open the Plugin Manager popup, select ‘Available Plugins’, and enter Redis in the search box

Then, select ‘Redis Data Set’ and click ‘Apply Changes and Restart JMeter’

Restart JMeter with automatic download.

Then, right-click on the JMeter thread group and add > Configure Components > jp@gc – Redis Data Set

At this point, you are ready to connect to the Redis database through jMeter configuration. If you already have a Redis database, you can configure it directly in the current interface. If you do not have a Redis database, you need to install the Redis database.

Install the Redis database

There are many ways to install Redis database, the use of docker installation, may be the simplest, I will use docker to install Redis database.

Docker run - itd - name jmeter redis \ - p - 6779-6379 \ daocloud. IO/library/redis: 3.2.8 - alpine redis - server - appendonly yesCopy the code

Ok, now that you have the Redis database, it’s time to insert some data into the database.

Docker execit jmeter-redis /bin/sh Connect to Redis redis- CLI # Insert list data lpush course jmeter, loadRuner lpush course WRK, AB lpush course locust,ngrinderCopy the code

So now we have a list of course in the Redis database, and we can get its data in JMeter.

Jmeter uses Redis data

Configure the relevant information in the RedisDataSet

  • Data Configuration

  • Redis key: the key in Redis, the name of a list (ordered data) or set (unordered data) in a Redis database

  • Variable Names: The Names of the variables exported from the dataset to the test element (to set which Variable the fetched value is stored in)

  • Delimiter: Delimiter used in rows stored in a Redis list or collection (Delimiter between variable names if the fetched value has multiple values)

  • Date Sources Type: indicates the data source Type. The options are List and Set

  • Recycle Data on Flase: Indicates whether data is reused

  • Connection Configuration

  • Redis server host: indicates the IP address of the Redis server

  • Redis Server port: indicates the Redis service port

  • Timeout for connect in MS: indicates the connection Timeout period. The default value is 2000 ms

  • Password for Connection: Password for connecting to Redis

  • Database: the name of the Database to which Redis is connected. The default value is 0

  • Redis Pool Configuration

field

usage

The default value

minIdle

At least how many instances of Redis are idle

0

maxIdle

The maximum number of idle Redis instances in a thread pool

10

maxActive

Controls how many Redis instances can be allocated to a pool, using pool.getResource(). If the value is -1, there is no limit; If a pool has already allocated maxActive jedis instances, the pool is in a exhausted state

20

maxWait

Represents the maximum wait time when borrow an instance of Redis. If the wait time is exceeded, JedisConnectionException is thrown directly

30000

whenExhaustedAction

Allocated Redis the operation to be taken when all Redis instances in the pool are allocated. There are three default types of when_hausted_fail (when no Redis instance is present, NoSuchElementException is thrown directly), when_hausted_block (when when_hausted_block, When maxWait is reached, JedisConnectionException is thrown), when_hausted_grow (when ex. hausted_grow = new jedis instance, maxActive is useless)

GROW

testOnBorrow

Whether the Alidate operation was performed in advance when a Redis instance was borrowed; If true, the resulting Redis instances are all available

False

testOnReturn

Whether validate is performed before a return to the pool

False

testWhileIdle

If true, an idle object evitor thread scans idle objects. If validate fails, the object will be dropped from the pool. This item is only meaningful when timeBetweenEvictionRunsMillis is greater than zero

False

timeBetweenEvictionRunsMillis

Indicates the number of milliseconds to sleep between idle Object evitor scans

30000

numTestsPerEvictionRun

Indicates the maximum number of objects scanned by the Idle Object Evitor at a time

0

minEvictableIdleTimeMillis

Indicates the minimum time for an object to stay in idle state before it can be scanned and expelled by idle Object evitor. This item is only meaningful when timeBetweenEvictionRunsMillis is greater than zero

60000

softMinEvictableIdleTimeMillis

On the basis of minEvictableIdleTimeMillis, joined at least minIdle object has been in the pool. If it is -1, Evicted does not expel any objects based on idle time. If minEvictableIdleTimeMillis > 0, then this setting meaningless, and only makes sense when timeBetweenEvictionRunsMillis is greater than zero

60000

Next we add the debug sampler, referring to the Redis variable name in the name. The thread group loop is then set multiple times.

run

We see that we have the Redis data.

Jmeter writes data to Redis

Above, we have talked about how to obtain the data in Redis database? Next, we will show you how to write data to the Redis database.

First, we download jedis JAR package, put the downloaded package into jMeter lib folder, restart JMeter

Then, in JMeter, add a new thread group and add ‘jSR223 Sampler’

  import redis.clients.jedis.Jedis;

Jedis jedis = new Jedis("81.69.228.171", 6679);
jedis.set("foo","bar");
String value = jedis.get("foo");
Copy the code

Run the script

It is confirmed from Redis database that the data has been stored.

How to write and retrieve data from JMeter?