A cache abstraction for Node.js that supports both Redis and memcached using
- for developers to easily get started with Redis or memcached
- for developers to easily switch between Redis and memcached
- for developers to use Redis and memcached in the same codebase
Inspired by Shopify's go-cache
npm install node-easy-cache
Check out the Example Project
All operations run the exact same on on Redis and memcached clients. Supported operations:
|Function||Return type (if not void)|
Note on integer behaviour in Redis vs memcached
Memcached does not allow storing negative integers, so the increment and decrement behaviour between Redis and memcached is different. However, this API makes them behave the same by using get and set operations for memcached using strings. Therefore, using
decrement for memcached is slower, but it will have the same behaviour as Redis.
If you want to use the default memcached behaviour, you can access the underlying client by accessing
Before testing, MAKE SURE THAT YOU HAVE NO IMPORTANT DATA IN REDIS/MEMCACHE! The test cases flush the database frequently.
Make sure you have
memcachedrunning. If you have Docker installed, you can run
docker-compose upto run Dockerized containers for testing
If you're not running Redis or memcached locally on the default port, set the
Please report any bugs using the GitHub issue tracker.
If you want to contribute features, please add test cases and run
prettier --write . (code formatter) before submitting. Notice that the test cases for both Redis and memcached should be the exact same. You can run the validateTestCases.sh script to ensure this.