You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-09 00:22:08 +03:00
54 lines
1.3 KiB
JavaScript
54 lines
1.3 KiB
JavaScript
'use strict'
|
|
|
|
var redis = require('redis')
|
|
var client = redis.createClient()
|
|
var setSize = 20
|
|
|
|
client.sadd('bigset', 'a member')
|
|
client.sadd('bigset', 'another member')
|
|
|
|
while (setSize > 0) {
|
|
client.sadd('bigset', 'member ' + setSize)
|
|
setSize -= 1
|
|
}
|
|
|
|
// multi chain with an individual callback
|
|
client.multi()
|
|
.scard('bigset')
|
|
.smembers('bigset')
|
|
.keys('*', function (err, replies) {
|
|
if (err) throw err
|
|
client.mget(replies, console.log)
|
|
})
|
|
.dbsize()
|
|
.exec(function (err, replies) {
|
|
if (err) throw err
|
|
console.log('MULTI got ' + replies.length + ' replies')
|
|
replies.forEach(function (reply, index) {
|
|
console.log('Reply ' + index + ': ' + reply.toString())
|
|
})
|
|
})
|
|
|
|
client.mset('incr thing', 100, 'incr other thing', 1, console.log)
|
|
|
|
// start a separate multi command queue
|
|
var multi = client.multi()
|
|
multi.incr('incr thing', console.log)
|
|
multi.incr('incr other thing', console.log)
|
|
|
|
// runs immediately
|
|
client.get('incr thing', console.log) // 100
|
|
|
|
// drains multi queue and runs atomically
|
|
multi.exec(function (err, replies) {
|
|
if (err) throw err
|
|
console.log(replies) // 101, 2
|
|
})
|
|
|
|
// you can re-run the same transaction if you like
|
|
multi.exec(function (err, replies) {
|
|
if (err) throw err
|
|
console.log(replies) // 102, 3
|
|
client.quit()
|
|
})
|