https://github.com/restricted/redis-data-cache
TypeScript implementation of data cache management by class name
https://github.com/restricted/redis-data-cache
cache data object redis state typesript
Last synced: about 2 months ago
JSON representation
TypeScript implementation of data cache management by class name
- Host: GitHub
- URL: https://github.com/restricted/redis-data-cache
- Owner: restricted
- Created: 2019-02-27T20:40:35.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-04-10T08:23:25.000Z (almost 7 years ago)
- Last Synced: 2025-10-19T22:52:08.707Z (5 months ago)
- Topics: cache, data, object, redis, state, typesript
- Language: JavaScript
- Homepage:
- Size: 31.3 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Redis data cache
---
Motivation:
- Support for partial data update by key (only first level, no nested data)
- Support find with partial object / array returns
- Support querying in find methods
Methods:
await create(data) - return Redis status for operation, where data is instance of some class
await createBatch(data[]) - return Redis status for operation, where data is array of instances of some class
await update(data) - return Redis status for operation, where data is instance of some class
await updatePartial(Class, data) - return Redis status for operation, where data is partial instance of some class (update properties with Object.assign)
await find(Class, fields?: ['id', 'name']) - return all instances of provided class with filtered properties
await findById(Class, id: any, fields?: ['id', 'name']) - return finded by id instance with filtered properties
await findById(Class, ids: [any], fields?: ['id', 'name']) - return finded by ids instances of provided class with filtered properties
await delete(Class, id: any) - remove instance from redis
Examples:
```
import { RedisDataCache } from 'redis-data-cache';
const cache = new RedisDataCache();
class Data {
id: number;
name?: string;
}
const data = new Data();
data.id = 20;
cache.create(data).catch(console.error);
const arrayData = [data];
createBatch(arrayData).catch(console.error)
data.name = 'Help';
update(data).catch(console.error);
find(Data).catch(console.error);
updatePartial(Class, { id: 20, name: 'Help me' }).catch(console.error);
findById(Data, id: 20).catch(console.error);
findByIds(Data, ids: [20, 30, 12]).catch(console.error);
delete(Class, 20).catch(console.error);
```