{"id":26282292,"url":"https://github.com/stevegrossi/hedwig_brain","last_synced_at":"2025-03-14T16:40:30.091Z","repository":{"id":57504600,"uuid":"80995801","full_name":"stevegrossi/hedwig_brain","owner":"stevegrossi","description":"Simple key-value persistence for Hedwig responders.","archived":false,"fork":false,"pushed_at":"2017-02-08T14:15:50.000Z","size":8,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-09T06:01:55.039Z","etag":null,"topics":["elixir","hedwig"],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stevegrossi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-05T13:48:07.000Z","updated_at":"2018-10-23T11:04:08.000Z","dependencies_parsed_at":"2022-08-29T23:40:28.131Z","dependency_job_id":null,"html_url":"https://github.com/stevegrossi/hedwig_brain","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevegrossi%2Fhedwig_brain","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevegrossi%2Fhedwig_brain/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevegrossi%2Fhedwig_brain/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevegrossi%2Fhedwig_brain/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stevegrossi","download_url":"https://codeload.github.com/stevegrossi/hedwig_brain/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243613618,"owners_count":20319543,"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":["elixir","hedwig"],"created_at":"2025-03-14T16:40:29.482Z","updated_at":"2025-03-14T16:40:30.074Z","avatar_url":"https://github.com/stevegrossi.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Hedwig Brain\n\nSimple key-value persistence for Hedwig responders, `Hedwig.Brain` stores lists of arbitrary terms under binary keys. Optionally, you may persist state to Redis for data durability across crashes and restarts.\n\n## Usage\n\n```elixir\nalias Hedwig.Brain\n\n# Store lists under binary keys:\niex\u003e Brain.set(\"people\", [\"Ada\", \"Babbage\"])\n\n# Retrieve lists by key:\niex\u003e Brain.get(\"people\")\n[\"Ada\", \"Babbage\"]\n\n# Delete lists. Lists at missing keys are empty:\niex\u003e Brain.delete(\"people\")\niex\u003e Brain.get(\"people\")\n[]\n\n# Append items to lists:\niex\u003e Brain.add(\"people\", %{first: \"Ada\", last: \"Byron\"})\niex\u003e Brain.get(\"people\")\n%{first: \"Ada\", last: \"Byron\"}\n\n# Delete items from lists:\niex\u003e Brain.set(\"people\", [\"Ada\", \"Babbage\"])\niex\u003e Brain.remove(\"people\", \"Ada\")\niex\u003e Brain.get(\"people\")\n\"Babbage\"\n\n# Retrieve items by index:\niex\u003e Brain.set(\"people\", [\"Ada\", \"Babbage\"])\niex\u003e Brain.at_index(\"people\", 0)\n\"Ada\"\n```\n\n## Installation\n\nAdd `hedwig_brain` as a dependency in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:hedwig_brain, \"~\u003e 0.1\"}\n  ]\nend\n```\n\nAnd run `mix deps.get`. Then, start the `Brain` process manually:\n\n```elixir\n{:ok, pid} = Hedwig.Brain.start_link\n```\n\nor as part of your application’s supervision tree:\n\n```elixir\nchildren = [\n  worker(Hedwig.Brain, [])\n]\n```\n\nNote that the `Brain` process is named, so you cannot run more than one instance of it.\n\n## In Production\n\nBy default, the `Brain` uses an in-memory `ProcessStore`—implemented as an `Agent`—to hold state. As a result, all state is lost when the process crashes or is restarted. To persist state to disk so that it survives restarts, you can configure the `Brain` to store state in Redis:\n\n    config :hedwig_brain, :store, Hedwig.Brain.RedisStore\n\nThe `RedisStore` will expect Redis to be running on the default host and port, `localhost:6379`. This can be overridden by either the `REDIS_URL` environment variable, or else `config :hedwig_brain, :redis_url` in the configuration file.\n\n## Testing\n\nThe tests for `hedwig_brain` require Redis to be running on the default host and port. They call `FLUSHDB` on database 3 before each test. The default Redis database is 0, but know that if you’re using database 3 locally, its data *will be wiped* by `mix test`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevegrossi%2Fhedwig_brain","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstevegrossi%2Fhedwig_brain","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevegrossi%2Fhedwig_brain/lists"}