shell方式telnet方式lua方式java方式压力测试redis

redis-benchmark执行99999999个命令测试

redis-benchmark  -h 192.168.199.190  -p 6382     -n 99999999

redis-benchmark选取88888888个随机数作为key,执行99999999个set或者lpush命令测试,并发为10

redis-benchmark -h 192.168.199.190	 -p 6382 -t set,lpush   -r 88888888 -n 99999999 -c 10

redis-benchmark选取88888888个随机数作为key,永久执行set或者lpush命令测试,并发为100

redis-benchmark -h 192.168.199.190	 -p 6382 -t set,lpush   -r 88888888 -l -c 100

redis-benchmark执行lua脚本

redis-benchmark  -h 192.168.199.190  -p 6382  -n 1000000 -q script load "redis.call('set','foo','bar')"

shell循环执行命令

for i in  {1..10};
do
echo -en "bar" | redis-cli -h 132.122.237.68  -p 6379 -a 123456 -x set foo$i
done
for i in  {1..10};
do
echo -en "bar" | redis-cli -h 192.168.199.192  -p 6379  -x set foo$i
done

命令行执行lua脚本

redis-cli -h 132.122.237.68 -p 6379 -a 123456 --eval redis.lua

其中redis.lua内容

for i=0,10,1  do   redis.call('set','helloworld'..i,'helloworld')   end

java执行lua脚本:

jedis jedis = new Jedis("192.168.199.192",6379);		
jedis.auth("123456"); 	
String script =" for i=0,10,1  do   redis.call('set','helloworld'..i,'helloworld')   end jedis.eval(script,0); 
jedis.close();

telnet和expect方式

/usr/bin/expect<<-EOF
set timeout -1
spawn telnet 132.122.237.68  6379
expect  "*Escape character is*"
send "auth 123456\r"
while {1} {
expect  "+OK"
send "set foo bar\r"
}
expect  "+OK"
send "quit\r"
interact
exit
EOF
/usr/bin/expect<<-EOF
set timeout -1
spawn telnet 192.168.199.192  6379
expect  "*Escape character is*"
while {1} {
send "set foo bar\r"
expect  "OK"
}
expect  "OK"
send "quit\r"
interact
exit
EOF

tcp/telnet方式

public class ReadInputStreamUtil{

	public static String read(InputStream inputStream, String suffix) {
		try {
			char lastChar = suffix.charAt(suffix.length() - 1);
			StringBuffer sb = new StringBuffer();
			char c = (char) inputStream.read();
			while (true) {				
				sb.append(c);
				if (c == lastChar && sb.toString().endsWith(suffix)) {
					return sb.toString();					 
				}
				c = (char) inputStream.read();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	public static void main(String[] args) throws Exception {

		/*
		TelnetClient telnetClient = new TelnetClient();
		telnetClient.connect("132.122.237.68", 6379);		
		InputStream inputStream = telnetClient.getInputStream();
		OutputStream outputStream = telnetClient.getOutputStream();
		*/
		
		Socket socket = new Socket("132.122.237.68", 6379);		
		InputStream inputStream = socket.getInputStream();
		OutputStream outputStream = socket.getOutputStream();

		 
		outputStream.write("auth 123456\r\n".getBytes());
		outputStream.flush();
		System.out.println(read(inputStream, "\r\n"));
 
		for (int i = 0; i < 10; i++) {
			outputStream.write(("set foo" + i + " bar\r\n").getBytes());
			outputStream.flush();
		    System.out.println("set返回结果="+read(inputStream, "\r\n"));
		  
		    outputStream.write(("get foo" + i + "\n").getBytes());
			outputStream.flush();
			System.out.println("get返回字节数="+read(inputStream, "\r\n"));
			System.out.println("get返回结果="+read(inputStream, "\r\n"));		    
		}
		outputStream.close();
		inputStream.close();

	}

}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值