https://github.com/devboidesigns/redis-wrapper
This library provides a wrapper around Redis 🔴 to facilitate common operations such as setting and getting values, managing sessions, and handling analytics data. It uses redis for Redis client operations, connect-redis for session store, and express-session for session management.
https://github.com/devboidesigns/redis-wrapper
redis redis-cache
Last synced: about 2 months ago
JSON representation
This library provides a wrapper around Redis 🔴 to facilitate common operations such as setting and getting values, managing sessions, and handling analytics data. It uses redis for Redis client operations, connect-redis for session store, and express-session for session management.
- Host: GitHub
- URL: https://github.com/devboidesigns/redis-wrapper
- Owner: DevboiDesigns
- License: mit
- Created: 2024-11-30T12:05:31.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-06T07:51:42.000Z (over 1 year ago)
- Last Synced: 2025-02-09T22:42:52.881Z (over 1 year ago)
- Topics: redis, redis-cache
- Language: TypeScript
- Homepage: https://redis.io
- Size: 76.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Redis API Wrapper
## Overview
This library provides a wrapper around Redis to facilitate common operations such as setting and getting values, managing sessions, and handling analytics data. It uses `redis` for Redis client operations, `connect-redis` for session store, and `express-session` for session management.
## Environment Variables
The following environment variables are used to configure the Redis client:
- `SESSION_SECRET`: Secret key for session management.
- `REDIS_PASSWORD`: Password for Redis authentication.
- `REDIS_HOST`: Hostname for the Redis server.
- `REDIS_PORT`: Port number for the Redis server.
- `IS_LOCAL`: Flag to indicate if the environment is local.
- `IS_CONTAINER`: Flag to indicate if the app is running in a docker container.
- `REDIS_LOCAL_URL`: URL for the local Redis server.
These variables are imported from the [env.keys.ts](src/config/env.keys.ts) file.
## Types
### RedisAnalyticsType
Defines the types of analytics data that can be stored in Redis:
- `"registered"`
- `"signed_in"`
- `"signed_out"`
- `"viewed"`
### RedisDirectory
Defines the directories (or namespaces) used in Redis:
- `"view_count"`
- `"logs"`
- `"users"`
- `"posts"`
## Usage
To use this library, import the `RedisLib` class and initialize it:
```typescript
import RedisLib from "./libs/redis.lib"
// Initialize Redis client
const redisLib = new RedisLib()
await redisLib.initRedisClient()
```
## Methods
`initRedisClient`
- Initializes the Redis client and sets up session management.
`close`
- Closes the Redis client connection.
`setAnalyticsValue`
- Sets an analytics value in Redis.
`setData`
- Sets a data value in Redis.
`setDataWithExpiry`
- Sets a data value in Redis with an expiry time.
`setValue`
- Sets a string or number value in Redis.
`setValueToExp`
- Sets a string value in Redis with an expiry time.
`getData`
- Gets a data value from Redis.
`getValue`
- Gets a string or number value from Redis.
`removeValue`
- Removes a value from Redis.