drapcode-redis
v1.5.5
Published
DrapCode Redis Utility
Downloads
225
Readme
Drapcode Redis Module
A Redis client module for Drapcode applications that provides caching and data storage functionality.
Installation
npm install drapcode-redisConfiguration
The module uses the following environment variables:
REDIS_HOST: Redis server host (default: "localhost")REDIS_PORT: Redis server port (default: 6379)REDIS_PASSWORD: Redis server password (default: "nextdefault")
Usage
import { redis_get_method, redis_set_method } from "drapcode-redis";
// Get data from Redis
const data = await redis_get_method("my-key");
// Set data in Redis
await redis_set_method("my-key", { value: "example" });API
Common Methods
common_get_method(key: string, res: Response, next: NextFunction)
Gets data from Redis and sends it in the response if found, otherwise calls next middleware.
common_set_method(key: string, data: any, dataExpiryTime?: number)
Sets data in Redis with optional expiry time (default: 3 hours).
common_clear_method(keys: string)
Removes specified keys from Redis.
common_clear_method_with_pattern(pattern: string)
Removes all keys matching the given pattern.
Redis Methods
redis_get_method(key: string)
Returns data from Redis as a Promise.
redis_set_method(key: string, data: any)
Sets data in Redis and returns a Promise.
redis_clear_currentRedisDB()
Clears all data from the current Redis database.
Error Handling
All methods include error handling and will:
- Log errors to console
- Return null or empty object on error
- Maintain application stability
Dependencies
- redis: ^4.6.13
- express: ^4.17.1
- @types/redis: ^4.0.11
- @types/express: ^4.17.7
