{"id":22220885,"url":"https://github.com/nokia/wiredis","last_synced_at":"2025-09-05T10:34:09.685Z","repository":{"id":69250274,"uuid":"156178003","full_name":"nokia/wiredis","owner":"nokia","description":"A C++ client for Redis (https://redis.io/)","archived":false,"fork":false,"pushed_at":"2020-08-06T14:01:15.000Z","size":25,"stargazers_count":9,"open_issues_count":3,"forks_count":3,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-04T04:11:28.659Z","etag":null,"topics":["redis"],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nokia.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,"zenodo":null}},"created_at":"2018-11-05T07:35:03.000Z","updated_at":"2025-03-07T01:44:10.000Z","dependencies_parsed_at":"2023-02-24T01:00:18.826Z","dependency_job_id":null,"html_url":"https://github.com/nokia/wiredis","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nokia/wiredis","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nokia%2Fwiredis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nokia%2Fwiredis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nokia%2Fwiredis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nokia%2Fwiredis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nokia","download_url":"https://codeload.github.com/nokia/wiredis/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nokia%2Fwiredis/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267386682,"owners_count":24079065,"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","status":"online","status_checked_at":"2025-07-27T02:00:11.917Z","response_time":82,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["redis"],"created_at":"2024-12-02T23:10:47.682Z","updated_at":"2025-07-30T16:33:03.798Z","avatar_url":"https://github.com/nokia.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# wiredis\nwiredis is a header-only, asynchronous c++11 client library for [redis](http://redis.io/) database server.\n\nIt depends only on [boost](https://www.boost.org/) library and uses [::boost::asio::io_service](https://www.boost.org/doc/libs/1_51_0/doc/html/boost_asio/reference/io_service.html) as event handler.\n\nTested on\n- Arch linux\n  - cmake 3.11.4\n  - g++ 8.1.1\n  - boost 1.67\n- Redhat\n  - cmake 3.12.0\n  - g++ 4.8.5\n  - boost 1.68\n\n## Compile and install\n\n```\n$ mkdir build \u0026\u0026 cd build \u0026\u0026 cmake ../ \u0026\u0026 sudo make install\n```\n\n## Features\n\n- Asynchronous interface\n- Standalone: depends only on [boost](https://www.boost.org) library.\n- Auto reconnect\n- TCP keepalive on idle connection\n- Exact match with redis commands without inner logic\n- Binary key/values\n- PUB/SUB mode\n\n## Usage\n\nYou can find working examples under [examples](examples/) folder and full documention below in this document.\n\nFirst of all you need a running ::boost::asio::io_service instance.\n\n```\n    ::boost::asio::io_service ios;\n    bool loop_condition = true;\n    std::thread scheduler_thread(\n        [\u0026]\n        {\n            while (loop_condition)\n            {\n                ios.reset();\n                ios.run();\n                std::this_thread::sleep_for(std::chrono::milliseconds(10));\n            }\n        });\n```\n\n...then create a `::nokia::net::redis_connection` instance:\n\n```\n    ::nokia::net::redis_connection con(ios);\n\n    con.connect(\"127.0.0.1\",\n                6379,\n                [] (boost::system::error_code const \u0026 error)\n                {\n                    if (error)\n                    {\n                        std::cout \u003c\u003c \"Connect failed. Keep trying...\" \u003c\u003c std::endl;\n                    }\n                    else\n                    {\n                        std::cout \u003c\u003c \"Connected!\" \u003c\u003c std::endl;\n                    }\n                },\n                [\u0026] (boost::system::error_code const \u0026 ec)\n                {\n                    std::cout \u003c\u003c \"Connection lost. Error core: \" \u003c\u003c ec \u003c\u003c \". Reconnecting...\"\u003c\u003c std::endl;\n                });\n```\n\nOnce the connection established you can start working on the connection.\nTo send a command to redis-server you need to invoke `execute()` function with a callback function, the command and the arguments of the command.\n\n```\n    con.execute([\u0026] (::nokia::net::proto::redis::reply \u0026\u0026 reply)\n                {\n                    if (::nokia::net::proto::redis::reply::NIL == reply.type)\n                    {\n                        std::cout \u003c\u003c \"Key not found\" \u003c\u003c std::endl;\n                    }\n                    else\n                    {\n                        std::cout \u003c\u003c \"Key found. Value:\" \u003c\u003c reply.str \u003c\u003c std::endl;\n                    }\n                },\n                \"GET\", \"key\");\n\n```\n\nIf you use multiple arguments you need to separate them:\n\n```\n    con.execute([\u0026] (::nokia::net::proto::redis::reply \u0026\u0026 reply)\n                {\n                    if (::nokia::net::proto::redis::reply::NIL == reply.type)\n                    {\n                        std::cout \u003c\u003c \"Key not found\" \u003c\u003c std::endl;\n                    }\n                    else\n                    {\n                        std::cout \u003c\u003c \"Key found. Value:\" \u003c\u003c reply.str \u003c\u003c std::endl;\n                    }\n                },\n                \"HSET\", \"key\", \"field\", \"value\");\n```\n\nReturn object has type `::nokia::net::proto::redis::reply \u0026\u0026` which follows the [RESP](https://redis.io/topics/protocol) definition.\n\n```\n    struct reply\n    {\n        enum type\n        {\n            INVALID, // [w] only for debugging purpose\n            STRING,\n            INTEGER,\n            ARRAY,\n            NIL,\n            ERROR\n        };\n        \n        type type;\n        \n        std::string str;\n        int64_t integer;\n\n        std::vector\u003creply\u003e elements;\n    };\n```\n\nTo close your connection you need to use `join()` function.\n\n```\n    con.disconnect();\n    con.join([] ()\n             {\n                 std::cout \u003c\u003c \"Cleanup done, we can die now.\" \u003c\u003c std::endl;\n             });\n```\n\nAlternatively, you can use `sync_join()` function but be warned: it uses the `io_service` object so never call from thread being run by your `io_service` object!\n\n## [PUB/SUB](https://redis.io/topics/pubsub) mode\n\nYou can use redis connection to watch a given channel.\n\nNote: once you switch to [PUB/SUB](https://redis.io/topics/pubsub) mode you can't use the conncetion for standard operations. Allowed commands in PUB/SUB mode: SUBSCRIBE, PSUBSCRIBE, UNSUBSCRIBE, PUNSUBSCRIBE, PING and QUIT.\n\n```\n    con.subscribe(\"my-channel\",\n                  [\u0026] ()\n                  {\n                      std::cout \u003c\u003c \"subscribed for channel \\\"my-channel\\\"\" \u003c\u003c std::endl;\n                  },\n                  [] (std::string const \u0026 channel, std::string const \u0026 message)\n                  {\n                      std::cout \u003c\u003c \"* Just get a message on channel \\\"\" \u003c\u003c channel \u003c\u003c \"\\\": \" \u003c\u003c message \u003c\u003c std::endl;\n                  },\n                  [\u0026] ()\n                  {\n                      std::cout \u003c\u003c \"* Unsubscribed from channel \\\"my-channel\\\"\" \u003c\u003c std::endl;\n                  });\n```\n\n## Documentation\n\n### redis_connection()\n```\nredis_connection(boost::asio::io_service \u0026 io_service);\n```\nSimply constructor to create redis_connection object.\n- io_service: The `::boost::asio::io_service` you want to use for event handler.\n\n\n### connect()\n\n```\nvoid connect(std::string const \u0026 ip,\n             uint16_t port,\n             std::function\u003cvoid (boost::system::error_code const \u0026)\u003e connected_callback,\n             std::function\u003cvoid (boost::system::error_code const \u0026)\u003e disconnected_callback,\n             bool auto_reconnect = true,\n             bool keepalive_enabled = true);\n```\nInitiate connecting to redis-server.\n- ip: ip address of redis server.\n- port: port of redis server.\n- connected_callback: this function will be called every time the client connects to the server including reconnecting.\n- disconnected_callback: this function will be called if the client losts conncection to server excluding the disconnect() function call.\n- auto_reconnect: if it's true the client tries to reconnect to the server. After reconncection the connection is in standard mode, you lose every previous subscriptions.\n- keepalive_enabled: if it's true the connection uses TCP keepaliving. The settings are\n  - TCP_KEEPIDLE: 2\n  - TCP_KEEPINTVL: 2\n  - TCP_KEEPCNT: 3\n\n\n### connected()\n```\nbool connected() const;\n```\nReturns true if the connection is established.\n\n\n### disconnect()\n```\nvoid disconnect();\n```\nDisconnect from redis server. Always use this function if you want tear-down, it performs clean-up.\n\n\n### join(), sync_join()\n```\nvoid join(std::function\u003cvoid ()\u003e cb);\nvoid sync_join();\n```\nWaits for clean-up. The first version calls back once the clean-up has finished, while the second version blocks.\n\nNote: `snyc_join()` uses the `io_service` object so never call from thread being run by your `io_service` object!\n\n\n### execute()\n```\ntemplate \u003ctypename... Ts\u003e\nvoid execute(std::function\u003cvoid (::nokia::net::proto::redis::reply \u0026\u0026)\u003e callback, Ts \u0026\u0026... ts);\n```\nInvoke redis command. The execution and return value are same as redis defines, there is no inner logic. See: https://redis.io/commands\n\nBinary arguments are supported.\n\n- callback: this function will be called with the result.\n- ts: redis command and its arguments.\n\n\n### subscribe(), psusbscribe()\n```\nvoid subscribe(std::string const \u0026 channel,\n               std::function\u003cvoid ()\u003e subscribed_callback,\n               std::function\u003cvoid (std::string const \u0026 channel, std::string const \u0026 message)\u003e change_callback,\n               std::function\u003cvoid ()\u003e unsubscribed_callback);\nvoid psubscribe(std::string const \u0026 pattern,\n                std::function\u003cvoid ()\u003e subscribed_callback,\n                std::function\u003cvoid (std::string const \u0026 pattern, std::string const \u0026 channel, std::string const \u0026 message)\u003e pattern_change_callback,\n                std::function\u003cvoid ()\u003e unsubscribed_callback);\n```\nSubscribe for a given channel/channel matches with the pattern.\nIf you already subscribed for a channel you will get `subscription_already_exists` exception.\n- channel/pattern: the channel/pattern of channel you want to subscribe.\n- subscribed_callback: this function will be called once the subscription is ready.\n- change_callback: this function will be called if new message arrives on the subscribed channel.\n- unsubscribed_callback: this function will be called if you've successfully unsubscribed from the channel.\n\n\n### unsubscribe(), punsubscribe()\n```\nvoid unsubscribe(std::string const \u0026 channel);\nvoid punsubscribe(std::string const \u0026 pattern);\n```\n\nUnsubscribe from a previously subscribed channel/pattern of channel.\nIf the subscription doesn't exist you'll get a `subscription_does_not_exist` exception.\n- channel/pattern: the channel/pattern of channel you want to unsubscribe from.\n\n\n### set_log_callback()\n```\nvoid set_log_callback(std::function\u003cvoid (std::string const \u0026)\u003e cb);\n```\nThe logs are printed out to stdout by default. If you want to handle by your own, you need to call this function with your callback function.\n\n\n## Tests\n\nTo run unit tests, you need to have installed valgrind, redis-server and need to use Debug configuration.\n\nTests start/stop redis-server, so turn off redis-server if it runs: systemctl stop redis\n\n```\nmkdir build\ncd build\ncmake ../ -G Ninja -DCMAKE_BUILD_TYPE=Debug\nninja\nctest  -T memcheck\n```\n\n\n## License\n\nThis project is licensed under the BSD-3-Clause license - see the [LICENSE](https://github.com/nokia/wiredis/blob/master/LICENSE).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnokia%2Fwiredis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnokia%2Fwiredis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnokia%2Fwiredis/lists"}