Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
backbone-redis-store
Advanced tools
This is a work in progress, it's not been thoroughly tested in development, let alone production. You have been warned.
There are npm modules that serve the backbone/redis storage problem, but they seem to include socket.io or similar transports to synchronize to the browser. This is great if you need that functionality, but I simply what a backbone.js redis store that neither knows about nor cares about the client.
backbone-redis-store is intended to be a simple (yet powerful) bridge between backbone.js and redis.
It is written in CoffeeScript, so you'll need CoffeeScript to run it.
redisStore
and take appropriate
action (should revert back to old Backbone.sync if no redisStore
is
found)model.id
keyed hash)Stores the model as JSON encoded data into a redis hash named
options.key
, where the id
of the model is the key to the hash.
Auto-increment counter is stored as next|{options.key}
Unique indexes are stored as a normal redis key:
unique|{options.key}:{field}|{value.toLowerCase()}
with value:
model.id
. They are not stored in a hash so that we can avoid the use
of WATCH
and instead use MSETNX
to check and set the unique keys.
Simply because we're sharing one redis connection across all clients
(probably) - we don't want various other WATCH
s to conflict, or an
UNWATCH
to cancel our watch. An alternate solution would be to use a
separate redis connection per transaction - this may be implemented in
future.
Dependencies:
To use it, you would:
# Create a new redisClient (npm install redis)
redisClient = require('redis').createClient()
# Require backbone (npm install backbone)
Backbone = require 'backbone'
# Import backbone-redis-store
RedisStore = require './backbone-redis-store'
# Implement RedisStore's Backbone.sync method
RedisStore.infect Backbone
# Define yourself a new model
class MyModel extends Backbone.Model
username: null
uniqueNumber: null
somethingElse: null
# Define a collection, setting a `redisStore` property
class MyModelCollection extends Backbone.Collection
redisStore: new RedisStore
key: 'mymodel'
redisClient: redisClient
unique: ['username','uniqueNumber']
model: MyModel
# Create a new instance of this collection and populate it
myModelCollection = new MyModelCollection()
myModelCollection.fetch()
Note: I would not recommend doing the last line for large stores - I would lazily fetch
data as you need it using myModelCollection.getByUnique
or similar.
new RedisStore
takes the following options:
key
- the redis key under which to store the model dataredisClient
- the connection to redis to use for storageunique
- an array of columns of the model that should be treated as
unique indexes. An empty array is perfectly valid.Backbone.Collection.getByUnique(key, value, options)
key
- the model key to look forvalue
- the value of said key to look foroptions
- accepts success
and error
callbacks like many Backbone
methodsI intend to add the following features in time:
If you fancy contributing, please get in touch! :)
FAQs
Backbone mod to enable Redis as store
The npm package backbone-redis-store receives a total of 0 weekly downloads. As such, backbone-redis-store popularity was classified as not popular.
We found that backbone-redis-store demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.