1. 程式人生 > >shell方式telnet方式lua方式java方式壓力測試redis

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

telnet和java方式

public class TelnetTest {

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

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

		TelnetClient tc = new TelnetClient();
		tc.setConnectTimeout(1000000000);
		tc.setDefaultTimeout(1000000000);

		tc.connect("132.122.237.68", 6379);
		tc.setSoTimeout(1000000000);
		InputStream in = tc.getInputStream();
		OutputStream os = tc.getOutputStream();

		os.write("auth 123456\r\n".getBytes());
		os.flush();
		System.out.println(read(in, "+OK"));

		for (int i = 0; i < 10; i++) {
			os.write(("set foo" + i + " bar\r\n").getBytes());
			os.flush();
			System.out.println(read(in, "+OK\r\n"));
		}
		os.close();
		in.close();

	}

}