-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.ml
158 lines (127 loc) · 5.23 KB
/
test.ml
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
(* This file is part of memcache-ocaml.
*
* memcache-ocaml is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* memcache-ocaml is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with memcache-ocaml. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2010 Alexander Markov *)
(* Usage: make test && ./test *)
open Lwt
let string_of_reply = function
| Memcache.STORED -> "STORED"
| Memcache.NOT_STORED -> "NOT_STORED"
| Memcache.EXISTS -> "EXISTS"
| Memcache.NOT_FOUND -> "NOT_FOUND"
let host = "localhost"
let port = 11211
let t =
Printf.printf "open_connection: %s:%d\n" host port;
Memcache.open_connection host port >>= fun cache ->
print_string "version: ";
Memcache.version cache >>= fun version ->
print_endline version;
print_string "flush_all:";
Memcache.flush_all cache >>= fun () ->
print_endline " ok";
print_endline "getsh: foo foo01";
Memcache.getsh cache ["foo"; "foo01"] >>= fun reply ->
Hashtbl.iter (fun name ((flags, unique), value) ->
Printf.printf " answer: %s (%d, %Ld) = %s\n" name flags unique value) reply;
print_endline "set: foo = bar";
Memcache.set cache "foo" "bar" >>= fun reply ->
print_endline (" answer: " ^ (string_of_reply reply));
print_endline "get: foo";
Memcache.get cache "foo" >>= fun reply ->
print_string " answer: ";
(match reply with
| Some (name, (flags, value)) ->
Printf.printf "%s (%d) = %s\n" name flags value
| None -> print_endline "None");
print_endline "add: foo = bar";
Memcache.add cache "foo" "bar" >>= fun reply ->
print_endline (" answer: " ^ (string_of_reply reply));
print_endline "geth: foo foo01";
Memcache.geth cache ["foo"; "foo01"] >>= fun reply ->
Hashtbl.iter (fun name (flags, value) ->
Printf.printf " answer: %s (%d) = %s\n" name flags value) reply;
print_endline "delete: foo";
Memcache.delete cache "foo" >>= fun reply ->
print_endline (" answer: " ^ (string_of_bool reply));
print_endline "set: foo01 = 1";
Memcache.set cache "foo01" "1" >>= fun reply ->
print_endline (" answer: " ^ (string_of_reply reply));
print_endline "incr64: foo01 2L";
Memcache.incr64 cache "foo01" 2L >>= fun reply ->
print_string " answer: ";
(match reply with
| Some value ->
Printf.printf "%Ld\n" value
| None -> print_endline "None");
print_endline "decr64: foo01 1L";
Memcache.decr64 cache "foo01" 1L >>= fun reply ->
print_string " answer: ";
(match reply with
| Some value ->
Printf.printf "%Ld\n" value
| None -> print_endline "None");
print_endline "incr: foo01 1";
Memcache.incr cache "foo01" "1" >>= fun reply ->
print_string " answer: ";
(match reply with
| Some value ->
Printf.printf "%s\n" value
| None -> print_endline "None");
print_endline "decr: foo01 1";
Memcache.decr cache "foo01" "1" >>= fun reply ->
print_string " answer: ";
(match reply with
| Some value ->
Printf.printf "%s\n" value
| None -> print_endline "None");
print_endline "getl: foo foo01";
Memcache.getl cache ["foo"; "foo01"] >>= fun l ->
List.iter (fun (name, (flags, value)) ->
Printf.printf " answer: %s (%d) = %s\n" name flags value) l;
print_endline "add: foo = bar";
Memcache.add cache "foo" "bar" >>= fun reply ->
print_endline (" answer: " ^ (string_of_reply reply));
print_endline "prepend: foo _";
Memcache.prepend cache "foo" "_" >>= fun reply ->
print_endline (" answer: " ^ (string_of_reply reply));
print_endline "append: foo _";
Memcache.append cache "foo" "_" >>= fun reply ->
print_endline (" answer: " ^ (string_of_reply reply));
print_endline "gets: foo";
Memcache.gets cache "foo" >>= fun resp ->
match resp with
| None -> print_endline "TEST FAILED!"; exit 1;
| Some (name, ((flags, unique), value)) ->
Printf.printf " answer: %s (%d, %Ld) = %s\n"
name flags unique value;
Printf.printf "cas: foo %Ld 'replaced by cas'\n" unique;
Memcache.cas cache "foo" unique "replaced by cas" >>= fun reply ->
print_endline (" answer: " ^ (string_of_reply reply));
print_endline "replace: foo = baz";
Memcache.replace cache "foo" "baz" >>= fun reply ->
print_endline (" answer: " ^ (string_of_reply reply));
print_endline "getsl: foo foo01";
Memcache.getsl cache ["foo"; "foo01"] >>= fun l ->
List.iter (fun (name, ((flags, unique), value)) ->
Printf.printf " answer: %s (%d, %Ld) = %s\n" name flags unique value) l;
Printf.printf "cas: foo %Ld 'replaced by cas'\n" unique;
Memcache.cas cache "foo" unique "replaced by cas" >>= fun reply ->
print_endline (" answer: " ^ (string_of_reply reply));
print_string "close_connection:";
Memcache.close_connection cache >>= fun () ->
print_endline " ok";
exit 0
let _ = Lwt_main.run t