[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-7794":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":17,"stars30d":18,"stars90d":16,"forks30d":16,"starsTrendScore":17,"compositeScore":19,"rankGlobal":10,"rankLanguage":10,"license":20,"archived":21,"fork":21,"defaultBranch":22,"hasWiki":23,"hasPages":21,"topics":24,"createdAt":10,"pushedAt":10,"updatedAt":25,"readmeContent":26,"aiSummary":27,"trendingCount":16,"starSnapshotCount":16,"syncStatus":28,"lastSyncTime":29,"discoverSource":30},7794,"redis-rb","redis\u002Fredis-rb","redis","A Ruby client library for Redis","",null,"Ruby",4000,1027,76,19,0,1,12,31.04,"MIT License",false,"master",true,[],"2026-06-12 02:01:44","# redis-rb [![Build Status][gh-actions-image]][gh-actions-link] [![Inline docs][rdoc-master-image]][rdoc-master-link]\n\nA Ruby client that tries to match [Redis][redis-home]' API one-to-one, while still providing an idiomatic interface.\n\nSee [RubyDoc.info][rubydoc] for the API docs of the latest published gem.\n\n## Getting started\n\nInstall with:\n\n```\n$ gem install redis\n```\n\nYou can connect to Redis by instantiating the `Redis` class:\n\n```ruby\nrequire \"redis\"\n\nredis = Redis.new\n```\n\nThis assumes Redis was started with a default configuration, and is\nlistening on `localhost`, port 6379. If you need to connect to a remote\nserver or a different port, try:\n\n```ruby\nredis = Redis.new(host: \"10.0.1.1\", port: 6380, db: 15)\n```\n\nYou can also specify connection options as a [`redis:\u002F\u002F` URL][redis-url]:\n\n```ruby\nredis = Redis.new(url: \"redis:\u002F\u002F:p4ssw0rd@10.0.1.1:6380\u002F15\")\n```\n\nThe client expects passwords with special characters to be URL-encoded (i.e.\n`CGI.escape(password)`).\n\nTo connect to Redis listening on a Unix socket, try:\n\n```ruby\nredis = Redis.new(path: \"\u002Ftmp\u002Fredis.sock\")\n```\n\nTo connect to a password protected Redis instance, use:\n\n```ruby\nredis = Redis.new(password: \"mysecret\")\n```\n\nTo connect a Redis instance using [ACL](https:\u002F\u002Fredis.io\u002Ftopics\u002Facl), use:\n\n```ruby\nredis = Redis.new(username: 'myname', password: 'mysecret')\n```\n\nThe Redis class exports methods that are named identical to the commands\nthey execute. The arguments these methods accept are often identical to\nthe arguments specified on the [Redis website][redis-commands]. For\ninstance, the `SET` and `GET` commands can be called like this:\n\n```ruby\nredis.set(\"mykey\", \"hello world\")\n# => \"OK\"\n\nredis.get(\"mykey\")\n# => \"hello world\"\n```\n\nAll commands, their arguments, and return values are documented and\navailable on [RubyDoc.info][rubydoc].\n\n## Connection Pooling and Thread safety\n\nThe client does not provide connection pooling. Each `Redis` instance\nhas one and only one connection to the server, and use of this connection\nis protected by a mutex.\n\nAs such it is heavily recommended to use the [`connection_pool` gem](https:\u002F\u002Fgithub.com\u002Fmperham\u002Fconnection_pool), e.g.:\n\n```ruby\nmodule MyApp\n  def self.redis\n    @redis ||= ConnectionPool::Wrapper.new do\n      Redis.new(url: ENV[\"REDIS_URL\"])\n    end\n  end\nend\n\nMyApp.redis.incr(\"some-counter\")\n```\n\n## Sentinel support\n\nThe client is able to perform automatic failover by using [Redis\nSentinel](http:\u002F\u002Fredis.io\u002Ftopics\u002Fsentinel). Make sure to run Redis 2.8+\nif you want to use this feature.\n\nTo connect using Sentinel, use:\n\n```ruby\nSENTINELS = [{ host: \"127.0.0.1\", port: 26380 },\n             { host: \"127.0.0.1\", port: 26381 }]\n\nredis = Redis.new(name: \"mymaster\", sentinels: SENTINELS, role: :master)\n```\n\n* The master name identifies a group of Redis instances composed of a master\nand one or more slaves (`mymaster` in the example).\n\n* It is possible to optionally provide a role. The allowed roles are `master`\nand `slave`. When the role is `slave`, the client will try to connect to a\nrandom slave of the specified master. If a role is not specified, the client\nwill connect to the master.\n\n* When using Sentinel support, you need to specify a list of sentinels to\nconnect to. The list does not need to enumerate all your Sentinel instances,\nbut a few so that if one is down the client will try the next one. The client\nis able to remember the last Sentinel that was able to reply correctly and will\nuse it for the next request.\n\nTo [authenticate](https:\u002F\u002Fredis.io\u002Fdocs\u002Fmanagement\u002Fsentinel\u002F#configuring-sentinel-instances-with-authentication) with Sentinel itself, you can specify the `sentinel_username` and `sentinel_password`. Exclude the `sentinel_username` option if you're using password-only authentication.\n\n```ruby\nSENTINELS = [{ host: '127.0.0.1', port: 26380},\n             { host: '127.0.0.1', port: 26381}]\n\nredis = Redis.new(name: 'mymaster', sentinels: SENTINELS, sentinel_username: 'appuser', sentinel_password: 'mysecret', role: :master)\n```\n\nIf you specify a username and\u002For password at the top level for your main Redis instance, Sentinel *will not* use those credentials.\n\n```ruby\n# Use 'mysecret' to authenticate against the mymaster instance, but skip authentication for the sentinels:\nSENTINELS = [{ host: '127.0.0.1', port: 26380 },\n             { host: '127.0.0.1', port: 26381 }]\n\nredis = Redis.new(name: 'mymaster', sentinels: SENTINELS, role: :master, password: 'mysecret')\n```\n\nSo you have to provide Sentinel credentials and Redis explicitly even if they are the same.\n\n```ruby\n# Use 'mysecret' to authenticate against the mymaster instance and sentinel\nSENTINELS = [{ host: '127.0.0.1', port: 26380 },\n             { host: '127.0.0.1', port: 26381 }]\n\nredis = Redis.new(name: 'mymaster', sentinels: SENTINELS, role: :master, password: 'mysecret', sentinel_password: 'mysecret')\n```\n\nAlso, the `name`, `password`, `username`, and `db` for the Redis instance can be passed as a URL:\n\n```ruby\nredis = Redis.new(url: \"redis:\u002F\u002Fappuser:mysecret@mymaster\u002F10\", sentinels: SENTINELS, role: :master)\n```\n\n## Cluster support\n\n[Clustering](https:\u002F\u002Fredis.io\u002Ftopics\u002Fcluster-spec). is supported via the [`redis-clustering` gem](cluster\u002F).\n\n## Pipelining\n\nWhen multiple commands are executed sequentially, but are not dependent,\nthe calls can be *pipelined*. This means that the client doesn't wait\nfor reply of the first command before sending the next command. The\nadvantage is that multiple commands are sent at once, resulting in\nfaster overall execution.\n\nThe client can be instructed to pipeline commands by using the\n`#pipelined` method. After the block is executed, the client sends all\ncommands to Redis and gathers their replies. These replies are returned\nby the `#pipelined` method.\n\n```ruby\nredis.pipelined do |pipeline|\n  pipeline.set \"foo\", \"bar\"\n  pipeline.incr \"baz\"\nend\n# => [\"OK\", 1]\n```\n\nCommands must be called on the yielded objects. If you call methods\non the original client objects from inside a pipeline, they will be sent immediately:\n\n```ruby\nredis.pipelined do |pipeline|\n  pipeline.set \"foo\", \"bar\"\n  redis.incr \"baz\" # => 1\nend\n# => [\"OK\"]\n```\n\n### Exception management\n\nThe `exception` flag in the `#pipelined` is a feature that modifies the pipeline execution behavior. When set\nto `false`, it doesn't raise an exception when a command error occurs. Instead, it allows the pipeline to execute all\ncommands, and any failed command will be available in the returned array. (Defaults to `true`)\n\n```ruby\nresults = redis.pipelined(exception: false) do |pipeline|\n  pipeline.set('key1', 'value1')\n  pipeline.lpush('key1', 'something') # This will fail\n  pipeline.set('key2', 'value2')\nend\n# results => [\"OK\", #\u003CRedisClient::WrongTypeError: WRONGTYPE Operation against a key holding the wrong kind of value>, \"OK\"]\n\nresults.each do |result|\n  if result.is_a?(Redis::CommandError)\n    # Do something with the failed result\n  end\nend\n```\n\n\n### Executing commands atomically\n\nYou can use `MULTI\u002FEXEC` to run a number of commands in an atomic\nfashion. This is similar to executing a pipeline, but the commands are\npreceded by a call to `MULTI`, and followed by a call to `EXEC`. Like\nthe regular pipeline, the replies to the commands are returned by the\n`#multi` method.\n\n```ruby\nredis.multi do |transaction|\n  transaction.set \"foo\", \"bar\"\n  transaction.incr \"baz\"\nend\n# => [\"OK\", 1]\n```\n\n### Futures\n\nReplies to commands in a pipeline can be accessed via the *futures* they\nemit. All calls on the pipeline object return a\n`Future` object, which responds to the `#value` method. When the\npipeline has successfully executed, all futures are assigned their\nrespective replies and can be used.\n\n```ruby\nset = incr = nil\nredis.pipelined do |pipeline|\n  set = pipeline.set \"foo\", \"bar\"\n  incr = pipeline.incr \"baz\"\nend\n\nset.value\n# => \"OK\"\n\nincr.value\n# => 1\n```\n\n## Error Handling\n\nIn general, if something goes wrong you'll get an exception. For example, if\nit can't connect to the server a `Redis::CannotConnectError` error will be raised.\n\n```ruby\nbegin\n  redis.ping\nrescue Redis::BaseError => e\n  e.inspect\n# => #\u003CRedis::CannotConnectError: Timed out connecting to Redis on 10.0.1.1:6380>\n\n  e.message\n# => Timed out connecting to Redis on 10.0.1.1:6380\nend\n```\n\nSee lib\u002Fredis\u002Ferrors.rb for information about what exceptions are possible.\n\n## Timeouts\n\nThe client allows you to configure connect, read, and write timeouts.\nStarting in version 5.0, the default for each is 1. Before that, it was 5.\nPassing a single `timeout` option will set all three values:\n\n```ruby\nRedis.new(:timeout => 1)\n```\n\nBut you can use specific values for each of them:\n\n```ruby\nRedis.new(\n  :connect_timeout => 0.2,\n  :read_timeout    => 1.0,\n  :write_timeout   => 0.5\n)\n```\n\nAll timeout values are specified in seconds.\n\nWhen using pub\u002Fsub, you can subscribe to a channel using a timeout as well:\n\n```ruby\nredis = Redis.new(reconnect_attempts: 0)\nredis.subscribe_with_timeout(5, \"news\") do |on|\n  on.message do |channel, message|\n    # ...\n  end\nend\n```\n\nIf no message is received after 5 seconds, the client will unsubscribe.\n\n## Reconnections\n\n**By default**, this gem will only **retry a connection once** and then fail, but\nthe client allows you to configure how many `reconnect_attempts` it should\ncomplete before declaring a connection as failed.\n\n```ruby\nRedis.new(reconnect_attempts: 0)\nRedis.new(reconnect_attempts: 3)\n```\n\nIf you wish to wait between reconnection attempts, you can instead pass a list\nof durations:\n\n```ruby\nRedis.new(reconnect_attempts: [\n  0, # retry immediately\n  0.25, # retry a second time after 250ms\n  1, # retry a third and final time after another 1s\n])\n```\n\nIf you wish to disable reconnection only for some commands, you can use\n`disable_reconnection`:\n\n```ruby\nredis.get(\"some-key\") # this may be retried\nredis.disable_reconnection do\n  redis.incr(\"some-counter\") # this won't be retried.\nend\n```\n\n## SSL\u002FTLS Support\n\nTo enable SSL support, pass the `:ssl => true` option when configuring the\nRedis client, or pass in `:url => \"rediss:\u002F\u002F...\"` (like HTTPS for Redis).\nYou will also need to pass in an `:ssl_params => { ... }` hash used to\nconfigure the `OpenSSL::SSL::SSLContext` object used for the connection:\n\n```ruby\nredis = Redis.new(\n  :url        => \"rediss:\u002F\u002F:p4ssw0rd@10.0.1.1:6381\u002F15\",\n  :ssl_params => {\n    :ca_file => \"\u002Fpath\u002Fto\u002Fca.crt\"\n  }\n)\n```\n\nThe options given to `:ssl_params` are passed directly to the\n`OpenSSL::SSL::SSLContext#set_params` method and can be any valid attribute\nof the SSL context. Please see the [OpenSSL::SSL::SSLContext documentation]\nfor all of the available attributes.\n\nHere is an example of passing in params that can be used for SSL client\ncertificate authentication (a.k.a. mutual TLS):\n\n```ruby\nredis = Redis.new(\n  :url        => \"rediss:\u002F\u002F:p4ssw0rd@10.0.1.1:6381\u002F15\",\n  :ssl_params => {\n    :ca_file => \"\u002Fpath\u002Fto\u002Fca.crt\",\n    :cert    => OpenSSL::X509::Certificate.new(File.read(\"client.crt\")),\n    :key     => OpenSSL::PKey::RSA.new(File.read(\"client.key\"))\n  }\n)\n```\n\n[OpenSSL::SSL::SSLContext documentation]: http:\u002F\u002Fruby-doc.org\u002Fstdlib-2.5.0\u002Flibdoc\u002Fopenssl\u002Frdoc\u002FOpenSSL\u002FSSL\u002FSSLContext.html\n\n## Expert-Mode Options\n\n - `inherit_socket: true`: disable safety check that prevents a forked child\n   from sharing a socket with its parent; this is potentially useful in order to mitigate connection churn when:\n    - many short-lived forked children of one process need to talk\n      to redis, AND\n    - your own code prevents the parent process from using the redis\n      connection while a child is alive\n\n   Improper use of `inherit_socket` will result in corrupted and\u002For incorrect\n   responses.\n\n## hiredis binding\n\nBy default, redis-rb uses Ruby's socket library to talk with Redis.\n\nThe hiredis driver uses the connection facility of hiredis-rb. In turn,\nhiredis-rb is a binding to the official hiredis client library. It\noptimizes for speed, at the cost of portability. Because it is a C\nextension, JRuby is not supported (by default).\n\nIt is best to use hiredis when you have large replies (for example:\n`LRANGE`, `SMEMBERS`, `ZRANGE`, etc.) and\u002For use big pipelines.\n\nIn your Gemfile, include `hiredis-client`:\n\n```ruby\ngem \"redis\"\ngem \"hiredis-client\"\n```\n\nIf your application doesn't call `Bundler.require`, you may have\nto require it explicitly:\n\n```ruby\nrequire \"hiredis-client\"\n````\n\nThis makes the hiredis driver the default.\n\nIf you want to be certain hiredis is being used, when instantiating\nthe client object, specify hiredis:\n\n```ruby\nredis = Redis.new(driver: :hiredis)\n```\n\n## Testing\n\nThis library is tested against recent Ruby and Redis versions.\nCheck [Github Actions][gh-actions-link] for the exact versions supported.\n\n## See Also\n\n- [async-redis](https:\u002F\u002Fgithub.com\u002Fsocketry\u002Fasync-redis) — An [async](https:\u002F\u002Fgithub.com\u002Fsocketry\u002Fasync) compatible Redis client.\n\n## Contributors\n\nSeveral people contributed to redis-rb, but we would like to especially\nmention Ezra Zygmuntowicz. Ezra introduced the Ruby community to many\nnew cool technologies, like Redis. He wrote the first version of this\nclient and evangelized Redis in Rubyland. Thank you, Ezra.\n\n## Contributing\n\n[Fork the project](https:\u002F\u002Fgithub.com\u002Fredis\u002Fredis-rb) and send pull\nrequests.\n\n\n[rdoc-master-image]: https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fdocs-rdoc.info-blue.svg\n[rdoc-master-link]:  https:\u002F\u002Frubydoc.info\u002Fgithub\u002Fredis\u002Fredis-rb\n[redis-commands]:    https:\u002F\u002Fredis.io\u002Fcommands\n[redis-home]:        https:\u002F\u002Fredis.io\n[redis-url]:         https:\u002F\u002Fwww.iana.org\u002Fassignments\u002Furi-schemes\u002Fprov\u002Fredis\n[gh-actions-image]:  https:\u002F\u002Fgithub.com\u002Fredis\u002Fredis-rb\u002Fworkflows\u002FTest\u002Fbadge.svg\n[gh-actions-link]:   https:\u002F\u002Fgithub.com\u002Fredis\u002Fredis-rb\u002Factions\n[rubydoc]:           https:\u002F\u002Frubydoc.info\u002Fgems\u002Fredis\n","redis-rb 是一个用于 Redis 的 Ruby 客户端库。该项目旨在提供与 Redis API 一一对应的接口，同时保持 Ruby 语言的惯用风格，支持通过多种方式（如主机名、端口、Unix 套接字或 URL）连接到 Redis 服务，并且可以处理密码保护和 ACL 认证的 Redis 实例。此外，它还支持 Redis Sentinel 自动故障转移功能。尽管自身不提供连接池功能，但推荐使用 connection_pool gem 来实现这一点。此库适用于需要在 Ruby 应用中集成高速缓存、消息队列等功能的场景，特别是当应用架构依赖于 Redis 提供的数据存储及传输能力时。",2,"2026-06-11 03:14:25","top_language"]