{"id":16743954,"url":"https://github.com/zshipko/resp-server","last_synced_at":"2025-06-13T07:06:16.492Z","repository":{"id":79821380,"uuid":"127395498","full_name":"zshipko/resp-server","owner":"zshipko","description":"An OCaml library for building servers that speak RESP","archived":false,"fork":false,"pushed_at":"2018-09-13T02:20:27.000Z","size":48,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-10T14:02:43.206Z","etag":null,"topics":["ocaml","redis-protocol"],"latest_commit_sha":null,"homepage":"","language":"OCaml","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zshipko.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-30T07:18:28.000Z","updated_at":"2018-09-13T02:20:28.000Z","dependencies_parsed_at":null,"dependency_job_id":"2e9539a7-6ecb-4a30-9271-831e234cbd4a","html_url":"https://github.com/zshipko/resp-server","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/zshipko/resp-server","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zshipko%2Fresp-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zshipko%2Fresp-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zshipko%2Fresp-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zshipko%2Fresp-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zshipko","download_url":"https://codeload.github.com/zshipko/resp-server/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zshipko%2Fresp-server/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259599331,"owners_count":22882357,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ocaml","redis-protocol"],"created_at":"2024-10-13T01:42:04.027Z","updated_at":"2025-06-13T07:06:16.451Z","avatar_url":"https://github.com/zshipko.png","language":"OCaml","funding_links":[],"categories":[],"sub_categories":[],"readme":"resp-server — Servers that communicate using the Redis serialization protocol\n-------------------------------------------------------------------------------\n%%VERSION%%\n\nresp-server is an OCaml library for building servers that communicate using the [Redis serialization protocol](https://redis.io/topics/protocol).\n\nresp-server is distributed under the ISC license.\n\nHomepage: https://github.com/zshipko/resp-server\n\n## Installation\n\nresp-server can be installed with `opam`:\n\n    opam install resp-server\n\nIf you don't use `opam` consult the [`opam`](opam) file for build instructions.\n\n## Documentation\n\nDocumentation is available [online](https://zshipko.github.io/resp-server).\n\nTo generate documentation locally run `odig odoc resp-server` - then to view run `odig doc` in the root of the project.\n\nSee `src/resp_server.mli` for the commented interface description.\n\n## Getting started\n\nTo create a new server using `resp-server` you need to define a few modules.\n\nAs an example we can create a simple counter server that has keys with integer values that can be incremented and decremented:\n\n1) `BACKEND` - defines the request context and client types\n\n```ocaml\nmodule Backend = struct\n    (** This is the global request context type *)\n    type t = (string, int) Hashtbl.t\n\n    (** The client type is the per-client request context type *)\n    type client = unit\n\n    let new_client _ctx = ()\nend\n```\n\n2) `AUTH` - defines authentication types\n\n```ocaml\nmodule Auth = struct\n    type t = string\n    let check t cmd =\n        Array.length cmd \u003e 0 \u0026\u0026 cmd.(0) = t\nend\n```\n\n3) Use `Make` to create the new server\n\n```ocaml\nmodule Server = Make(Auth)(Backend)\n```\n\n4) Define some commands\n\n```ocaml\nlet modify_value db args f =\n    match args with\n    | [| String key |] -\u003e\n        let () =\n            match Hashtbl.find_opt srv key with\n            | Some i -\u003e Hashtbl.replace srv key (f i)\n            | None -\u003e Hashtbl.replace srv key (f 0)\n        in\n        Server.ok\n    | _ -\u003e Server.error \"Invalid arguments\"\n\nlet _incr db _cli _cmd args =\n    modify_value db args (fun a -\u003e a + 1)\n\nlet _decr db _cli _cmd args =\n    modify_value db args (fun a -\u003e a - 1)\n\nlet commands = [\n    \"incr\", _incr;\n    \"decr\", _decr;\n]\n```\n\n4) Create and run the server\n\n```ocaml\nlet main =\n    let db = Hashtbl.create 16 in\n    let auth = \"password\" in\n    let srv = Server.create ~auth ~commands (`TCP (`Port 1234)) db in\n    Server.run srv\n\nlet () = Lwt_main.run main\n```\n\n## Tests\n\nIn the distribution sample programs and tests are located in the\n[`test`](test) directory. They can be built and run with:\n\n    jbuilder runtest\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzshipko%2Fresp-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzshipko%2Fresp-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzshipko%2Fresp-server/lists"}