Skip to content

Commit

Permalink
feat: add psetexBuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan committed Jan 30, 2022
1 parent 2059b13 commit e3866a7
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 25 deletions.
1 change: 0 additions & 1 deletion compat.md
Expand Up @@ -242,7 +242,6 @@
- [persistBuffer][1]
- [pexpireBuffer][1]
- [pexpireatBuffer][1]
- [psetexBuffer][1]
- [psubscribeBuffer][1]
- [pttlBuffer][1]
- [publishBuffer][1]
Expand Down
1 change: 0 additions & 1 deletion jest.config.redis.js
Expand Up @@ -50,7 +50,6 @@ module.exports = {
'test/integration/commands/persist.js',
'test/integration/commands/pexpire.js',
'test/integration/commands/pexpireat.js',
'test/integration/commands/psetex.js',
'test/integration/commands/psubscribe.js',
'test/integration/commands/pttl.js',
'test/integration/commands/publish.js',
Expand Down
5 changes: 5 additions & 0 deletions src/commands/psetex.js
Expand Up @@ -7,3 +7,8 @@ export function psetex(key, milliseconds, value) {

return 'OK'
}

export function psetexBuffer(...args) {
const val = psetex.apply(this, args)
return val ? Buffer.from(val) : val
}
42 changes: 21 additions & 21 deletions test/integration/commands/psetex.js
@@ -1,26 +1,26 @@
import Promise from 'bluebird'
import Redis from 'ioredis'

describe('psetex', () => {
it('should set value and expire', () => {
const redis = new Redis()
return redis
.psetex('foo', 100, 'bar')
.then(status => {
return expect(status).toBe('OK')
})
.then(() => {
expect(redis.data.get('foo')).toBe('bar')
expect(redis.expires.has('foo')).toBe(true)
})
.then(() => {
return Promise.delay(200)
})
.then(() => {
return redis.get('foo')
})
.then(result => {
return expect(result).toBe(null)
// eslint-disable-next-line import/no-relative-parent-imports
import { runTwinSuite } from '../../../test-utils'

runTwinSuite('psetex', (command, equals) => {
describe(command, () => {
it('should set value and expire', async () => {
const redis = new Redis()

const status = await redis[command]('foo', 100, 'bar')
expect(equals(status, 'OK')).toBe(true)
expect(await redis.get('foo')).toBe('bar')
expect(await redis.pttl('foo')).toBeGreaterThan(0)

await new Promise(resolve => {
return setTimeout(resolve, 200)
})

expect(await redis.get('foo')).toBe(null)
expect(await redis.pttl('foo')).toBe(-2)

redis.disconnect()
})
})
})
11 changes: 9 additions & 2 deletions test/integration/commands/setex.js
Expand Up @@ -8,10 +8,17 @@ runTwinSuite('setex', (command, equals) => {
it('should set value and expire', async () => {
const redis = new Redis()

const status = await redis[command]('foo', 10, 'bar')
const status = await redis[command]('foo', 1, 'bar')
expect(equals(status, 'OK')).toBe(true)
expect(await redis.get('foo')).toBe('bar')
expect(await redis.ttl('foo')).toBeGreaterThan(0)
expect(await redis.ttl('foo')).toBe(1)

await new Promise(resolve => {
return setTimeout(resolve, 1500)
})

expect(await redis.get('foo')).toBe(null)
expect(await redis.ttl('foo')).toBe(-2)

redis.disconnect()
})
Expand Down

0 comments on commit e3866a7

Please sign in to comment.