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();
}
}