Skip to content

Commit eea8345

Browse files
committed
Merge pull request mrnumber#7 from aluuu/remove-batteries
Remove Batteries
2 parents 671461c + d279948 commit eea8345

File tree

10 files changed

+80
-32
lines changed

10 files changed

+80
-32
lines changed

.travis-ci.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
OPAM_DEPENDS="batteries uuidm lwt ounit"
1+
OPAM_DEPENDS="re uuidm lwt ounit"
22

33
case "$OCAML_VERSION,$OPAM_VERSION" in
44
4.00.1,1.0.0) ppa=avsm/ocaml40+opam10 ;;

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ Ocaml bindings for [Redis](http://redis.io/)
44

55
## Dependencies
66

7-
* [Batteries](https://github.com/ocaml-batteries-team/batteries-included.git)
87
* [Lwt](http://ocsigen.org/lwt/install) (optional)
98

109
## Quick start

_oasis

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Library redis
1313
Pack: true
1414
Modules: Redis_sync
1515
InternalModules: Client, Cache, Mutex, Make
16-
BuildDepends: batteries, uuidm
16+
BuildDepends: re.str, uuidm
1717

1818
Flag lwt
1919
Description: Build the Lwt client
@@ -41,13 +41,13 @@ Executable redis_examples
4141
BuildDepends: threads, core, redis, redis_lwt, lwt.unix, lwt
4242

4343
Executable test
44-
Path: test
45-
BuildTools: ocamlbuild
46-
MainIs: test.ml
47-
BuildDepends: lwt, lwt.unix, oUnit, redis
48-
Install: false
49-
Build$: flag(tests)
44+
Path: test
45+
BuildTools: ocamlbuild
46+
MainIs: test.ml
47+
BuildDepends: lwt, lwt.unix, oUnit, redis
48+
Install: false
49+
Build$: flag(tests)
5050

5151
Test main
52-
Run$: flag(tests)
53-
Command: $test
52+
Run$: flag(tests)
53+
Command: $test

_tags

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# OASIS_START
2-
# DO NOT EDIT (digest: e7c0f94fa6df599a02800c8237d35a94)
2+
# DO NOT EDIT (digest: a879416111424ed1672bec0da78d5ff1)
33
# Ignore VCS directories, you can use the same kind of rule outside
44
# OASIS_START/STOP if you want to exclude directories that contains
55
# useless stuff for the build process
@@ -23,39 +23,39 @@ true: annot, bin_annot
2323
"src/make.cmx": for-pack(Redis)
2424
# Library redis_lwt
2525
"src/redis_lwt.cmxs": use_redis_lwt
26-
<src/*.ml{,i,y}>: pkg_batteries
2726
<src/*.ml{,i,y}>: pkg_lwt
2827
<src/*.ml{,i,y}>: pkg_lwt.unix
28+
<src/*.ml{,i,y}>: pkg_re.str
2929
<src/*.ml{,i,y}>: pkg_uuidm
3030
<src/*.ml{,i,y}>: use_redis
3131
# Executable redis_examples
32-
<examples/examples.{native,byte}>: pkg_batteries
3332
<examples/examples.{native,byte}>: pkg_core
3433
<examples/examples.{native,byte}>: pkg_lwt
3534
<examples/examples.{native,byte}>: pkg_lwt.unix
35+
<examples/examples.{native,byte}>: pkg_re.str
3636
<examples/examples.{native,byte}>: pkg_redis_lwt
3737
<examples/examples.{native,byte}>: pkg_threads
3838
<examples/examples.{native,byte}>: pkg_uuidm
3939
<examples/examples.{native,byte}>: use_redis
40-
<examples/*.ml{,i,y}>: pkg_batteries
4140
<examples/*.ml{,i,y}>: pkg_core
4241
<examples/*.ml{,i,y}>: pkg_lwt
4342
<examples/*.ml{,i,y}>: pkg_lwt.unix
43+
<examples/*.ml{,i,y}>: pkg_re.str
4444
<examples/*.ml{,i,y}>: pkg_redis_lwt
4545
<examples/*.ml{,i,y}>: pkg_threads
4646
<examples/*.ml{,i,y}>: pkg_uuidm
4747
<examples/*.ml{,i,y}>: use_redis
4848
# Executable test
49-
"test/test.byte": pkg_batteries
5049
"test/test.byte": pkg_lwt
5150
"test/test.byte": pkg_lwt.unix
5251
"test/test.byte": pkg_oUnit
52+
"test/test.byte": pkg_re.str
5353
"test/test.byte": pkg_uuidm
5454
"test/test.byte": use_redis
55-
<test/*.ml{,i,y}>: pkg_batteries
5655
<test/*.ml{,i,y}>: pkg_lwt
5756
<test/*.ml{,i,y}>: pkg_lwt.unix
5857
<test/*.ml{,i,y}>: pkg_oUnit
58+
<test/*.ml{,i,y}>: pkg_re.str
5959
<test/*.ml{,i,y}>: pkg_uuidm
6060
<test/*.ml{,i,y}>: use_redis
6161
# OASIS_STOP

setup.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(* setup.ml generated for the first time by OASIS v0.3.1 *)
22

33
(* OASIS_START *)
4-
(* DO NOT EDIT (digest: 797597d926bc254ba8caec885bf4542f) *)
4+
(* DO NOT EDIT (digest: f4efc07f392b077279ce72697adb7b6a) *)
55
(*
66
Regenerated by OASIS v0.4.5
77
Visit http://oasis.forge.ocamlcore.org for more information and
@@ -6917,7 +6917,7 @@ let setup_t =
69176917
bs_compiled_object = Best;
69186918
bs_build_depends =
69196919
[
6920-
FindlibPackage ("batteries", None);
6920+
FindlibPackage ("re.str", None);
69216921
FindlibPackage ("uuidm", None)
69226922
];
69236923
bs_build_tools = [ExternalTool "ocamlbuild"];
@@ -7107,7 +7107,7 @@ let setup_t =
71077107
};
71087108
oasis_fn = Some "_oasis";
71097109
oasis_version = "0.4.5";
7110-
oasis_digest = Some "\015}3'h\012\239\132^\173TOhY\197\196";
7110+
oasis_digest = Some "\150\1632\012\127qS\198\1999]\212?\180\218\023";
71117111
oasis_exec = None;
71127112
oasis_setup_args = [];
71137113
setup_update = false

src/META

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# OASIS_START
2-
# DO NOT EDIT (digest: b056c40693e1e9ada07100e2100493f0)
2+
# DO NOT EDIT (digest: b919e1916716c906859709a7f8f4b98a)
33
version = "0.2"
44
description = "Ocaml bindings for Redis"
5-
requires = "batteries uuidm"
5+
requires = "re.str uuidm"
66
archive(byte) = "redis.cma"
77
archive(byte, plugin) = "redis.cma"
88
archive(native) = "redis.cmxa"

src/cache.ml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
(** A convenience module for writing redis caches *)
2-
open Batteries
32

43
(** Signature to parameterize the cache *)
54
module type S = sig
@@ -23,7 +22,7 @@ module Make(IO : Make.IO)(Client : module type of Client.Make(IO))(S : S) = stru
2322
let key = S.cache_key key in
2423
let data = S.string_of_data data in
2524
set r key data >>= fun () ->
26-
IO.return (Option.may
25+
IO.return (Utils.Option.may
2726
(fun cache_expiration ->
2827
IO.ignore_result (expire r key cache_expiration)
2928
)
@@ -32,7 +31,7 @@ module Make(IO : Make.IO)(Client : module type of Client.Make(IO))(S : S) = stru
3231
let get r key =
3332
let key = S.cache_key key in
3433
get r key >>= fun value ->
35-
IO.return (Option.map S.data_of_string value)
34+
IO.return (Utils.Option.map S.data_of_string value)
3635

3736
let delete r key =
3837
let key = S.cache_key key in

src/client.ml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
33
This has only been tested with Redis 2.2, but will probably work for >= 2.0
44
**)
5-
open Batteries
65

76
(* Make communication module *)
87
module Make(IO : Make.IO) = struct
@@ -217,12 +216,12 @@ module Make(IO : Make.IO) = struct
217216
(* multibulks all of whose entries are not nil *)
218217
let return_no_nil_multibulk reply =
219218
return_bulk_multibulk reply >>= fun list ->
220-
IO.return (List.filter_map identity list)
219+
IO.return (Utils.List.filter_map (fun x -> x) list)
221220

222221
let return_key_value_multibulk reply =
223222
return_bulk_multibulk reply >>= fun list ->
224223
try
225-
IO.return (List.filter_map (function
224+
IO.return (Utils.List.filter_map (function
226225
| (Some k, Some v) -> Some (k, v)
227226
| _ -> None
228227
) (deinterleave list))
@@ -237,9 +236,9 @@ module Make(IO : Make.IO) = struct
237236
let return_info_bulk reply =
238237
return_bulk reply >>= function
239238
| Some b ->
240-
let fields = String.nsplit b "\r\n" in
241-
let fields = List.filter (fun x -> x <> "" && not (String.starts_with x "#") ) fields in
242-
IO.return (List.map (fun f -> String.split f ":") fields)
239+
let fields = Utils.String.nsplit b "\r\n" in
240+
let fields = List.filter (fun x -> x <> "" && not (String.get x 0 = '#')) fields in
241+
IO.return (Utils.List.filter_map (fun f -> Utils.String.split f ":") fields)
243242
| None -> IO.return []
244243

245244
(* generate command for SORT *)
@@ -866,7 +865,7 @@ module Make(IO : Make.IO) = struct
866865

867866
(* Lists the currently active channels. If no pattern is specified, all channels are listed. *)
868867
let pubsub_channels connection channels =
869-
let message = Option.default "*" channels in
868+
let message = Utils.Option.default "*" channels in
870869
let command = ["PUBSUB"; "CHANNELS"; message ] in
871870
send_request connection command >>= return_multibulk
872871

src/utils.ml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
module List = struct
2+
let filter_map f l =
3+
let rec loop l accum =
4+
match l with
5+
| [] -> accum
6+
| hd :: tl ->
7+
match f hd with
8+
| Some x -> loop tl (x :: accum)
9+
| None -> loop tl accum
10+
in
11+
List.rev (loop l [])
12+
end
13+
14+
module String = struct
15+
module Str = Re_str
16+
17+
let nsplit str delim = Str.split (Str.regexp delim) str
18+
19+
let split str delim =
20+
match Str.bounded_split (Str.regexp delim) str 2 with
21+
| a :: b :: [] -> Some (a, b)
22+
| _ -> None
23+
end
24+
25+
module Option = struct
26+
let default d = function
27+
| None -> d
28+
| Some v -> v
29+
30+
let may f = function
31+
| None -> ()
32+
| Some v -> f v; ()
33+
34+
let map f = function
35+
| None -> None
36+
| Some v -> Some (f v)
37+
end

src/utils.mli

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module List : sig
2+
val filter_map : ('a -> 'b option) -> 'a list -> 'b list
3+
end
4+
5+
module String : sig
6+
val nsplit : string -> string -> string list
7+
val split : string -> string -> (string * string) option
8+
end
9+
10+
module Option : sig
11+
val default : 'a -> 'a option -> 'a
12+
val may : ('a -> unit) -> 'a option -> unit
13+
val map : ('a -> 'b) -> 'a option -> 'b option
14+
end

0 commit comments

Comments
 (0)