https://github.com/admirkadriu/sein-redis
Secondary indexing for Redis
https://github.com/admirkadriu/sein-redis
database database-index indexing javascript nodejs redis
Last synced: 3 months ago
JSON representation
Secondary indexing for Redis
- Host: GitHub
- URL: https://github.com/admirkadriu/sein-redis
- Owner: admirkadriu
- Created: 2019-01-06T17:29:03.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T21:33:26.000Z (over 3 years ago)
- Last Synced: 2025-11-04T03:02:04.324Z (7 months ago)
- Topics: database, database-index, indexing, javascript, nodejs, redis
- Language: JavaScript
- Homepage:
- Size: 675 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# sein-redis
Secondary indexing for Redis
# Quick Start
## Install
```shell
$ npm install sein-redis
```
## Usage Example
```javascript
const Redis = require('ioredis');
const seinRedis = require('sein-redis');
const redis = new Redis();
await seinRedis.setClient(redis);
seinRedis.setPrefix('example');
class UserModel extends seinRedis.Model {
constructor() {
super();
this.modelName = 'User';
this.setDefinitions([
{
name: 'id',
primaryKey: true,
},
{
name: 'email',
uniqueIndex: true,
},
{
name: 'typeId',
index: true,
},
]);
}
getByEmail(email) {
return this.getByUniqueIndex({ email }, true);
}
getByType(typeId) {
return this.getByIndex({ typeId }, true);
}
}
const isSet = await userModel.set({
id: 'd982398j2398u',
name: 'Test User',
email: 'testuser@tests.com',
typeId: 1,
});
let user = await userModel.get('d982398j2398u');
user = await userModel.getByEmail('testuser@tests.com');
const users = await userModel.getByType(1);
```
# Licence
MIT