{"id":13483740,"url":"https://github.com/amakawa/redic","last_synced_at":"2025-03-27T15:30:30.369Z","repository":{"id":7833925,"uuid":"9205349","full_name":"amakawa/redic","owner":"amakawa","description":"Lightweight Redis Client","archived":false,"fork":false,"pushed_at":"2019-08-09T07:47:27.000Z","size":63,"stargazers_count":120,"open_issues_count":2,"forks_count":14,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-16T23:35:56.392Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/amakawa.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":"CONTRIBUTING","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-04-03T21:25:14.000Z","updated_at":"2024-08-18T07:07:24.000Z","dependencies_parsed_at":"2022-08-28T04:21:16.293Z","dependency_job_id":null,"html_url":"https://github.com/amakawa/redic","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amakawa%2Fredic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amakawa%2Fredic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amakawa%2Fredic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amakawa%2Fredic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amakawa","download_url":"https://codeload.github.com/amakawa/redic/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245871682,"owners_count":20686246,"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":[],"created_at":"2024-07-31T17:01:14.773Z","updated_at":"2025-03-27T15:30:29.960Z","avatar_url":"https://github.com/amakawa.png","language":"Ruby","funding_links":[],"categories":["Ruby","Database Drivers"],"sub_categories":[],"readme":"Redic\n=====\n\nLightweight Redis Client\n\nDescription\n-----------\n\nLightweight Redis Client inspired by [redigo][redigo], a Redis\nclient library for golang.\n\n## Usage\n\n```ruby\n# Accepts a Redis URL and defaults to \"redis://127.0.0.1:6379\".\nredis = Redic.new\n\n# Processes the command and returns the response.\nredis.call(\"SET\", \"foo\", \"bar\")\n\nassert_equal \"bar\", redis.call(\"GET\", \"foo\")\n\n# Pipelining is implemented by buffering commands,\n# then calling Redic#commit\nredis.queue(\"SET\", \"foo\", \"bar\")\nredis.queue(\"GET\", \"foo\")\n\nassert_equal [\"OK\", \"bar\"], redis.commit\n```\n\nYou can provide the password and the database to be selected. The\nformat for Redis URLs is `redis://user:pass@host:port/db`. As\nRedis only needs a password for authentication, the user can be\nomitted:\n\n```ruby\n# Connect to localhost:6380 using \"bar\" as password and use the\n# database 2. Both AUTH and SELECT commands are issued after\n# connecting. The user part of the URL is not provided.\nredis = Redic.new(\"redis://:bar@localhost:6380/2\")\n```\n\nIt is also possible to configure a timeout for the connection. The\ndefault timeout is 10 seconds.\n\n```ruby\n# Timeout expressed in microseconds.\nredis = Redic.new(REDIS_URL, 2_000_000)\nredis.timeout == 2_000_000 #=\u003e true\n```\nA client can be re-configured, forcing the next connection to\nbe established with the new details:\n\n```ruby\nredis = Redic.new(\"redis://localhost:6379\")\nredis.configure(\"redis://localhost:6380\")\n```\n\nHere's one final example using both a Redis URL and a timeout:\n\n```ruby\n# It's recommended to store the REDIS_URL as an environment\n# variable. Use `fetch` to retrieve values that must be present,\n# as it raises an error if the value is not found.\nREDIS_URL = ENV.fetch(\"REDIS_URL\")\nREDIS_TIMEOUT = ENV.fetch(\"REDIS_TIMEOUT\")\n\nredis = Redic.new(REDIS_URL, REDIS_TIMEOUT)\n```\n\nBoth the initializer and the `configure` method accept a `URL` and\na `timeout`.\n\nIn order to close the connection, call `quit`:\n\n```ruby\nredis = Redic.new(\"redis://localhost:6379\")\nredis.quit\n```\n\nWith that command, `\"QUIT\"` is sent to Redis and the socket is closed.\n\n## Differences with redis-rb\n\nRedic uses [hiredis][hiredis] for the connection and for parsing\nthe replies. There are no alternative connection drivers. Unlike\n[redis-rb][redis-rb] it doesn't define all the Redis commands, and\ninstead it acts as a transport layer. The lock provided is smaller\nthan that of redis-rb, as it only wraps the writing and reading from\nthe connection. So even if both clients are thread-safe by default,\nthe peformance of a smaller lock is marginally better.\n\n[redigo]: https://github.com/garyburd/redigo\n[hiredis]: https://github.com/pietern/hiredis-rb\n[redis-rb]: https://github.com/redis/redis-rb\n\n## Limitations\n\nWhen a client enters a subscribed mode, further reads to retrieve the\nmessages are not thread safe. It is very important to take this into\naccount and to create a different client if you need to send different\noperations while a client is subscribed to a channel.\n\n```ruby\n# Example of pub/sub usage.\nc1 = Redic.new\nc2 = Redic.new\n\n# After this command, the client is no longer thread safe.\nc1.call(\"SUBSCRIBE\", \"foo\")\n\n# That's why we need to publish from a different connection.\nc2.call(\"PUBLISH\", \"foo\")\n\n# Note that this operation is not thread safe.\nassert_equal [\"message\", \"foo\", \"value1\"], c1.client.read\n```\n\nYou can wrap thread unsafe operations in a mutex:\n\n```ruby\nredis = Redic.new\n\nmutex = Mutex.new\n\nmutex.synchronize do\n  redis.call(\"MONITOR\")\n\n  # Display every command sent to Redis.\n  loop do\n    puts redis.client.read\n  end\nend\n```\n\n## Installation\n\nYou can install it using rubygems.\n\n```\n$ gem install redic\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famakawa%2Fredic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famakawa%2Fredic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famakawa%2Fredic/lists"}