You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-07 13:22:56 +03:00
chore: refactor codebase to promises
This commit is contained in:
@@ -10,84 +10,75 @@ describe('prefix key names', () => {
|
||||
describe(`using ${ip}`, () => {
|
||||
let client = null
|
||||
|
||||
beforeEach((done) => {
|
||||
beforeEach(() => {
|
||||
client = redis.createClient({
|
||||
prefix: 'test:prefix:'
|
||||
})
|
||||
client.on('ready', () => {
|
||||
client.flushdb((err) => {
|
||||
done(err)
|
||||
})
|
||||
})
|
||||
return client.flushdb()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
client.end(true)
|
||||
})
|
||||
|
||||
it('auto prefix set / get', (done) => {
|
||||
client.set('key', 'value', helper.isString('OK'))
|
||||
client.get('key', helper.isString('value'))
|
||||
client.getrange('key', 1, -1, (err, reply) => {
|
||||
assert.strictEqual(reply, 'alue')
|
||||
assert.strictEqual(err, null)
|
||||
})
|
||||
client.exists('key', helper.isNumber(1))
|
||||
// The key will be prefixed itself
|
||||
client.exists('test:prefix:key', helper.isNumber(0))
|
||||
client.mset('key2', 'value2', 'key3', 'value3')
|
||||
client.keys('*', (err, res) => {
|
||||
assert.strictEqual(err, null)
|
||||
assert.strictEqual(res.length, 3)
|
||||
assert(res.indexOf('test:prefix:key') !== -1)
|
||||
assert(res.indexOf('test:prefix:key2') !== -1)
|
||||
assert(res.indexOf('test:prefix:key3') !== -1)
|
||||
done()
|
||||
})
|
||||
it('auto prefix set / get', () => {
|
||||
return Promise.all([
|
||||
client.set('key', 'value').then(helper.isString('OK')),
|
||||
client.get('key').then(helper.isString('value')),
|
||||
client.getrange('key', 1, -1).then((reply) => {
|
||||
assert.strictEqual(reply, 'alue')
|
||||
}),
|
||||
client.exists('key').then(helper.isNumber(1)),
|
||||
// The key will be prefixed itself
|
||||
client.exists('test:prefix:key').then(helper.isNumber(0)),
|
||||
client.mset('key2', 'value2', 'key3', 'value3'),
|
||||
client.keys('*').then((res) => {
|
||||
assert.strictEqual(res.length, 3)
|
||||
assert(res.includes('test:prefix:key'))
|
||||
assert(res.includes('test:prefix:key2'))
|
||||
assert(res.includes('test:prefix:key3'))
|
||||
})
|
||||
])
|
||||
})
|
||||
|
||||
it('auto prefix set / get with .batch', (done) => {
|
||||
it('auto prefix set / get with .batch', () => {
|
||||
const batch = client.batch()
|
||||
batch.set('key', 'value', helper.isString('OK'))
|
||||
batch.get('key', helper.isString('value'))
|
||||
batch.getrange('key', 1, -1, (err, reply) => {
|
||||
assert.strictEqual(reply, 'alue')
|
||||
assert.strictEqual(err, null)
|
||||
})
|
||||
batch.exists('key', helper.isNumber(1))
|
||||
batch.set('key', 'value')
|
||||
batch.get('key')
|
||||
batch.getrange('key', 1, -1)
|
||||
batch.exists('key')
|
||||
// The key will be prefixed itself
|
||||
batch.exists('test:prefix:key', helper.isNumber(0))
|
||||
batch.exists('test:prefix:key')
|
||||
batch.mset('key2', 'value2', 'key3', 'value3')
|
||||
batch.keys('*', (err, res) => {
|
||||
assert.strictEqual(err, null)
|
||||
assert.strictEqual(res.length, 3)
|
||||
assert(res.indexOf('test:prefix:key') !== -1)
|
||||
assert(res.indexOf('test:prefix:key2') !== -1)
|
||||
assert(res.indexOf('test:prefix:key3') !== -1)
|
||||
batch.keys('*')
|
||||
return batch.exec().then((res) => {
|
||||
const prefixes = res.pop()
|
||||
assert.deepStrictEqual(res, ['OK', 'value', 'alue', 1, 0, 'OK'])
|
||||
assert.strictEqual(prefixes.length, 3)
|
||||
assert(prefixes.includes('test:prefix:key'))
|
||||
assert(prefixes.includes('test:prefix:key2'))
|
||||
assert(prefixes.includes('test:prefix:key3'))
|
||||
})
|
||||
batch.exec(done)
|
||||
})
|
||||
|
||||
it('auto prefix set / get with .multi', (done) => {
|
||||
it('auto prefix set / get with .multi', () => {
|
||||
const multi = client.multi()
|
||||
multi.set('key', 'value', helper.isString('OK'))
|
||||
multi.get('key', helper.isString('value'))
|
||||
multi.getrange('key', 1, -1, (err, reply) => {
|
||||
assert.strictEqual(reply, 'alue')
|
||||
assert.strictEqual(err, null)
|
||||
})
|
||||
multi.exists('key', helper.isNumber(1))
|
||||
multi.set('key', 'value')
|
||||
multi.get('key')
|
||||
multi.getrange('key', 1, -1)
|
||||
multi.exists('key')
|
||||
// The key will be prefixed itself
|
||||
multi.exists('test:prefix:key', helper.isNumber(0))
|
||||
multi.exists('test:prefix:key')
|
||||
multi.mset('key2', 'value2', 'key3', 'value3')
|
||||
multi.keys('*', (err, res) => {
|
||||
assert.strictEqual(err, null)
|
||||
assert.strictEqual(res.length, 3)
|
||||
assert(res.indexOf('test:prefix:key') !== -1)
|
||||
assert(res.indexOf('test:prefix:key2') !== -1)
|
||||
assert(res.indexOf('test:prefix:key3') !== -1)
|
||||
multi.keys('*')
|
||||
return multi.exec().then((res) => {
|
||||
const prefixes = res.pop()
|
||||
assert.deepStrictEqual(res, ['OK', 'value', 'alue', 1, 0, 'OK'])
|
||||
assert.strictEqual(prefixes.length, 3)
|
||||
assert(prefixes.includes('test:prefix:key'))
|
||||
assert(prefixes.includes('test:prefix:key2'))
|
||||
assert(prefixes.includes('test:prefix:key3'))
|
||||
})
|
||||
multi.exec(done)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user