hemera-redis-store
Version:
193 lines (177 loc) • 4.39 kB
JavaScript
const tap = require("tap")
const Hemera = require('nats-hemera')
const Nats = require("hemera-testsuite/nats")
const nats = new Nats()
const hemera = new Hemera(nats)
hemera.register(require("./init"))
function init(){
const client = hemera.redis.client
client.del('hash')
client.hset('hash', 'test1', 2)
client.hset('hash', 'integer', 200)
}
hemera.ready(() => {
init()
tap.test('这是一个关于Redis hash类型的(hset)测试', (t) => {
t.plan(1);
hemera.act({
topic: 'redis-store',
cmd: 'hset',
hash_key: 'hash',
sub_key: 'test',
value: { name: 'name', value: 'value' }
}).then(resp => {
t.equal(1, resp.data)
}, err => {
t.error(err)
})
})
tap.test('这是一个关于Redis hash类型的(hget)测试', (t) => {
t.plan(1);
hemera.act({
topic: 'redis-store',
cmd: 'hget',
hash_key: 'hash',
sub_key: 'test'
}).then(resp => {
t.equal('{"name":"name","value":"value"}', resp.data)
}, err => {
t.error(err)
})
})
tap.test('这是一个关于Redis hash类型的(hgetall)测试', (t) => {
t.plan(1);
hemera.act({
topic: 'redis-store',
cmd: 'hgetall',
hash_key: 'hash'
}).then(resp => {
t.equal('2', resp.data.test1)
}, err => {
t.error(err)
})
})
tap.test('这是一个关于Redis hash类型的(hdel)测试', (t) => {
t.plan(1);
hemera.act({
topic: 'redis-store',
cmd: 'hdel',
hash_key: 'hash',
sub_key: 'test1'
}).then(resp => {
t.equal(1, resp.data)
}, err => {
t.error(err)
})
})
tap.test('这是一个关于Redis hash类型的(hmset)测试', (t) => {
t.plan(1);
hemera.act({
topic: 'redis-store',
cmd: 'hmset',
hash_key: 'hash',
obj: {
name: 'name',
pass: 'password'
}
}).then(resp => {
t.equal('OK', resp.data)
}, err => {
t.error(err)
})
})
tap.test('这是一个关于Redis hash类型的(hmget)测试', (t) => {
t.plan(1);
hemera.act({
topic: 'redis-store',
cmd: 'hmget',
hash_key: 'hash',
array: ['name', 'pass']
}).then(resp => {
t.equal('password', resp.data[1])
}, err => {
t.error(err)
})
})
tap.test('这是一个关于Redis hash类型的(hlen)测试', (t) => {
t.plan(1);
hemera.act({
topic: 'redis-store',
cmd: 'hlen',
hash_key: 'hash'
}).then(resp => {
t.equal(4, resp.data)
}, err => {
t.error(err)
})
})
tap.test('这是一个关于Redis hash类型的(hexists)测试', (t) => {
t.plan(1);
hemera.act({
topic: 'redis-store',
cmd: 'hexists',
hash_key: 'hash',
sub_key: 'test'
}).then(resp => {
t.equal(1, resp.data)
}, err => {
t.error(err)
})
})
tap.test('这是一个关于Redis hash类型的(hkeys)测试', (t) => {
t.plan(1);
hemera.act({
topic: 'redis-store',
cmd: 'hkeys',
hash_key: 'hash'
}).then(resp => {
t.equal(4, resp.data.length)
}, err => {
t.error(err)
})
})
tap.test('这是一个关于Redis hash类型的(hvals)测试', (t) => {
t.plan(1);
hemera.act({
topic: 'redis-store',
cmd: 'hvals',
hash_key: 'hash'
}).then(resp => {
t.equal(4, resp.data.length)
}, err => {
t.error(err)
})
})
tap.test('这是一个关于Redis hash类型的(hincrby)测试', (t) => {
t.plan(1);
hemera.act({
topic: 'redis-store',
cmd: 'hincrby',
hash_key: 'hash',
sub_key: 'integer',
number: 300
}).then(resp => {
t.equal(500, resp.data)
}, err => {
t.error(err)
})
})
tap.test('这是一个关于Redis hash类型的(hincrbyfloat)测试', (t) => {
t.plan(1);
hemera.act({
topic: 'redis-store',
cmd: 'hincrbyfloat',
hash_key: 'hash',
sub_key: 'integer',
number: 20.1314
}).then(resp => {
t.ok(resp.data.indexOf('520.1314') >= 0)
}, err => {
t.error(err)
})
})
})
tap.tearDown(() => {
console.log("tap.tearDown")
hemera.close()
})