Batches commands like incrby, hincrby and sadd to Redis.
Redis Batch wraps a node_redis instance, and batches write commands like hincrby, incrby and sadd to Redis. For systems generating lots of writes to Redis, this can be a significant performance increase for Redis and for the machines issuing the write commands.
When we deployed redis-batch within Segment's server cluster:
Redis-batch only supports "write" commands that make sense to be batched. Of the 150+ Redis commands, redis-batch is only intended to support 34. Currently it supports 12. Not all of them are supported yet, feel free to pull request!
var RedisBatch = require'redis-batch';var redisBatch = redis; // redis instance created elsewherevar redisBatch = redis flushAfter: 3000 ;/*** hincrby batches by key:field* This will become a single "hincrby warehouse pants -6" when sent to redis.*/redisBatchhincrby'warehouse' 'pants' -2hincrby'warehouse' 'pants' -1hincrby'warehouse' 'pants' -3;/*** incrby batches by key* This will become a single "incrby projectcounter 22" when sent to redis.*/redisBatchincrby'projectcounter' 12incrby'projectcounter' 6incrby'projectcounter' 4;/*** pexpire de-duplicates by key* This will become a single "pexpire key 1000" when sent to redis.*/redisBatchpexpire'key' 1000pexpire'key' 1000pexpire'key' 1000;/*** sadd batches by key* This will become a single "sadd key member1 member2 member3" when sent to redis.*/redisBatchsadd'key' 'member1'sadd'key' 'member2'sadd'key' 'member3';
You can intermingle sadd, incrby and hincrby as you desire.
WWWWWW||WWWWWWW W W||W W W||( OO )__________/ | \/o o| MIT \\___/||_||__||_|| *|| || || ||_||_|| _||_||(__|__|(__|__|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.