/
slabtest
executable file
·82 lines (67 loc) · 1.63 KB
/
slabtest
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/perl
use strict;
use warnings;
use IO::Socket::INET;
require './util.pl';
$host = shift | 'localhost:11211';
if ($com eq 'set') {
$byte = shift;
$items = shift || 1;
$counter = shift || 1;
die "SET: $0 set <byte> [items] [counter] [host]\n" unless $byte && ($items > 0);
}
elsif ($com eq 'del') {
$classid = shift;
$items = shift || 1;
die "DEL: $0 del <class_id> [items] [host]\n" unless $classid && ($items > 0);
}
$addr = shift || "localhost:11211";
my $sock = IO::Socket::INET->new(PeerAddr => $addr,
Proto => 'tcp');
die "Could not connect to $addr\n" unless $sock;
my $key_prefix = 'k';
if ($com eq 'flush_all') {
print $sock $com;
print "Complete!: (Command)$com\n";
exit;
}
elsif ($com eq 'set') {
my $key;
# my $keynum = &find_largest_key;
my $value = "a" x $byte;
for my $n (1..$items) {
$counter++;
# $key = ($key_prefix).($keynum);
$key = ($key_prefix).($counter);
print $sock "$com $key 0 0 $byte\r\n$value\r\n";
#print "$com $key 0 0 $byte\r\n$value\r\n";
while (<$sock>) {
last if (/^STORED/);
# die "$_" unless (/^STORED/);
}
# $keynum++;
}
print "Complete!: (Command)$com (Byte)$byte (Items)$items (SendTo)$addr\n";
exit;
}
elsif ($com eq 'del') {
my @keys;
print $sock "stats cachedump $classid $items\r\n";
my $i = 0;
while (<$sock>) {
last if /^END/;
if (/^ITEM (\S+)/) {
$keys[$i] = $1;
}
$i++;
}
foreach my $key (@keys) {
print $sock "delete $key\r\n";
while (<$sock>) {
last if /^DELETED/;
}
}
print "Complete!: (Command)$com (ClassID)$classid (Items)$items\n";
exit;
}
__END__