Sloth Bucket
A simple, persistent user slot system to store data sequentially with allocate/deallocate functions.
Get started
- Install and run redis.
- We have provided a Dockerfile that will create a simple redis server container
sudo docker build -t <your namespace>/redis .
sudo docker run -d -p 6379:6379 <your namespace>/redis
- Install sloth-bucket
npm install sloth-bucket --save
- For using sloth-bucket in production, you can easily configure the underlying redis store:
var sloth = ; var options = host: '192.168.2.45' port: 8034 socket_keepalive: truesloth;
Usage
var sloth = ;var username = 'marvin'; //initialize the slots with a starting buffer:sloth; var hitPoints = '5';//assign variable value above to a new slot: sloth; //deallocate a slot at index 3 for user 'marvin':sloth; sloth
Utilities
//reset all slots for a user:sloth; //get next available slot id:sloth;
Configuration
For more redis configuration options, consult the redis documentation.
//configure underlying redis cache:var options = host: '192.168.2.45' port: 8034 socket_keepalive: truesloth; //set slot's hash index as non-zero based:sloth;
Changes by release (all versions prior to 2.0 are beta)
v. 1.4.1
- removed the slot prefixing, in favor of enabling multiple slots, like this:
sloth;sloth;
v. 1.3.12
- new minor feature: nonZeroBased() configures non-zero based hash of slots
- new minor feature: get/setSlotValue() function to get/set slot data
v. 1.2.11
- added nextAvailableSlotId() function for retrieving next unallocated slot Id
Tests
### Set up
- Install redis on the computer on which you want to run the tests.
- We have provided a Dockerfile that will create a simple redis server container
sudo docker build -t <your namespace>/redis .
sudo docker run -d -p 6379:6379 <your namespace>/redis
- Install the redis-cli package:
:$ npm install redis-cli -g
### Run
-
Sloth-bucket tests are simple scripts with no dependencies on unit testing frameworks or test runners.
Get over it, cd into the /test folder, run:node test
node test1
node test2
-
Any time you want to check in on what the tests are producing, run the redis CLI:
:$ redis-cli
:$ HGETALL user:steve
- Bask in the [sloth-bucket] goodness! :)
- run
node clean
to delete the user slots, or:
:$ redis-cli
:$ DEL user:steve