0.1.2 • Published 10 years ago

pd-redis-record v0.1.2

Weekly downloads
2
License
MIT
Repository
github
Last release
10 years ago

pd-redis-record (Abandoned)

A redis and data model mapping

var Record = require('pd-redis-record');
var modelName = 'user';
var primKeys = ['id'];
var User = Record(modelName, primKeys);

User.amount().then(..);

User.listIds().then(..);

User.rangeIds({
  latest: (new Date()).getTime(),
  earliest: 0
  limit: [0, 20]
}).then(..);

User.getByIdList(idList, {
  fields : ['status', 'firstName'],
  each: function(record){
    //setSthTo(record);
    return record;
  }
}).then(...);

User.getOne('myemail@email.com', {
  fields: ['status', 'firstName']  ,
  withCreatedAt : true  //As creation time is stored in a sorted-set which is different from the record data
                        //it may bring more or less performance loss
}).then(..);

User.range({
  latest : ...,
  earliest : ...,
  limit : ...,
  fields : ....
  //there is no need for withCreatedAt as this function will search both 
  //the data hash and sorted-set index for sure
}).then(..);

User.create({
  id:'johndoe@email.com',
  firstName : 'John',
  lastName : 'Doe'
}).then(...);

User.modify({
  id:'johndoe@email.com',
  firstName : 'Jane',
  lastName : 'Doe'
}).then(...);

User.remove('johndoe@gmail.com').then(...);

User.checkAbsence('johndoe@gmail.com').then(function(){
   //not found
}).then(function(err){
   //found or error
});

User.checkPresence('johndoe@gmail.com').then(function(){
   //found
}).then(function(err){
   //not found or error
});