Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge remote branch 'wagerlabs/unified_request_protocol' into wagerla…

…bs-unified_request_protocol

Conflicts:
	src/redis.ml
	tests/smoke_test.ml
  • Loading branch information...
commit 16b921c5cd3bc26103571f0fe0dfce6e796f06b4 2 parents f453ffe + 8fffe1f
@rgeoghegan authored
View
38 Makefile
@@ -0,0 +1,38 @@
+# OASIS_START
+# DO NOT EDIT (digest: bc1e05bfc8b39b664f29dae8dbd3ebbb)
+
+SETUP = ocaml setup.ml
+
+build: setup.data
+ $(SETUP) -build $(BUILDFLAGS)
+
+doc: setup.data build
+ $(SETUP) -doc $(DOCFLAGS)
+
+test: setup.data build
+ $(SETUP) -test $(TESTFLAGS)
+
+all:
+ $(SETUP) -all $(ALLFLAGS)
+
+install: setup.data
+ $(SETUP) -install $(INSTALLFLAGS)
+
+uninstall: setup.data
+ $(SETUP) -uninstall $(UNINSTALLFLAGS)
+
+reinstall: setup.data
+ $(SETUP) -reinstall $(REINSTALLFLAGS)
+
+clean:
+ $(SETUP) -clean $(CLEANFLAGS)
+
+distclean:
+ $(SETUP) -distclean $(DISTCLEANFLAGS)
+
+setup.data:
+ $(SETUP) -configure $(CONFIGUREFLAGS)
+
+.PHONY: build doc test all install uninstall reinstall clean distclean configure
+
+# OASIS_STOP
View
173 Rakefile
@@ -1,173 +0,0 @@
-# Copyright (C) 2011 Rory Geoghegan - r.geoghegan@gmail.com
-# Released under the BSD license. See the LICENSE.txt file for more info.
-
-desc "Compile the library"
-task :library
-
-desc "Create the binary used for testing"
-task :test_binaries
-
-desc "Run unit tests"
-task :test => [:test_binaries] do
- sh "./build/tests/run_test_redis_util"
- sh "./build/tests/all_other_tests"
-end
-
-desc "Run smoke test"
-task :smoke_test => ["build/tests/smoke_test"] do
- sh "./build/tests/smoke_test"
-end
-
-desc "Delete droppings"
-task :clean do
- rm_rf "build"
-end
-
-desc "Start a Redis Server"
-task :start_redis => "/tmp/redis" do
- sh "redis-server redis.conf"
-end
-
-desc "Build html documentation"
-task :docs => "doc/index.html"
-
-directory "build"
-directory "/tmp/redis"
-
-# Utility code
-
-def compile source, dest
- sh "ocamlopt -w X -c -I build -o #{dest} #{source}"
-end
-
-# Library
-
-external_libs = ["unix.cmxa", "str.cmxa"].join(" ")
-
-file "build/redis_common.cmx" => ["src/redis_common.ml", "build"] do
- compile "src/redis_common.ml", "build/redis_common"
-end
-
-file "build/redis.cmi" => ["src/redis.mli", "build"] do
- compile "src/redis.mli", "build/redis.cmi"
-end
-
-file "build/redis.cmx" => ["src/redis.ml", "build/redis_common.cmx", "build/redis.cmi", "build"] do
- compile "src/redis.ml", "build/redis"
-end
-
-file "build/Redis.cmxa" => ["build/redis.cmx", "build/redis_common.cmx", "build"] do
- sh %W{
- ocamlopt
- -a
- -o build/Redis.cmxa
- build/redis_common.cmx
- build/redis.cmx
- }.join(" ")
-end
-
-task :library => "build/Redis.cmxa"
-
-# Test files
-
-directory "build/tests"
-
-# Redis_utils is a bit funny because we need to test more functions than the default mli files gives us access to
-test_objects = "build/tests/test_objects"
-directory test_objects
-
-file "build/tests/run_test_redis_util" => ["build/tests/script.cmx", test_objects, "build/tests/test_redis_util.cmx", "#{test_objects}/redis_common.cmx", "build/tests/run_test_redis_util.ml"] do
- sh %W{
- ocamlopt
- -o build/tests/run_test_redis_util
- -I build/tests
- #{external_libs}
- build/tests/script.cmx
- #{test_objects}/redis_common.cmx
- build/tests/test_redis_util.cmx
- build/tests/run_test_redis_util.ml
- }.join(" ")
-end
-file "build/tests/test_redis_util.cmx" => ["tests/test_redis_util.ml", "build/tests/script.cmx", "#{test_objects}/redis_common.cmx"] do
- sh %W{
- ocamlopt -c
- -o build/tests/test_redis_util
- -I build/tests
- -I build/tests/test_objects
- tests/test_redis_util.ml
- }.join(" ")
-end
-file "#{test_objects}/redis_common.cmx" => "#{test_objects}/redis_common.ml" do
- compile "#{test_objects}/redis_common.ml", "#{test_objects}/redis_common"
-end
-file "#{test_objects}/redis_common.ml" => "src/redis_common.ml" do
- cp "src/redis_common.ml", "#{test_objects}/redis_common.ml"
-end
-file "build/tests/run_test_redis_util.ml" => "tests/test_redis_util.ml" do
- sh "ruby tests/create_test.rb tests/test_redis_util.ml > build/tests/run_test_redis_util.ml"
-end
-
-task :test_binaries => "build/tests/run_test_redis_util"
-
-## Now for all other tests
-test_files = FileList["tests/test_*.ml"].exclude(/test_redis_util.ml$/)
-
-test_files.each do |test_file|
- file test_file.pathmap("build/tests/%n.cmx") => [test_file, :library, "build/tests/script.cmx"] do
- sh %W{
- ocamlopt
- -w X -c
- -I build
- -I build/tests
- -o #{test_file.pathmap("build/tests/%n")}
- #{test_file}
- }.join(" ")
- end
- file "build/tests/all_other_tests" => test_file.pathmap("build/tests/%n.cmx")
- file "build/tests/all_other_tests.ml" => test_file
-end
-
-file "build/tests/all_other_tests.ml" do
- sh %W{
- ruby
- tests/create_test.rb
- #{test_files.join(" ")}
- > build/tests/all_other_tests.ml
- }.join(" ")
-end
-
-file "build/tests/all_other_tests" => ["build/tests/all_other_tests.ml", :library] do
- sh %W{
- ocamlopt
- -w X
- -I build
- -I build/tests
- -o build/tests/all_other_tests
- #{external_libs}
- build/Redis.cmxa
- build/tests/script.cmx
- #{test_files.map{|f| f.pathmap("build/tests/%n.cmx")}.join(" ")}
- build/tests/all_other_tests.ml
- }.join(" ")
-end
-
-task :test_binaries => "build/tests/all_other_tests"
-
-## Smoke test
-file "build/tests/smoke_test" => [:library, "tests/smoke_test.ml", "build/tests"] do
- sh "ocamlopt -I build -o build/tests/smoke_test #{external_libs} build/Redis.cmxa tests/smoke_test.ml"
-end
-
-file "build/tests/script.cmx" => ["build/tests", "tests/script.ml"] do
- sh %W{
- ocamlopt -c
- -o build/tests/script
- tests/script.ml
- }.join(" ")
-end
-
-# Documentation
-directory "doc"
-file "doc/index.html" => ["doc", "src/redis.mli"] do
- sh "ocamldoc -html -d doc src/redis.mli"
-end
View
35 _oasis
@@ -0,0 +1,35 @@
+OASISFormat: 0.1
+Name: beagle
+Version: 1.0
+LicenseFile: COPYING
+License: BSD4
+Authors: Rory Geoghegan
+Homepage: https://github.com/rgeoghegan/ocaml-redis
+BuildTools: ocamlbuild
+Plugins: DevFiles (0.2), META (0.2)
+Synopsis: Redis client
+
+Library redis
+ Build: true
+ FindlibName: ocaml-redis
+ Path: src
+ Modules: Redis
+ BuildDepends: unix
+ Install: true
+ CompiledObject: best
+
+Flag tests
+ Description: Build and run tests
+
+Executable test
+ Path: tests
+ MainIs: test.ml
+ Install: false
+ Build$: flag(tests)
+ BuildDepends: oUnit (>= 1.1.0), ocaml-redis, str
+ CompiledObject: best
+
+Test main
+ Run$: flag(tests)
+ Command: $test
+
View
15 _tags
@@ -0,0 +1,15 @@
+# OASIS_START
+# DO NOT EDIT (digest: b4adbdfab949c1094f4b13a8ce18cc80)
+# Library redis
+"src": include
+<src/*.ml{,i}>: pkg_unix
+# Executable test
+<tests/test.{native,byte}>: use_redis
+<tests/test.{native,byte}>: pkg_unix
+<tests/test.{native,byte}>: pkg_str
+<tests/test.{native,byte}>: pkg_oUnit
+<tests/*.ml{,i}>: use_redis
+<tests/*.ml{,i}>: pkg_unix
+<tests/*.ml{,i}>: pkg_str
+<tests/*.ml{,i}>: pkg_oUnit
+# OASIS_STOP
View
8 configure
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+# OASIS_START
+# DO NOT EDIT (digest: ed33e59fe00e48bc31edf413bbc8b8d6)
+set -e
+
+ocaml setup.ml -configure $*
+# OASIS_STOP
View
463 myocamlbuild.ml
@@ -0,0 +1,463 @@
+(* OASIS_START *)
+(* DO NOT EDIT (digest: 4fd9ecb3aefa4a4f7bd85ce6e3ef9343) *)
+module OASISGettext = struct
+# 21 "/Users/joelr/work/ocaml/oasis-0.2.0/src/oasis/OASISGettext.ml"
+
+ let ns_ str =
+ str
+
+ let s_ str =
+ str
+
+ let f_ (str : ('a, 'b, 'c, 'd) format4) =
+ str
+
+ let fn_ fmt1 fmt2 n =
+ if n = 1 then
+ fmt1^^""
+ else
+ fmt2^^""
+
+ let init =
+ []
+
+end
+
+module OASISExpr = struct
+# 21 "/Users/joelr/work/ocaml/oasis-0.2.0/src/oasis/OASISExpr.ml"
+
+
+
+ open OASISGettext
+
+ type test = string
+
+ type flag = string
+
+ type t =
+ | EBool of bool
+ | ENot of t
+ | EAnd of t * t
+ | EOr of t * t
+ | EFlag of flag
+ | ETest of test * string
+
+
+ type 'a choices = (t * 'a) list
+
+ let eval var_get t =
+ let rec eval' =
+ function
+ | EBool b ->
+ b
+
+ | ENot e ->
+ not (eval' e)
+
+ | EAnd (e1, e2) ->
+ (eval' e1) && (eval' e2)
+
+ | EOr (e1, e2) ->
+ (eval' e1) || (eval' e2)
+
+ | EFlag nm ->
+ let v =
+ var_get nm
+ in
+ assert(v = "true" || v = "false");
+ (v = "true")
+
+ | ETest (nm, vl) ->
+ let v =
+ var_get nm
+ in
+ (v = vl)
+ in
+ eval' t
+
+ let choose ?printer ?name var_get lst =
+ let rec choose_aux =
+ function
+ | (cond, vl) :: tl ->
+ if eval var_get cond then
+ vl
+ else
+ choose_aux tl
+ | [] ->
+ let str_lst =
+ if lst = [] then
+ s_ "<empty>"
+ else
+ String.concat
+ (s_ ", ")
+ (List.map
+ (fun (cond, vl) ->
+ match printer with
+ | Some p -> p vl
+ | None -> s_ "<no printer>")
+ lst)
+ in
+ match name with
+ | Some nm ->
+ failwith
+ (Printf.sprintf
+ (f_ "No result for the choice list '%s': %s")
+ nm str_lst)
+ | None ->
+ failwith
+ (Printf.sprintf
+ (f_ "No result for a choice list: %s")
+ str_lst)
+ in
+ choose_aux (List.rev lst)
+
+end
+
+
+module BaseEnvLight = struct
+# 21 "/Users/joelr/work/ocaml/oasis-0.2.0/src/base/BaseEnvLight.ml"
+
+ module MapString = Map.Make(String)
+
+ type t = string MapString.t
+
+ let default_filename =
+ Filename.concat
+ (Sys.getcwd ())
+ "setup.data"
+
+ let load ?(allow_empty=false) ?(filename=default_filename) () =
+ if Sys.file_exists filename then
+ begin
+ let chn =
+ open_in_bin filename
+ in
+ let st =
+ Stream.of_channel chn
+ in
+ let line =
+ ref 1
+ in
+ let st_line =
+ Stream.from
+ (fun _ ->
+ try
+ match Stream.next st with
+ | '\n' -> incr line; Some '\n'
+ | c -> Some c
+ with Stream.Failure -> None)
+ in
+ let lexer =
+ Genlex.make_lexer ["="] st_line
+ in
+ let rec read_file mp =
+ match Stream.npeek 3 lexer with
+ | [Genlex.Ident nm; Genlex.Kwd "="; Genlex.String value] ->
+ Stream.junk lexer;
+ Stream.junk lexer;
+ Stream.junk lexer;
+ read_file (MapString.add nm value mp)
+ | [] ->
+ mp
+ | _ ->
+ failwith
+ (Printf.sprintf
+ "Malformed data file '%s' line %d"
+ filename !line)
+ in
+ let mp =
+ read_file MapString.empty
+ in
+ close_in chn;
+ mp
+ end
+ else if allow_empty then
+ begin
+ MapString.empty
+ end
+ else
+ begin
+ failwith
+ (Printf.sprintf
+ "Unable to load environment, the file '%s' doesn't exist."
+ filename)
+ end
+
+ let var_get name env =
+ let rec var_expand str =
+ let buff =
+ Buffer.create ((String.length str) * 2)
+ in
+ Buffer.add_substitute
+ buff
+ (fun var ->
+ try
+ var_expand (MapString.find var env)
+ with Not_found ->
+ failwith
+ (Printf.sprintf
+ "No variable %s defined when trying to expand %S."
+ var
+ str))
+ str;
+ Buffer.contents buff
+ in
+ var_expand (MapString.find name env)
+
+ let var_choose lst env =
+ OASISExpr.choose
+ (fun nm -> var_get nm env)
+ lst
+end
+
+
+module MyOCamlbuildFindlib = struct
+# 21 "/Users/joelr/work/ocaml/oasis-0.2.0/src/plugins/ocamlbuild/MyOCamlbuildFindlib.ml"
+
+ (** OCamlbuild extension, copied from
+ * http://brion.inria.fr/gallium/index.php/Using_ocamlfind_with_ocamlbuild
+ * by N. Pouillard and others
+ *
+ * Updated on 2009/02/28
+ *
+ * Modified by Sylvain Le Gall
+ *)
+ open Ocamlbuild_plugin
+
+ (* these functions are not really officially exported *)
+ let run_and_read =
+ Ocamlbuild_pack.My_unix.run_and_read
+
+ let blank_sep_strings =
+ Ocamlbuild_pack.Lexers.blank_sep_strings
+
+ let split s ch =
+ let x =
+ ref []
+ in
+ let rec go s =
+ let pos =
+ String.index s ch
+ in
+ x := (String.before s pos)::!x;
+ go (String.after s (pos + 1))
+ in
+ try
+ go s
+ with Not_found -> !x
+
+ let split_nl s = split s '\n'
+
+ let before_space s =
+ try
+ String.before s (String.index s ' ')
+ with Not_found -> s
+
+ (* this lists all supported packages *)
+ let find_packages () =
+ List.map before_space (split_nl & run_and_read "ocamlfind list")
+
+ (* this is supposed to list available syntaxes, but I don't know how to do it. *)
+ let find_syntaxes () = ["camlp4o"; "camlp4r"]
+
+ (* ocamlfind command *)
+ let ocamlfind x = S[A"ocamlfind"; x]
+
+ let dispatch =
+ function
+ | Before_options ->
+ (* by using Before_options one let command line options have an higher priority *)
+ (* on the contrary using After_options will guarantee to have the higher priority *)
+ (* override default commands by ocamlfind ones *)
+ Options.ocamlc := ocamlfind & A"ocamlc";
+ Options.ocamlopt := ocamlfind & A"ocamlopt";
+ Options.ocamldep := ocamlfind & A"ocamldep";
+ Options.ocamldoc := ocamlfind & A"ocamldoc";
+ Options.ocamlmktop := ocamlfind & A"ocamlmktop"
+
+ | After_rules ->
+
+ (* When one link an OCaml library/binary/package, one should use -linkpkg *)
+ flag ["ocaml"; "link"; "program"] & A"-linkpkg";
+
+ (* For each ocamlfind package one inject the -package option when
+ * compiling, computing dependencies, generating documentation and
+ * linking. *)
+ List.iter
+ begin fun pkg ->
+ flag ["ocaml"; "compile"; "pkg_"^pkg] & S[A"-package"; A pkg];
+ flag ["ocaml"; "ocamldep"; "pkg_"^pkg] & S[A"-package"; A pkg];
+ flag ["ocaml"; "doc"; "pkg_"^pkg] & S[A"-package"; A pkg];
+ flag ["ocaml"; "link"; "pkg_"^pkg] & S[A"-package"; A pkg];
+ flag ["ocaml"; "infer_interface"; "pkg_"^pkg] & S[A"-package"; A pkg];
+ end
+ (find_packages ());
+
+ (* Like -package but for extensions syntax. Morover -syntax is useless
+ * when linking. *)
+ List.iter begin fun syntax ->
+ flag ["ocaml"; "compile"; "syntax_"^syntax] & S[A"-syntax"; A syntax];
+ flag ["ocaml"; "ocamldep"; "syntax_"^syntax] & S[A"-syntax"; A syntax];
+ flag ["ocaml"; "doc"; "syntax_"^syntax] & S[A"-syntax"; A syntax];
+ flag ["ocaml"; "infer_interface"; "syntax_"^syntax] & S[A"-syntax"; A syntax];
+ end (find_syntaxes ());
+
+ (* The default "thread" tag is not compatible with ocamlfind.
+ * Indeed, the default rules add the "threads.cma" or "threads.cmxa"
+ * options when using this tag. When using the "-linkpkg" option with
+ * ocamlfind, this module will then be added twice on the command line.
+ *
+ * To solve this, one approach is to add the "-thread" option when using
+ * the "threads" package using the previous plugin.
+ *)
+ flag ["ocaml"; "pkg_threads"; "compile"] (S[A "-thread"]);
+ flag ["ocaml"; "pkg_threads"; "link"] (S[A "-thread"]);
+ flag ["ocaml"; "pkg_threads"; "infer_interface"] (S[A "-thread"])
+
+ | _ ->
+ ()
+
+end
+
+module MyOCamlbuildBase = struct
+# 21 "/Users/joelr/work/ocaml/oasis-0.2.0/src/plugins/ocamlbuild/MyOCamlbuildBase.ml"
+
+ (** Base functions for writing myocamlbuild.ml
+ @author Sylvain Le Gall
+ *)
+
+
+
+ open Ocamlbuild_plugin
+
+ type dir = string
+ type file = string
+ type name = string
+ type tag = string
+
+# 55 "/Users/joelr/work/ocaml/oasis-0.2.0/src/plugins/ocamlbuild/MyOCamlbuildBase.ml"
+
+ type t =
+ {
+ lib_ocaml: (name * dir list) list;
+ lib_c: (name * dir * file list) list;
+ flags: (tag list * (spec OASISExpr.choices)) list;
+ }
+
+ let env_filename =
+ Pathname.basename
+ BaseEnvLight.default_filename
+
+ let dispatch_combine lst =
+ fun e ->
+ List.iter
+ (fun dispatch -> dispatch e)
+ lst
+
+ let dispatch t e =
+ let env =
+ BaseEnvLight.load
+ ~filename:env_filename
+ ~allow_empty:true
+ ()
+ in
+ match e with
+ | Before_options ->
+ let no_trailing_dot s =
+ if String.length s >= 1 && s.[0] = '.' then
+ String.sub s 1 ((String.length s) - 1)
+ else
+ s
+ in
+ List.iter
+ (fun (opt, var) ->
+ try
+ opt := no_trailing_dot (BaseEnvLight.var_get var env)
+ with Not_found ->
+ Printf.eprintf "W: Cannot get variable %s" var)
+ [
+ Options.ext_obj, "ext_obj";
+ Options.ext_lib, "ext_lib";
+ Options.ext_dll, "ext_dll";
+ ]
+
+ | After_rules ->
+ (* Declare OCaml libraries *)
+ List.iter
+ (function
+ | lib, [] ->
+ ocaml_lib lib;
+ | lib, dir :: tl ->
+ ocaml_lib ~dir:dir lib;
+ List.iter
+ (fun dir ->
+ flag
+ ["ocaml"; "use_"^lib; "compile"]
+ (S[A"-I"; P dir]))
+ tl)
+ t.lib_ocaml;
+
+ (* Declare C libraries *)
+ List.iter
+ (fun (lib, dir, headers) ->
+ (* Handle C part of library *)
+ flag ["link"; "library"; "ocaml"; "byte"; "use_lib"^lib]
+ (S[A"-dllib"; A("-l"^lib); A"-cclib"; A("-l"^lib)]);
+
+ flag ["link"; "library"; "ocaml"; "native"; "use_lib"^lib]
+ (S[A"-cclib"; A("-l"^lib)]);
+
+ flag ["link"; "program"; "ocaml"; "byte"; "use_lib"^lib]
+ (S[A"-dllib"; A("dll"^lib)]);
+
+ (* When ocaml link something that use the C library, then one
+ need that file to be up to date.
+ *)
+ dep ["link"; "ocaml"; "use_lib"^lib]
+ [dir/"lib"^lib^"."^(!Options.ext_lib)];
+
+ (* TODO: be more specific about what depends on headers *)
+ (* Depends on .h files *)
+ dep ["compile"; "c"]
+ headers;
+
+ (* Setup search path for lib *)
+ flag ["link"; "ocaml"; "use_"^lib]
+ (S[A"-I"; P(dir)]);
+ )
+ t.lib_c;
+
+ (* Add flags *)
+ List.iter
+ (fun (tags, cond_specs) ->
+ let spec =
+ BaseEnvLight.var_choose cond_specs env
+ in
+ flag tags & spec)
+ t.flags
+ | _ ->
+ ()
+
+ let dispatch_default t =
+ dispatch_combine
+ [
+ dispatch t;
+ MyOCamlbuildFindlib.dispatch;
+ ]
+
+end
+
+
+open Ocamlbuild_plugin;;
+let package_default =
+ {
+ MyOCamlbuildBase.lib_ocaml = [("src/redis", ["src"])];
+ lib_c = [];
+ flags = [];
+ }
+ ;;
+
+let dispatch_default = MyOCamlbuildBase.dispatch_default package_default;;
+
+(* OASIS_STOP *)
+Ocamlbuild_plugin.dispatch dispatch_default;;
View
5,287 setup.ml
5,287 additions, 0 deletions not shown
View
10 src/META
@@ -0,0 +1,10 @@
+# OASIS_START
+# DO NOT EDIT (digest: b505ea62fc07ec8359583aa739221e91)
+version = "1.0"
+description = "Redis client"
+requires = "unix"
+archive(byte) = "redis.cma"
+archive(native) = "redis.cmxa"
+exists_if = "redis.cma"
+# OASIS_STOP
+
View
4 src/redis.mllib
@@ -0,0 +1,4 @@
+# OASIS_START
+# DO NOT EDIT (digest: e111446745a1825b862f8727ae63bce4)
+Redis
+# OASIS_STOP
View
34 src/redis_common.ml
@@ -3,8 +3,17 @@
Utility code used mostly internally to the library. *)
-type redis_value_type = RedisString | RedisNil | RedisList | RedisSet | RedisZSet
-type bulk_data = Nil | String of string
+type redis_value_type =
+ | RedisString
+ | RedisNil
+ | RedisList
+ | RedisSet
+ | RedisZSet
+
+type bulk_data =
+ | Nil
+ | String of string
+
type rank = NilRank | Rank of int
type multi_bulk_data = MultibulkNil | MultibulkValue of bulk_data list
exception RedisServerError of string
@@ -104,12 +113,10 @@ module Connection =
Buffer.contents out_buf
end;;
+ (* Send the given text out to the connection without flushing *)
let send_text_straight text (_, out_chan) =
- (* Send the given text out to the connection without flushing *)
- begin
- output_string out_chan text;
- output_string out_chan "\r\n"
- end
+ output_string out_chan text;
+ output_string out_chan "\r\n"
let send_text text connection =
(* Send the given text out to the connection *)
@@ -211,12 +218,11 @@ module Helpers =
let send_with_value_and_receive_command_safely command value connection =
(* Will send out the command, appended with the length of value, and will then send out value. Also
- will catch and fail on any errors. I.e., given 'foo' 'bar', will send "foo 3\r\nbar\r\n" *)
- begin
- Connection.send_text_straight (command ^ " " ^ (string_of_int (String.length value))) connection;
- Connection.send_text value connection;
- handle_error (receive_answer connection)
- end
+ will catch and fail on any errors. I.e., given 'foo'
+ 'bar', will send "foo 3\r\nbar\r\n" *)
+ Connection.send_text_straight command connection;
+ Connection.send_text value connection;
+ handle_error (receive_answer connection)
let aggregate_command command tokens =
(* Given a list of tokens, joins them with command *)
@@ -261,7 +267,7 @@ module Helpers =
let handle_special_status special_status reply =
(* For status replies, does error checking and display *)
- match handle_error reply with
+ match handle_error reply with
Status(x) when x = special_status -> () |
Status(x) -> failwith ("Received status(" ^ x ^ ")") |
_ -> failwith "Did not recognize what I got back"
View
60 tests/create_test.rb
@@ -1,60 +0,0 @@
-#!/usr/bin/env ruby
-# Copyright (C) 2011 Rory Geoghegan - r.geoghegan@gmail.com
-# Released under the BSD license. See the LICENSE.txt file for more info.
-#
-# Script that generates a global test module based on all the ocaml code files it parses.
-
-require "rubygems"
-require "trollop"
-require "erb"
-
-opts = Trollop::options do
- opt :outfile, "Outfile to write to", :type => String
-end
-
-MODULE_NAMER = /([^\/]*)\.ml$/
-tests = {}
-ARGV.each do |filename|
- module_name = MODULE_NAMER.match(filename)[1].capitalize
- File.new(filename, "r").each_line do |line|
- if line =~ /^let (test_\S+) \(\) =/
- then
- if not tests.key? module_name then
- tests[module_name] = []
- end
- tests[module_name] << $1
- end
- end
-end
-
-template_text = %q{
-let execute_test test_name test_func =
- begin
- print_string (" " ^ test_name ^ "... ");
- test_func ();
- print_endline "\x1b[32mpassed\x1b[m"
- end;;
-
-let main () =
- begin
- print_newline ();
-% tests.each_pair do |mod_name, test_names|
- print_endline "In module <%=mod_name%>:";
-% test_names.each do |name|
- execute_test "<%=name%>" <%=mod_name%>.<%=name%>;
-% end
- print_newline ();
-% end
- print_endline "\x1b[36mAll Done!\x1b[m";
- end;;
-
-let _ = main();;
-}
-
-template = ERB.new(template_text, 0, "%")
-
-if opts[:outfile] then
- File.open(opts[:outfile], "w") {|f| f.write(template.result)}
-else
- puts template.result
-end
View
401 tests/smoke_test.ml
@@ -3,218 +3,241 @@
Simple smoke test to be run on local server. *)
-let smoke_test_with_quit conn = begin
- Redis.auth "qwerty" conn;
- Redis.flushall conn;
-
- assert ( false = Redis.exists "rory" conn);
- Redis.set "rory" "cool" conn;
- assert ( "cool" = Redis.string_of_bulk_data (Redis.get "rory" conn));
- assert ( "cool" = Redis.string_of_bulk_data (Redis.getset "rory" "not cool" conn));
- assert ( [Redis.String("not cool"); Redis.Nil] = Redis.mget ["rory"; "tim"] conn);
- assert ( false = Redis.setnx "rory" "uncool" conn);
- assert ( "not cool" = Redis.string_of_bulk_data (Redis.get "rory" conn));
-
- Redis.mset [("rory", "cool"); ("tim", "not cool")] conn;
- assert (not (Redis.msetnx [("rory", "not cool"); ("tim", "cool")] conn));
-
- Redis.set "rory" "0" conn;
- assert ( 1 = Redis.incr "rory" conn);
- assert ( 5 = Redis.incrby "rory" 4 conn);
- assert ( 4 = Redis.decr "rory" conn);
- assert ( 2 = Redis.decrby "rory" 2 conn);
-
- Redis.set "rory" "very " conn;
- assert (9 = Redis.append "rory" "cool" conn);
-
- assert ("cool" = Redis.string_of_bulk_data (Redis.substr "rory" 5 9 conn));
-
- assert ( 2 = Redis.del ["rory"; "tim"] conn);
- assert (false = Redis.del_one "rory" conn);
-
- Redis.set "rory" "cool" conn;
- assert ( Redis.RedisNil = (Redis.value_type "tim" conn));
- assert ( Redis.RedisString = (Redis.value_type "rory" conn));
-
- assert ( ["rory"] = Redis.keys "*" conn);
- assert ( "rory" = Redis.randomkey conn);
- Redis.rename "rory" "tim" conn;
-
- assert ( "tim" = Redis.randomkey conn);
-
- Redis.set "rory" "more cool" conn;
- assert ( false = Redis.renamenx "rory" "tim" conn);
-
- Redis.setex "rory" 10 "cool" conn;
-
- assert ( 2 == Redis.dbsize conn );
-
- Redis.set "rory" "cool" conn;
- assert ( Redis.expire "rory" 10 conn );
- assert ( 10 >= Redis.ttl "rory" conn );
-
- assert (Redis.expireat "tim" (Unix.time() +. 10.) conn);
- assert ( 10 >= Redis.ttl "tim" conn );
-
- (* List operations *)
- ignore (Redis.del ["rory"] conn);
- assert ( 1 == Redis.rpush "rory" "cool" conn);
-
- assert ( 2 == Redis.lpush "rory" "even cooler" conn);
- assert ( 2 == (Redis.llen "rory" conn));
- assert ( [Redis.String("even cooler"); Redis.String("cool")] = (Redis.lrange "rory" 0 1 conn));
-
- Redis.ltrim "rory" 0 0 conn;
- assert ( (Redis.string_of_bulk_data (Redis.lindex "rory" 0 conn)) = "even cooler");
- Redis.lset "rory" 0 "just cool" conn;
- ignore (Redis.rpush "rory" "cool" conn);
- assert (1 = Redis.lrem "rory" 0 "cool" conn);
-
- ignore (Redis.rpush "rory" "cool" conn);
- ignore (Redis.rpush "rory" "even cooler" conn);
+open OUnit
- assert ( (Redis.string_of_bulk_data (Redis.lpop "rory" conn)) = "just cool");
- assert ( (Redis.string_of_bulk_data (Redis.rpop "rory" conn)) = "even cooler");
-
- ignore (Redis.rpush "cool" "rory" conn);
- ignore (Redis.rpush "cool" "tim" conn);
- assert ( (Redis.string_of_bulk_data (Redis.rpoplpush "cool" "not_cool" conn)) = "tim");
-
- (* Set operations *)
- ignore (Redis.del_one "tim" conn);
- assert ( Redis.sadd "tim" "not cool" conn);
- assert ( Redis.sadd "tim" "smells" conn);
-
- assert ( Redis.srem "tim" "smells" conn);
- assert ( "not cool" = Redis.string_of_bulk_data (Redis.spop "tim" conn) );
-
- ignore ( Redis.del_one "rory" conn);
- assert ( Redis.sadd "rory" "cool" conn);
- assert ( Redis.sadd "tim" "even cooler" conn);
+let suite =
+ let setup () =
+ let conn = Redis.create_connection () in
+ Redis.auth "qwerty" conn;
+ Redis.flushall conn;
+ conn
+ in
+ let teardown conn =
+ Redis.flushall conn;
+ Redis.quit conn
+ in
+ let test f = (bracket setup f teardown) in
+ "smoke test" >:::
+ [
+ "general" >::
+ (test
+ (fun conn ->
+ assert_equal false (Redis.exists "rory" conn);
+ Redis.set "rory" "cool" conn;
+ assert_equal "cool" (Redis.string_of_bulk_data (Redis.get "rory" conn));
+ assert_equal "cool" (Redis.string_of_bulk_data (Redis.getset "rory" "not cool" conn));
+ assert_equal [Redis.String("not cool"); Redis.Nil] (Redis.mget ["rory"; "tim"] conn);
+ assert_equal false (Redis.setnx "rory" "uncool" conn);
+ assert_equal "not cool" (Redis.string_of_bulk_data (Redis.get "rory" conn));
+
+ Redis.mset [("rory", "cool"); ("tim", "not cool")] conn;
+ assert_bool "" (not (Redis.msetnx [("rory", "not cool"); ("tim", "cool")] conn));
+
+ Redis.set "rory" "0" conn;
+ assert_equal 1 (Redis.incr "rory" conn);
+ assert_equal 5 (Redis.incrby "rory" 4 conn);
+ assert_equal 4 (Redis.decr "rory" conn);
+ assert_equal 2 (Redis.decrby "rory" 2 conn);
+
+ Redis.set "rory" "very " conn;
+ assert_equal 9 (Redis.append "rory" "cool" conn);
+
+ assert_equal "cool" (Redis.string_of_bulk_data (Redis.substr "rory" 5 9 conn));
+
+ assert_equal 2 (Redis.del ["rory"; "tim"] conn);
+ assert_equal false (Redis.del_one "rory" conn);
+
+ Redis.set "rory" "cool" conn;
+ assert_equal Redis.RedisNil (Redis.value_type "tim" conn);
+ assert_equal Redis.RedisString (Redis.value_type "rory" conn);
+
+ assert_equal ["rory"] (Redis.keys "*" conn);
+ assert_equal "rory" (Redis.randomkey conn);
+ Redis.rename "rory" "tim" conn;
+
+ assert_equal "tim" (Redis.randomkey conn);
+
+ Redis.set "rory" "more cool" conn;
+ assert_equal false (Redis.renamenx "rory" "tim" conn);
+
+ Redis.setex "rory" 10 "cool" conn;
+
+ assert_equal 2 (Redis.dbsize conn );
+
+ Redis.set "rory" "cool" conn;
+ assert_bool "" (Redis.expire "rory" 10 conn);
+ assert_bool "" (10 >= Redis.ttl "rory" conn);
+
+ assert_bool "" (Redis.expireat "tim" (Unix.time() +. 10.) conn);
+ assert_bool "" (10 >= Redis.ttl "tim" conn);
+ ));
+ "list operations" >::
+ (test
+ (fun conn ->
+ ignore (Redis.del ["rory"] conn);
+ assert_equal 1 (Redis.rpush "rory" "cool" conn);
+ assert_equal 2 (Redis.lpush "rory" "even cooler" conn);
+ assert_equal 2 (Redis.llen "rory" conn);
+ assert_equal [Redis.String("even cooler"); Redis.String("cool")]
+ (Redis.lrange "rory" 0 1 conn);
+
+ Redis.ltrim "rory" 0 0 conn;
+ assert_equal "even cooler" (Redis.string_of_bulk_data (Redis.lindex "rory" 0 conn));
+ Redis.lset "rory" 0 "just cool" conn;
+ ignore (Redis.rpush "rory" "cool" conn);
+ assert_equal 1 (Redis.lrem "rory" 0 "cool" conn);
+
+ ignore (Redis.rpush "rory" "cool" conn);
+ ignore (Redis.rpush "rory" "even cooler" conn);
+
+ assert_equal "just cool" (Redis.string_of_bulk_data (Redis.lpop "rory" conn));
+ assert_equal "even cooler" (Redis.string_of_bulk_data (Redis.rpop "rory" conn));
+
+ ignore (Redis.rpush "cool" "rory" conn);
+ ignore (Redis.rpush "cool" "tim" conn);
+ assert_equal "tim" (Redis.string_of_bulk_data (Redis.rpoplpush "cool" "not_cool" conn));
+ ));
+
+ "set operations" >::
+ (test
+ (fun conn ->
+ ignore (Redis.del_one "tim" conn);
+ assert_bool "" (Redis.sadd "tim" "not cool" conn);
+ assert_bool "" (Redis.sadd "tim" "smells" conn);
+ assert_bool "" (Redis.srem "tim" "smells" conn);
+ assert_equal "not cool" (Redis.string_of_bulk_data (Redis.spop "tim" conn));
+
+ ignore ( Redis.del_one "rory" conn);
+ assert_bool "" (Redis.sadd "rory" "cool" conn);
+ assert_bool "" ( Redis.sadd "tim" "even cooler" conn);
+ assert_bool "" ( Redis.smove "tim" "rory" "even cooler" conn );
+
+ assert_equal 2 (Redis.scard "rory" conn );
+ assert_bool "" ( Redis.sismember "rory" "cool" conn );
- assert ( Redis.smove "tim" "rory" "even cooler" conn );
- assert ( 2 = Redis.scard "rory" conn );
+ ignore ( Redis.srem "rory" "cool" conn );
+ assert_equal "even cooler" (Redis.string_of_bulk_data (List.hd (Redis.smembers "rory" conn)) );
- assert ( Redis.sismember "rory" "cool" conn );
+ ignore (Redis.sadd "tim" "even cooler" conn);
- ignore ( Redis.srem "rory" "cool" conn );
- assert ( "even cooler" = Redis.string_of_bulk_data (List.hd (Redis.smembers "rory" conn)) );
- ignore (Redis.sadd "tim" "even cooler" conn);
- assert ( "even cooler" = Redis.string_of_bulk_data (List.hd (Redis.sinter ["rory"; "tim"] conn)) );
+ assert_equal "even cooler" (Redis.string_of_bulk_data (List.hd (Redis.sinter ["rory"; "tim"] conn)) );
- assert ( 1 = Redis.sinterstore "bob" ["rory"; "tim"] conn );
+ assert_equal 1 ( Redis.sinterstore "bob" ["rory"; "tim"] conn );
- assert ( "even cooler" = Redis.string_of_bulk_data (List.hd (Redis.sunion ["rory"; "tim"] conn)) );
- assert ( 1 = Redis.sunionstore "bob" ["rory"; "tim"] conn );
- ignore ( Redis.srem "tim" "even cooler" conn );
- assert ( "even cooler" = Redis.string_of_bulk_data (List.hd (Redis.sdiff "rory" ["tim"] conn)) );
- assert ( 1 = Redis.sdiffstore "bob" "rory" ["tim"] conn);
+ assert_equal "even cooler" (Redis.string_of_bulk_data (List.hd (Redis.sunion ["rory"; "tim"] conn)) );
+ assert_equal 1 (Redis.sunionstore "bob" ["rory"; "tim"] conn );
- ignore (Redis.del_one "rory" conn);
- ignore (Redis.del_one "tim" conn);
- ignore (Redis.sadd "rory" "cool" conn);
- assert ( "cool" = Redis.string_of_bulk_data (Redis.srandmember "rory" conn));
- assert (Redis.Nil = Redis.srandmember "non_existent_key" conn);
+ ignore ( Redis.srem "tim" "even cooler" conn );
+ assert_equal "even cooler" (Redis.string_of_bulk_data (List.hd (Redis.sdiff "rory" ["tim"] conn)) );
+ assert_equal 1 (Redis.sdiffstore "bob" "rory" ["tim"] conn);
+
+ ignore (Redis.del ["rory"; "tim"] conn);
+ ignore (Redis.sadd "rory" "cool" conn);
+ assert_equal "cool" (Redis.string_of_bulk_data (Redis.srandmember "rory" conn));
+ assert_equal Redis.Nil (Redis.srandmember "non_existent_key" conn);
+ ));
+
+(*
(* Multiple databases *)
Redis.select 1 conn;
Redis.select 0 conn;
- assert ( Redis.move "rory" 1 conn );
+ assert_bool "" ( Redis.move "rory" 1 conn );
ignore (Redis.lpush "rory" "1" conn);
ignore (Redis.lpush "rory" "2" conn);
ignore (Redis.lpush "rory" "11" conn);
(* Sorted sets *)
- assert (Redis.zadd "coolest" 42.0 "rory" conn);
- assert (Redis.zrem "coolest" "rory" conn);
+ assert_bool "" (Redis.zadd "coolest" 42.0 "rory" conn);
+ assert_bool "" (Redis.zrem "coolest" "rory" conn);
ignore (Redis.zadd "coolest" 1.0 "rory" conn);
ignore (Redis.zadd "coolest" 99.0 "tim" conn);
- assert (
+ assert_bool "" (
["rory"; "tim"]
= List.map
Redis.string_of_bulk_data
(Redis.zrange "coolest" 0 1 conn));
- assert (
+ assert_bool "" (
[("rory", 1.0); ("tim", 99.0)]
= List.map
(fun (a,b) -> (Redis.string_of_bulk_data a, b))
(Redis.zrange_withscores "coolest" 0 1 conn));
- assert (
+ assert_bool "" (
["tim"; "rory"]
= List.map
Redis.string_of_bulk_data
(Redis.zrevrange "coolest" 0 1 conn));
- assert (
+ assert_bool "" (
[("tim", 99.0); ("rory", 1.0)]
= List.map
(fun (a,b) -> (Redis.string_of_bulk_data a, b))
(Redis.zrevrange_withscores "coolest" 0 1 conn));
- assert (
+ assert_bool "" (
"rory"
= Redis.string_of_bulk_data
(List.hd
(Redis.zrangebyscore
"coolest" 0.0 100.0 ~limit:(`Limit(0,1)) conn)));
- assert (
+ assert_bool "" (
2.0
= Redis.zincrby "coolest" 1.0 "rory" conn);
- assert (
+ assert_bool "" (
Redis.Rank(0) = Redis.zrank "coolest" "rory" conn
);
- assert (
+ assert_bool "" (
Redis.Rank(1) = Redis.zrevrank "coolest" "rory" conn
);
- assert (2 = Redis.zcard "coolest" conn);
+ assert_bool "" (2 = Redis.zcard "coolest" conn);
- assert (2.0 = Redis.zscore "coolest" "rory" conn);
+ assert_bool "" (2.0 = Redis.zscore "coolest" "rory" conn);
- assert (1 = Redis.zremrangebyrank "coolest" 0 0 conn);
+ assert_bool "" (1 = Redis.zremrangebyrank "coolest" 0 0 conn);
- assert (1 = Redis.zremrangebyscore "coolest" 80.0 120.0 conn);
+ assert_bool "" (1 = Redis.zremrangebyscore "coolest" 80.0 120.0 conn);
ignore (Redis.del_one "tim" conn);
ignore (Redis.del_one "rory" conn);
ignore (Redis.zadd "rory" 10.0 "cool" conn);
ignore (Redis.zadd "tim" 20.0 "uncool" conn);
- assert (2 = Redis.zunionstore "union" ["rory"; "tim"] conn);
- assert (2 = Redis.zunionstore "union" ["rory"; "tim"] ~aggregate:`Sum conn);
- assert (2 = Redis.zunionstore "union" ["rory"; "tim"] ~aggregate:`Min conn);
- assert (2 = Redis.zunionstore "union" ["rory"; "tim"] ~aggregate:`Max conn);
-
- assert (2 = Redis.zunionstore_withweights "union" ["rory"; "tim"] [1.0; 0.5] conn);
- assert (2 = Redis.zunionstore_withweights "union" ["rory"; "tim"] [1.0; 0.5] ~aggregate:`Sum conn);
- assert (2 = Redis.zunionstore_withweights "union" ["rory"; "tim"] [1.0; 0.5] ~aggregate:`Min conn);
- assert (2 = Redis.zunionstore_withweights "union" ["rory"; "tim"] [1.0; 0.5] ~aggregate:`Max conn);
-
- assert (0 = Redis.zinterstore "inter" ["rory"; "tim"] conn);
- assert (0 = Redis.zinterstore "inter" ["rory"; "tim"] ~aggregate:`Sum conn);
- assert (0 = Redis.zinterstore "inter" ["rory"; "tim"] ~aggregate:`Min conn);
- assert (0 = Redis.zinterstore "inter" ["rory"; "tim"] ~aggregate:`Max conn);
-
- assert (0 = Redis.zinterstore_withweights "inter" ["rory"; "tim"] [1.0; 0.5] conn);
- assert (0 = Redis.zinterstore_withweights "inter" ["rory"; "tim"] [1.0; 0.5] ~aggregate:`Sum conn);
- assert (0 = Redis.zinterstore_withweights "inter" ["rory"; "tim"] [1.0; 0.5] ~aggregate:`Min conn);
- assert (0 = Redis.zinterstore_withweights "inter" ["rory"; "tim"] [1.0; 0.5] ~aggregate:`Max conn);
+ assert_bool "" (2 = Redis.zunionstore "union" ["rory"; "tim"] conn);
+ assert_bool "" (2 = Redis.zunionstore "union" ["rory"; "tim"] ~aggregate:`Sum conn);
+ assert_bool "" (2 = Redis.zunionstore "union" ["rory"; "tim"] ~aggregate:`Min conn);
+ assert_bool "" (2 = Redis.zunionstore "union" ["rory"; "tim"] ~aggregate:`Max conn);
+
+ assert_bool "" (2 = Redis.zunionstore_withweights "union" ["rory"; "tim"] [1.0; 0.5] conn);
+ assert_bool "" (2 = Redis.zunionstore_withweights "union" ["rory"; "tim"] [1.0; 0.5] ~aggregate:`Sum conn);
+ assert_bool "" (2 = Redis.zunionstore_withweights "union" ["rory"; "tim"] [1.0; 0.5] ~aggregate:`Min conn);
+ assert_bool "" (2 = Redis.zunionstore_withweights "union" ["rory"; "tim"] [1.0; 0.5] ~aggregate:`Max conn);
+
+ assert_bool "" (0 = Redis.zinterstore "inter" ["rory"; "tim"] conn);
+ assert_bool "" (0 = Redis.zinterstore "inter" ["rory"; "tim"] ~aggregate:`Sum conn);
+ assert_bool "" (0 = Redis.zinterstore "inter" ["rory"; "tim"] ~aggregate:`Min conn);
+ assert_bool "" (0 = Redis.zinterstore "inter" ["rory"; "tim"] ~aggregate:`Max conn);
+
+ assert_bool "" (0 = Redis.zinterstore_withweights "inter" ["rory"; "tim"] [1.0; 0.5] conn);
+ assert_bool "" (0 = Redis.zinterstore_withweights "inter" ["rory"; "tim"] [1.0; 0.5] ~aggregate:`Sum conn);
+ assert_bool "" (0 = Redis.zinterstore_withweights "inter" ["rory"; "tim"] [1.0; 0.5] ~aggregate:`Min conn);
+ assert_bool "" (0 = Redis.zinterstore_withweights "inter" ["rory"; "tim"] [1.0; 0.5] ~aggregate:`Max conn);
(* Sort *)
ignore (Redis.del_one "rory" conn);
ignore (Redis.lpush "rory" "1" conn);
ignore (Redis.lpush "rory" "2" conn);
- assert ( "2" = Redis.string_of_bulk_data (List.hd (
+ assert_bool "" ( "2" = Redis.string_of_bulk_data (List.hd (
Redis.sort "rory" ~alpha:`Alpha ~order:`Desc conn
)));
- assert ("2" = Redis.string_of_bulk_data (List.hd (
+ assert_bool "" ("2" = Redis.string_of_bulk_data (List.hd (
Redis.sort "rory" ~pattern:Redis.NoSort conn
)));
@@ -240,62 +263,62 @@ let smoke_test_with_quit conn = begin
ignore (Redis.hset "hash_1" "yob" "1984" conn);
ignore (Redis.hset "hash_2" "yob" "1980" conn);
- assert (
+ assert_bool "" (
["Rory"; "Bob"] =
List.map Redis.string_of_bulk_data
(Redis.sort "people" ~get:(Redis.KeyPattern("name_*")) conn));
- assert (
+ assert_bool "" (
["1984"; "1980"] =
List.map Redis.string_of_bulk_data
(Redis.sort "people" ~get:(Redis.FieldPattern("hash_*", "yob")) conn));
- assert (
+ assert_bool "" (
["Bob"; "1980"] =
List.map Redis.string_of_bulk_data
(List.hd (Redis.sort_get_many "people" ["name_*"; "yob_*"] ~pattern:(Redis.KeyPattern("yob_*")) conn))
);
- assert (
+ assert_bool "" (
["Bob"; "1980"] =
List.map Redis.string_of_bulk_data
(List.hd (Redis.sort_get_many "people" ["name_*"; "yob_*"] ~pattern:(Redis.FieldPattern("hash_*", "yob")) conn))
);
- assert(2=
+ assert_bool ""(2=
Redis.sort_and_store "people" ["name_*"] "results" ~pattern:(Redis.KeyPattern("yob_*")) conn);
(* Hashes *)
ignore (Redis.del ["rory"] conn);
- assert (Redis.hset "rory" "cool" "true" conn);
- assert (not (Redis.hset "rory" "cool" "false" conn));
+ assert_bool "" (Redis.hset "rory" "cool" "true" conn);
+ assert_bool "" (not (Redis.hset "rory" "cool" "false" conn));
- assert (Redis.hdel "rory" "cool" conn);
- assert (not (Redis.hdel "rory" "cool" conn));
+ assert_bool "" (Redis.hdel "rory" "cool" conn);
+ assert_bool "" (not (Redis.hdel "rory" "cool" conn));
- assert (Redis.hset "rory" "handsome" "true" conn);
- assert (Redis.String("true") = Redis.hget "rory" "handsome" conn);
- assert (Redis.Nil = Redis.hget "rory" "boring" conn);
+ assert_bool "" (Redis.hset "rory" "handsome" "true" conn);
+ assert_bool "" (Redis.String("true") = Redis.hget "rory" "handsome" conn);
+ assert_bool "" (Redis.Nil = Redis.hget "rory" "boring" conn);
- assert ([Redis.String("true"); Redis.Nil] = Redis.hmget "rory" ["handsome"; "boring"] conn);
+ assert_bool "" ([Redis.String("true"); Redis.Nil] = Redis.hmget "rory" ["handsome"; "boring"] conn);
Redis.hmset "rory" [("handsome", "false"); ("boring", "true")] conn;
- assert(26 = Redis.hincrby "rory" "age" 26 conn);
+ assert_bool ""(26 = Redis.hincrby "rory" "age" 26 conn);
- assert(Redis.hexists "rory" "handsome" conn);
- assert(not (Redis.hexists "rory" "andsome" conn));
+ assert_bool ""(Redis.hexists "rory" "handsome" conn);
+ assert_bool ""(not (Redis.hexists "rory" "andsome" conn));
- assert(3 = Redis.hlen "rory" conn);
+ assert_bool ""(3 = Redis.hlen "rory" conn);
ignore (Redis.del ["rory"] conn);
ignore (Redis.hset "rory" "cool" "true" conn);
- assert(["cool"] = Redis.hkeys "rory" conn);
+ assert_bool ""(["cool"] = Redis.hkeys "rory" conn);
- assert(["true"] = Redis.hvals "rory" conn);
+ assert_bool ""(["true"] = Redis.hvals "rory" conn);
- assert( [("cool", "true")] = Redis.hgetall "rory" conn);
+ assert_bool ""( [("cool", "true")] = Redis.hgetall "rory" conn);
(* Remote server control commands *)
- assert ( "master" = Redis.Info.get
+ assert_bool "" ( "master" = Redis.Info.get
(Redis.info conn)
"role"
);
@@ -305,42 +328,50 @@ let smoke_test_with_quit conn = begin
ignore (Redis.del ["rory"; "tim"; "bob"] conn);
ignore (Redis.rpush "rory" "cool" conn);
- assert ((Redis.string_of_bulk_data (Redis.blpop "rory" conn)) = "cool");
- assert ((Redis.blpop "rory" ~timeout:(`Seconds(1)) conn) = Redis.Nil);
+ assert_bool "" ((Redis.string_of_bulk_data (Redis.blpop "rory" conn)) = "cool");
+ assert_bool "" ((Redis.blpop "rory" ~timeout:(`Seconds(1)) conn) = Redis.Nil);
ignore (Redis.rpush "tim" "not cool" conn);
- assert ((Redis.blpop_many ["rory"; "tim"] conn) = ("tim", Redis.String("not cool")));
- assert ((Redis.blpop_many ["rory"; "tim"] ~timeout:(`Seconds(1)) conn) = ("", Redis.Nil));
+ assert_bool "" ((Redis.blpop_many ["rory"; "tim"] conn) = ("tim", Redis.String("not cool")));
+ assert_bool "" ((Redis.blpop_many ["rory"; "tim"] ~timeout:(`Seconds(1)) conn) = ("", Redis.Nil));
ignore (Redis.rpush "rory" "cool" conn);
- assert ((Redis.string_of_bulk_data (Redis.brpop "rory" conn)) = "cool");
- assert ((Redis.brpop "rory" ~timeout:(`Seconds(1)) conn) = Redis.Nil);
+ assert_bool "" ((Redis.string_of_bulk_data (Redis.brpop "rory" conn)) = "cool");
+ assert_bool "" ((Redis.brpop "rory" ~timeout:(`Seconds(1)) conn) = Redis.Nil);
ignore (Redis.rpush "tim" "not cool" conn);
- assert ((Redis.blpop_many ["rory"; "tim"; "bob"] conn) = ("tim", Redis.String("not cool")));
- assert ((Redis.blpop_many ["rory"; "tim"; "bob"] ~timeout:(`Seconds(1)) conn) = ("", Redis.Nil));
+ assert_bool "" ((Redis.blpop_many ["rory"; "tim"; "bob"] conn) = ("tim", Redis.String("not cool")));
+ assert_bool "" ((Redis.blpop_many ["rory"; "tim"; "bob"] ~timeout:(`Seconds(1)) conn) = ("", Redis.Nil));
(* Persistence *)
print_endline "-- Starting persistence tests";
Redis.save conn;
Redis.bgsave conn;
- assert ( 0.0 < Redis.lastsave conn);
+ assert_bool "" ( 0.0 < Redis.lastsave conn);
Redis.bgrewriteaof conn;
+*)
+ ]
+let shutdown_suite =
+ let setup () : Redis.Connection.t =
+ let conn = Redis.create_connection () in
+ Redis.auth "qwerty" conn;
+ Redis.flushall conn;
+ conn
+ in
+ let teardown (conn : Redis.Connection.t) =
Redis.flushall conn;
Redis.quit conn
-end;;
-
-let smoke_test_with_shutdown conn = begin
- (* Shutdown is different from quit, so it needs it's own test function *)
- Redis.auth "qwerty" conn;
- Redis.shutdown conn
-end
-
-let _ =
- begin
- smoke_test_with_quit (Redis.create_connection ());
- smoke_test_with_shutdown (Redis.create_connection ());
- print_endline "\x1b[32mSmoke test passed\x1b[m"
- end;;
+ in
+ let test f = (bracket setup f teardown) in
+ "smoke test" >:::
+ [
+ "general" >::
+ (test
+ (fun conn ->
+ (* Shutdown is different from quit, so it needs it's own test function *)
+ Redis.auth "qwerty" conn;
+ Redis.shutdown conn;
+ ));
+ ]
View
9 tests/test.ml
@@ -0,0 +1,9 @@
+open OUnit;;
+
+let suite = "ocaml-redis" >:::
+ [
+ Smoke_test.suite;
+ ]
+
+let _ = run_test_tt_main suite
+
Please sign in to comment.
Something went wrong with that request. Please try again.