{"id":18012876,"url":"https://github.com/tonivade/resp-server","last_synced_at":"2025-12-27T16:07:56.417Z","repository":{"id":47094744,"uuid":"45353822","full_name":"tonivade/resp-server","owner":"tonivade","description":"Netty implementation of REdis Serialization Protocol, and a simple framework to implement command based protocols","archived":false,"fork":false,"pushed_at":"2024-10-22T05:49:10.000Z","size":1171,"stargazers_count":59,"open_issues_count":2,"forks_count":16,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-10-30T04:59:56.662Z","etag":null,"topics":["framework","netty","redis","resp"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tonivade.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2015-11-01T19:17:31.000Z","updated_at":"2024-10-22T05:49:06.000Z","dependencies_parsed_at":"2023-11-30T22:24:17.372Z","dependency_job_id":"31a536f7-4c49-44d3-8bd8-4a891b3afefe","html_url":"https://github.com/tonivade/resp-server","commit_stats":null,"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tonivade%2Fresp-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tonivade%2Fresp-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tonivade%2Fresp-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tonivade%2Fresp-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tonivade","download_url":"https://codeload.github.com/tonivade/resp-server/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247601448,"owners_count":20964864,"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":["framework","netty","redis","resp"],"created_at":"2024-10-30T03:19:22.311Z","updated_at":"2025-12-27T16:07:56.379Z","avatar_url":"https://github.com/tonivade.png","language":"Java","readme":"# resp-server\n\nNetty implementation of REdis Serialization Protocol, and a simple framework to implement command based protocols.\n\n## Why?\n\nI love REDIS, IMHO is one of the best pieces of code ever made. Is fast, small\nand easy. One of the things I love of REDIS is the RESP protocol, and I think that\nit would be nice to build a library to implement services using this protocol. I\nhave to say that this piece of code is based in another project I'm working \n[ClauDB](https://github.com/tonivade/claudb).\n\n## What?\n\n[RESP](http://redis.io/topics/protocol) is the protocol used by REDIS, but it\ncan be used to implement other client-server protocols.\n\nIt's nice because:\n\n- Is easy\n- Is fast\n- Also is human readable\n\nRESP can serialize some data types\n\n- simple strings: `+PONG\\r\\n`\n- errors: `-ERROR\\r\\n`\n- integers: `:1\\r\\n`\n- bulk strings (binary-safe): `$4\\r\\nPING\\r\\n`\n- arrays: `*3\\r\\n:1\\r\\n:2\\r\\n:3\\r\\n`\n\nWhat binary safe means? It means that can be what ever you want, a UTF-8 String\nor compressed data, a picture, etc...\n\nArrays can hold any data types inside, also other arrays.\n\nAnd use `\\r\\n` as delimiter, that means you can open a `telnet/netcat/nc` against\nthe server port and send whatever you want.\n\nSo, what provide this project in addition to the protocol implementation? Well,\nit defines a framework to implement command oriented protocols.\n\nYou only need to define a set of commands and implement them.\n\nSome commands are built-in, `ping`, `echo`, `time` and `quit`.\n\n## What is a command?\n\nA command is an array of bulk string in RESP, first element in array is the command, \nand the additional elements are the parameters of the command. This is how a command\nlooks like:\n\n```\n    *2\\r\\n\n    $4\\r\\n\n    ECHO\\r\\n\n    $13\\r\\n\n    Hello World!\\r\\n\n```\n\nIn this sample, `ECHO` is the command and `Hello world!` is the parameter.\n\n## How is implemented?\n\nThe protocol is implemented in Java8, using asynchronous IO ([netty](https://netty.io/)), and using the\nreactive programming paradigm ([rxjava](http://www.rxjava.com/)). What that means? It means that is single\nthread, every request is managed inside the same thread, so there's no concurrency\nissues at all, the same way as REDIS works.\n\n## How can I use it?\n\nIt's very easy, you only need 2 lines of code to start the server\n\n```java\n    RespServer server = RespServer.builder()\n      .host(\"localhost\").port(12345).commands(new CommandSuite()).build();\n    server.start();\n```\n\nCommandSuite is the default commands suite but you can extend and add your own commands,\nwell, that's the point :)\n\nWhat a command looks like?\n\n```java\n    @Command(\"ping\")\n    public class PingCommand implements RespCommand {\n        @Override\n        public RedisToken execute(Request request) {\n            return RedisToken.status(\"PONG\");\n        }\n    }\n```\n    \nA command must implement the interface `RespCommand`. This interface only defines\nthe method `execute`, who receives a `Request` object and returns a `RedisToken`.\n\nYou can get the parameter of the command like this\n\n```java\n    SafeString param0 = request.getParam(0);\n```\n    \nEvery parameter is a `SafeString`, and what the hell is a `SafeString`? Previously,\nwe said that RESP is binary-safe, so, it means that you can receive anything. `SafeString`\nwraps the bytes received, but, don't worry, it's not going to be a problem, trust me.\n\nAnd you can response to a request this way:\n\n```java\n    return RedisToken.status(\"PONG\");\n```\n    \nYou have similar methods like `array`, `integer`, `string`, `error`...\n\nAnnotations are used to define some metadata to the commands, `@Command` annotation\ndefines the command name, also there's another annotation, `@ParamLength` to define\nthe number of the parameter accepted for this command\n\n```java\n    @Command(\"echo\")\n    @ParamLength(1)\n    public class EchoCommand implements RespCommand {\n        @Override\n        public RedisToken execute(Request request) {\n            return RedisToken.string(request.getParam(0));\n        }\n    }\n```\n    \nIf the number of parameters is less than the especified value, the command\nis rejected with an error.\n\n## Maven\n\n    \u003cdependency\u003e\n        \u003cgroupId\u003ecom.github.tonivade\u003c/groupId\u003e\n        \u003cartifactId\u003eresp-server\u003c/artifactId\u003e\n        \u003cversion\u003e0.24.0\u003c/version\u003e\n    \u003c/dependency\u003e\n\n## Gradle\n\n    compile 'com.github.tonivade:resp-server:0.24.0'\n    \n## Stargazers over time\n\n[![Stargazers over time](https://starchart.cc/tonivade/resp-server.svg)](https://starchart.cc/tonivade/resp-server)\n\n## Continuous Integration\n\n[![Build Status](https://api.travis-ci.org/tonivade/resp-server.svg?branch=master)](https://travis-ci.org/tonivade/resp-server)\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/47b2b3213b7248eca911e4783ed6d031)](https://www.codacy.com/app/tonivade/resp-server?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=tonivade/resp-server\u0026amp;utm_campaign=Badge_Grade)\n[![Codacy Coverage](https://api.codacy.com/project/badge/Coverage/47b2b3213b7248eca911e4783ed6d031)](https://www.codacy.com/app/tonivade/resp-server?utm_source=github.com\u0026utm_medium=referral\u0026utm_content=tonivade/resp-server\u0026utm_campaign=Badge_Coverage)\n\n## LICENSE\n\nThis project is released under MIT License\n","funding_links":[],"categories":["网络编程"],"sub_categories":["Spring Cloud框架"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftonivade%2Fresp-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftonivade%2Fresp-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftonivade%2Fresp-server/lists"}