{"id":24946397,"url":"https://github.com/machinezone/mockredis","last_synced_at":"2025-04-10T05:14:49.299Z","repository":{"id":76807709,"uuid":"138952754","full_name":"machinezone/mockredis","owner":"machinezone","description":"MockRedis is an in-memory, pure-PHP implementation of Redis.","archived":false,"fork":false,"pushed_at":"2020-09-25T20:00:51.000Z","size":54,"stargazers_count":3,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T06:23:20.951Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","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/machinezone.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}},"created_at":"2018-06-28T01:49:28.000Z","updated_at":"2020-09-25T19:47:37.000Z","dependencies_parsed_at":"2023-07-04T22:15:53.349Z","dependency_job_id":null,"html_url":"https://github.com/machinezone/mockredis","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/machinezone%2Fmockredis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/machinezone%2Fmockredis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/machinezone%2Fmockredis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/machinezone%2Fmockredis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/machinezone","download_url":"https://codeload.github.com/machinezone/mockredis/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248161278,"owners_count":21057555,"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":"2025-02-02T20:24:23.232Z","updated_at":"2025-04-10T05:14:49.284Z","avatar_url":"https://github.com/machinezone.png","language":"PHP","readme":"[MockRedis](https://github.com/machinezone/php-mockredis)\n=========================================================\nMockRedis is an in-memory, pure-PHP implementation of Redis.\n\nIt aims for compatibility first and speed second.\nIt's intended to take the place of a proper Redis backend, for the purpose of testing and prototyping.\nIt primarily provides a new `MockRedis` class to represent a Redis connection, but also provides executable scripts that behave like `redis-server` and `redis-cli`.\n\nBasic Usage\n-----------\nIn its most basic form, MockRedis can be used by instantiating it and calling Redis commands on it via methods of the same name.\n\nThis PHP:\n```php\n$redis = new mz\\mockredis\\MockRedis();\n$redis-\u003eset('hello', 'world');\nvar_dump($redis-\u003eget('hello'));\n```\nIs equivalent to these Redis commands:\n```redis\nSET hello world\nGET hello\n```\nAnd would print:\n```\nstring(5) \"world\"\n```\n\nIn this mode, the effects of commands will persist until the end of the script.\nMultiple instances will share the same data and affect one another.\n\nAll arguments are treated as strings, and replies are handled as follows:\n- Redis integer reply    -\u003e PHP `int` return\n- Redis bulk reply       -\u003e PHP `string|null` return\n- Redis multi bulk reply -\u003e PHP `array|null` return\n- Redis status reply     -\u003e PHP `true|string` return (`true` for \"OK\", otherwise a `string`)\n- Redis error reply      -\u003e throw `MockRedisException` with the error message\n\n\nInstallation\n------------\nMockRedis will work with composer's autoloading, or you can `require 'include.php'` to load everything directly.\n\n\nPersistence\n-----------\nBy default, MockRedis only stores its state in memory, shared across instances of the same name.\nIt also provides two on-disk storage implementations for persisting across PHP scripts or as a troubleshooting aid.\n\nThe handlers for these are `MemoryMockRedisPersistence`, `SerializeMockRedisPersistence`, and `JsonMockRedisPersistence`, which you may specify when you instantiate `MockRedis` or by setting `MockRedis::$persistenceClass`.\nYou may also use your own `MockRedisPersistence` handler, to mock the persistence layer (e.g. seeding data) or to use some other storage destination or format.\n\n\nScripting\n---------\nIf you have the `php-lua` extension loaded, MockRedis will use it to handle the Lua scripting commands `EVAL`, `EVALSHA`, and `SCRIPT`.\n\nMockRedis provides the `PhpLuaMockRedisScripting` class to handle this, but you may override that with your own `MockRedisScripting` class when you instantiate `MockRedis` or by setting `MockRedis::$scriptingClass`.\nYou may want to override this to mock the scripting layer or integrate with a different Lua module.\n\n\nConfiguration\n-------------\nStatic configuration:\n- `MockRedis::$exceptionClass` - override the type for error replies\n        You may want this if your code is already expecting a different exception type for redis errors.\n\n- `MockRedis::$timeFunc` - override a callback for current system time\n        You may want this in unit tests or other environments where you need full control over the clock.\n\n- `MockRedis::$persistenceClass` - default handler for data persistence\n- `MockRedis::$scriptingClass` - set a handler for Lua scripting commands\n\nInstance configuration - `new MockRedis($name, $persistence, $scriptingClass)`:\n- `$name` - the name of this instance.  instances with the same name will normally share similar storage.\n- `$persistence` - a `MockRedisPersistence` object to handle storage.\n- `$scriptingClass` - a class to instantiate for Lua scripting commands.\n\n\nMock Executables\n----------------\nMockRedis also provides an executable script `mockredis` that mimics `redis-server` or `redis-cli`.\nThis is used for troubleshooting and testing during development, but may also be useful as mock implementations of these executables.\nIt can also be used as a relatively complex example of how to use MockRedis.\n\n\nCaveats\n-------\nPHP's default setting for `precision`, which controls how floats are cast to strings, is lower than how Redis would behave.\nYou may want to set this `precision` to -1, 16, or 17.\nThe `mockredis` script itself does this.\nAlso, `serialize_precision` will affect on-disk persistence.\n\n\nCompatibility, Coverage, Bugs\n-----------------------------\nMockRedis attempts to provide the same behavior as Redis where it can.\nA few commands, such as INFO or OBJECT, will give a valid response that does not match Redis.\nIt does not try to match the behavior any specific version of Redis, but instead tries to get the greatest coverage across all versions of Redis.\n\nThis is an overview of MockRedis's coverage of Redis commands.  Check `MockRedis.php` for specifics.\n\nGroup        |      | Notes\n:------------|:-----|:-----\nCluster      | none | (always replies as though disabled)\nConnection   | full | partial AUTH (no password may be set)\nGeo          | none |\nHashes       | full |\nHyperLogLog  | none |\nKeys         | most | no MIGRATE, partial OBJECT, partial SORT\nLists        | most | no BLPOP, no BRPOP, no BRPOPLPUSH\nPub/Sub      | none |\nScripting    | most | (requires [php-lua](https://github.com/laruence/php-lua), non-deterministic writes are ignored)\u003cbr\u003eno SCRIPT DEBUG, no SCRIPT KILL\nServer       | some | BGSAVE, BGREWRITEAOF, DBSIZE, FLUSHALL, FLUSHDB, LASTSAVE, SAVE, TIME\u003cbr\u003epartial DEBUG, partial INFO\nSets         | full |\nSorted Sets  | full |\nStrings      | most | no BITFIELD\nTransactions | none |\n\n`mz\\mockredis\\NotImplementedException` is thrown when Redis functionality is intentionally unimplemented.\n\nBeyond that, `FIXME` is used to tag discrepancies with Redis, while `TODO` is used to tag improvements.\n\nMockRedis can be tested using Redis's own tests, by symlinking `\u003cmockredis\u003e/bin/mockredis` to `\u003credis\u003e/src/redis-server`.\n\n\nLicense\n-------\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmachinezone%2Fmockredis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmachinezone%2Fmockredis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmachinezone%2Fmockredis/lists"}