{"id":24058,"library":"mockredispy","title":"mockredispy","description":"mockredispy is a Python library that provides a mock implementation of redis-py, useful for testing code that interacts with Redis without connecting to a real Redis server. The current version is 2.9.3, with periodic releases. It supports most redis-py commands but has limitations.","status":"active","version":"2.9.3","language":"python","source_language":"en","source_url":"https://github.com/locationlabs/mockredis","tags":["testing","mock","redis","fixtures"],"install":[{"cmd":"pip install mockredispy","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"MockRedis inherits from redis-py's StrictRedis or Redis classes for compatibility","package":"redis","optional":false}],"imports":[{"note":"common outdated import path","wrong":"from mockredis.mock import MockRedis","symbol":"MockRedis","correct":"from mockredis import MockRedis"},{"note":"incorrect function name","wrong":"from mockredis import mock_redis","symbol":"mock_redis_client","correct":"from mockredis import mock_redis_client"}],"quickstart":{"code":"from mockredis import MockRedis\n\n# Create a mock Redis client\nr = MockRedis()\nr.set('key', 'value')\nprint(r.get('key'))  # b'value'","lang":"python","description":"Basic usage: create a MockRedis instance and use it like a real redis client."},"warnings":[{"fix":"Check the mockredis documentation for supported commands, or use fakeredis as an alternative.","message":"MockRedis does not support all Redis commands; scripts (LUA), pub/sub, and certain advanced features are not implemented.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Use 'mock_redis_client' instead of 'mock_redis'.","message":"The method 'mock_redis' has been renamed to 'mock_redis_client' in newer versions.","severity":"deprecated","affected_versions":">=2.9.0"},{"fix":"Decode bytes to string using .decode() if needed: r.get('key').decode()","message":"MockRedis returns bytes for string values, similar to redis-py, but may cause confusion when comparing with expected strings.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run 'pip install mockredispy' and ensure the import is 'from mockredis import MockRedis'.","cause":"The library is not installed or import path is incorrect.","error":"ImportError: No module named mockredis"},{"fix":"Upgrade to the latest version: 'pip install --upgrade mockredispy'","cause":"The installed version may be outdated; older versions of mockredis did not support pipelines.","error":"AttributeError: 'MockRedis' object has no attribute 'pipeline'"},{"fix":"Use correct import: 'from mockredis import MockRedis' then call 'MockRedis()'","cause":"You tried to instantiate MockRedis incorrectly (e.g., MockRedis() but MockRedis is a module).","error":"TypeError: 'MockRedis' object is not callable"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}