Nicely Packaged Make


    1.4.1 • Public • Published


    A redis adapter for Sails / Waterline with basic schema and indexing support.

    This adapter is intended to be used with models with very simple attributes (only number, boolean, string and json types are supported) and to do very simple queries, if you need something more complex you should be considering not using redis and move to a full featured DB like MongoDB, PostgreSQL, etc.


    To install this adapter, run:

    npm install sails-redis-schema

    Then, add the adapter to the config/datastores.js file like this:

    module.exports.datastores = {
      'redis-schema': {
        adapter: require('sails-redis-schema'),
        url: 'redis://user:password@' // defaults to ''

    You could also use the options field with any of the values listed here:

    module.exports.datastores = {
      'redis-schema': {
        adapter: require('sails-redis-schema'),
        options: {
          host: '',
          port: 5412,
          db: 3,
          enableOfflineQueue: false

    More info about datastores at:


    In most cases I added easy to understand errors, but as a rule of thumb, if some functionality is not listed here is probably because is not implemented. Keep in mind that I tried to implement this adapter as minimal as possible.

    Model Definition

    First, define your model and configure it to use the redis-schema datastore like this:

    module.exports = {
      identity: 'user',
      datastore: 'redis-schema',
      attributes: {
        id: {
          type: 'string'
        age: {
          type: 'number',
          defaultsTo: 18,
          meta: { index: true }
        firstName: {
          type: 'string',
          required: true,
          meta: { index: true }
        lastName: {
          type: 'string'

    Things to keep in mind:

    • For now, only the type's number, boolean, string and json are allowed.
    • If you want to query your model using other attribute than the primaryKey, you have to index it, to do so, do the same as we did with firstName, and add:
        meta: { index: true }


    The find method only allows to query items using only 1 attribute; you won't be able to do composed querys like: { firstName: 'Ada', age: 20 }.

    Also, don't forget to add the meta: { index: true } to all the attributes that you want to use to query items.


    // Correct
    User.find({ id: '123123123' }) // Find users with id '123123123'
    User.find({ firstName: 'Mark' }) // Find users named 'Mark'
    User.find({ firstName: ['Mark', 'Ada'] }) // Find users named `Mark` or `Ada`
    // Select fields
      where: { firstName: ['Mark', 'Ada'] }
      select: ['firstName', 'lastName']
    // Incorrect
    User.find({ firstName: 'Mark', age: 20 }) // Throws an error


    The create method works as expected. And, if you don't define an id, we will create one for you using nanoid.


    const ada = await User.create({
      firstName: 'Ada',
      lastName: 'Lovelace',
      age: 36


    Destroys one or multiple items, query rules apply the same as .find().

    const deletedItems = await User.destroy({
      firstName: ['Mark', 'Ada']

    👆 Deletes all users named "Mark" or "Ada", and, in this case we added the .fetch() call so it will bring back all the deleted items.


    Updates one or multiple items, query rules apply the same as .find().

    await User.update({
      firstName: 'Mark',
    }, {
      age: 32

    👆 Changes the age of all users named "Mark" to be 32 years old.


    The same as .find(), but returns the amount of queried items.

    const marksCount = await User.count({ firstName: 'Mark' })
    // `There are ${marksCount} marks.`

    More Info

    Visit Models & ORM in the docs for more information about using models, datastores, and adapters in your app/microservice.


    To run the tests, first make sure to have a redis server running. Or start one using Docker with:

    docker-compose up

    And then, to execute the tests run (this will connect to the running redis on

    npm test

    Or, you can use a custom redis instance setting the environment variable like this:

    TEST_REDIS_URL= npm test




    npm i @miroculus/sails-redis-schema

    DownloadsWeekly Downloads






    Unpacked Size

    25.8 kB

    Total Files


    Last publish


    • eugeniacarvajal
    • miroculusbot
    • ignusmart
    • rodowi
    • smvilar
    • nightmareze1
    • mjlescano