Zipped Redis Vault is a high-performance key-value storage solution that leverages the speed of Redis. It comes with built-in compression using Zlib and optional encryption to keep your data secure and storage-efficient.
- Redis-Backed: Utilizes Redis for fast, in-memory data storage and retrieval.
- Automatic Compression: Values are automatically compressed with Zlib, optimizing storage space.
- Optional Encryption: Offers the option to encrypt data before storage for enhanced security.
- Redis: A high-performance in-memory key-value data store.
- Dotenv: A zero-dependency module to load environment variables.
- Zlib: A compression library providing data compression functionality.
- Crypto-JS: A library of cryptography standards for encryption.
Retrieves the value associated with the given key.
- Parameters:
key
- The key to fetch the value for. - Returns: A promise that resolves to the value, or
null
if the key doesn't exist.
Stores a value under the specified key.
- Parameters:
key
- The key under which to store the value.value
- The value to store.
- Returns: A promise that resolves once the operation is complete.
watcher(key: string, logTime: boolean, callback: (value: any) => void, savedUpdateTime?: string): void
Watches a specific key for any updates and executes a callback when the key is updated.
- Parameters:
key
- The key to watch.logTime
- Iftrue
, logs the update time to the console.callback
- A function to execute when the key is updated.savedUpdateTime
- (Optional) The initial last known update time.
Here's a quick guide to getting started with Zipped Redis Vault:
-
Setup: Ensure Redis is running and accessible. Place your configuration in a
dev.env
file at the root of your project, like so:SECRET=your_encryption_key SECRET_KEYS=comma_separated_keys_to_encrypt REDIS_URL=redis://your_redis_url:6379
-
Storing and Retrieving Data:
const { set, get } = require('zipped-redis-vault'); (async () => { await set('myKey', { name: 'John', age: 30 }); const value = await get('myKey'); console.log(value); // Outputs: { name: 'John', age: 30 } })();
-
Using the Watcher:
const { set, watcher } = require('zipped-redis-vault'); watcher('myKey', true, (value) => { console.log('Updated value:', value); }); setTimeout(async () => { await set('myKey', { name: 'Doe', age: 35 }); // The watcher will log: Updated value: { name: 'Doe', age: 35 } }, 2000);
-
Encryption: Any keys specified in the
SECRET_KEYS
of yourdev.env
will be encrypted automatically.await set('secureData', { cardNumber: '1234-5678-9012-3456' }); const data = await get('secureData'); console.log(data); // Outputs: { cardNumber: '1234-5678-9012-3456' }
- client: RedisClient - The instance of the Redis client used by the module.
To install the package, you need to have Redis running and a dev.env
file with the necessary configurations.
-
Install the package using npm:
npm i github:zyoi/Zipped-Redis-Vault
All configuration is handled through the dev.env
file. This should include:
SECRET
: Your encryption key.SECRET_KEYS
: A comma-separated list of keys to encrypt.REDIS_URL
: The URL to your Redis server.
To run tests, ensure your Redis instance is accessible as configured in dev.env
:
npm test
Contributions are welcome! Feel free to submit issues, pull requests, or suggestions to help improve the project.
Licensed under the MIT License.