{"id":19316720,"url":"https://github.com/maxim/redis_collection","last_synced_at":"2025-08-30T04:10:18.942Z","repository":{"id":56891449,"uuid":"74623060","full_name":"maxim/redis_collection","owner":"maxim","description":"Sync a ruby enumerable with a redis namespace","archived":false,"fork":false,"pushed_at":"2016-11-29T20:56:09.000Z","size":9,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-08-09T20:59:54.867Z","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/maxim.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-11-23T23:55:34.000Z","updated_at":"2019-01-09T19:45:22.000Z","dependencies_parsed_at":"2022-08-21T00:50:29.806Z","dependency_job_id":null,"html_url":"https://github.com/maxim/redis_collection","commit_stats":null,"previous_names":["crossfield/redis_collection"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/maxim/redis_collection","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxim%2Fredis_collection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxim%2Fredis_collection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxim%2Fredis_collection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxim%2Fredis_collection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maxim","download_url":"https://codeload.github.com/maxim/redis_collection/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxim%2Fredis_collection/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272801084,"owners_count":24995217,"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-08-30T02:00:09.474Z","response_time":77,"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":[],"created_at":"2024-11-10T01:12:23.679Z","updated_at":"2025-08-30T04:10:18.924Z","avatar_url":"https://github.com/maxim.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RedisCollection\n\nEasily sync an iterable ruby object with a redis namespace.\n\nThis tool DOES NOT:\n\n- integrate with anything\n- help retrieve data back from redis\n- handle redis connection issues\n- make birds in 5 mile radius attack you\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'redis_collection'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install redis_collection\n\n## Usage\n\n```ruby\nbooks = [\n  { id: 1, title: 'Programming Elixir' },\n  { id: 2, title: 'Programming Phoenix' }\n]\n\nredis = Redis.new(url: ENV['REDIS_URL'])\nredis_collection = RedisCollection.new(redis, namespace: 'books_')\nredis_collection.sync(books)\nredis.mget('books_1', 'books_2')\n# =\u003e [\"\\x04\\b{\\aI\\\"\\aid\\x06:\\x06ETi\\x06I\\\"\\ntitle\\x06;\\x00TI\\\"\\x17Programming Elixir\\x06;\\x00T\", \"\\x04\\b{\\aI\\\"\\aid\\x06:\\x06ETi\\aI\\\"\\ntitle\\x06;\\x00TI\\\"\\x18Programming Phoenix\\x06;\\x00T\"]\n```\n\nBy default each object in the collection is serialized via `Marshal.dump` and loaded via `Marshal.load`. Identity of each object is determined by calling `['id']` by default. To change these defaults you can provide procs to `RedisCollection.new`.\n\n```ruby\nredis_collection = RedisCollection.new(redis,\n  namespace: 'books_',\n  load: -\u003e string { JSON.parse(string) },\n  dump: -\u003e object { object.to_json },\n  make_key: -\u003e object { object.special_id }\n)\nredis_collection.sync(books)\n```\n\nIn the above example objects are converted to/from JSON and must respond to `special_id` to be identified.\n\nMethod `sync` always overwrites keys that already exist in Redis, and deletes keys that are in Redis but not in collection.\n\n## Benchmark\n\nMethod `sync` returns a hash of stats containing 3 pieces of information:\n\n1. `:mset_cnt` - how many strings were [mset](http://redis.io/commands/mset)\n2. `:del_cnt` - how many strings were [del](http://redis.io/commands/del)\n3. `:time` - the result of `Benchmark.measure {}` on the redis call\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/crossfield/redis_collection. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxim%2Fredis_collection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaxim%2Fredis_collection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxim%2Fredis_collection/lists"}