import redis from 'k6/experimental/redis';
const redis_addrs = __ENV.REDIS_ADDRS || '';
const redis_password = __ENV.REDIS_PASSWORD || '';
const redisClient = new redis.Client({
addrs: redis_addrs.split(',') || new Array('localhost:6379'),
password: redis_password,
});
export default function () {
redisClient
.rpush('mylist', 'first')
.then((_) => redisClient.rpush('mylist', 'second'))
.then((_) => redisClient.rpush('mylist', 'first'))
.then((_) => redisClient.rpush('mylist', 'second'))
.then((_) => redisClient.lrem('mylist', 0, 'second'))
.then((_) => redisClient.lrem('mylist', 1, 'first'))
.then((length) => {
if (length !== 1) {
throw new Error('lrem operations should have left 1 item behind');
}
return redisClient.lpop('mylist');
});
}