npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@srfnstack/redish

v0.3.4

Published

Redis Protocol Object/Document storage in collections

Downloads

8

Readme

redish

What is redish

redish is a NO->RM (Nice Object to Redis protocol Mapper) that will save your documents to a storage backend that supports the redis protocol with transactions ( MULTI, EXEC, etc ). Redis or ( Titan + TiKV ) are excellent options.

The primary goal is to provide a typical ORM like experience that uses the redis protocol instead of sql.

Redish adds collections, which are much like mongo collections, or tables in RDBMS.

It supports storing and retrieving objects with the data types of properties preserved on retrieval.

Getting Started

Provide a redis client to initialize the db.

You should use https://www.npmjs.com/package/redis version 4+.

version 3 will not work for 0.3+ of redish.

Serialization configuration is done once per db. You can create multiple instances of db if you wish.

After creating the db, use the result to create collections. A collection consists of a key prefix and a zset that all keys are stored in. The zset allows finding all the objects in the collection and provides speedy pagination.

Use the collection object to save, find, and update the collection and objects within it.

By default, a field named 'id' is used as the key to store the object in redis.

The value of id is prefixed with the collection name and two underscores, i.e. given id='1234', it will store the object using the key stuff__1234.

You can change the id field by passing the option idField to db.collection. I.e. db.collection('stuff', {idField:'myField'})

The collection prefix is used for two reasons, first to quickly identify which collection any given key belongs too, and to ensure uniqueness across collections since there's only a single keyspace in redis.

When loading objects, the key can be passed in with or without the prefix to make some use cases simpler.

const db = redish.createDb( client )
const stuff = db.collection('stuff')

const saved = stuff.save({
    id: '1234',
    things: [
        {name: 'thing1'},
        {name: 'thing2'}
    ]
})

expect(saved.id).toEqual('stuff__1234')

const loaded = stuff.findOneById(saved.id)

Serialization

Objects are serialized using the jpflat and all fields are serialized to string

Custom Serialization

All data in redis is stored as a string, so serialization is done by checking the type of the value, and adding a prefix of fixed length to every value. This way the data

If you want to change the way that values are serialized and deserialized, you can provide custom serializers. This is useful for cases where you want to convert objects of a specific type (i.e. Date) to a string and back.