Skip to content

Commit

Permalink
feat: add strlenBuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan committed Jan 30, 2022
1 parent 5f208f8 commit 6f82dd8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
1 change: 0 additions & 1 deletion compat.md
Expand Up @@ -241,7 +241,6 @@
- [srandmemberBuffer][1]
- [sremBuffer][1]
- [sscanBuffer][1]
- [strlenBuffer][1]
- [subscribeBuffer][1]
- [sunionBuffer][1]
- [sunionstoreBuffer][1]
Expand Down
1 change: 0 additions & 1 deletion jest.config.redis.js
Expand Up @@ -61,7 +61,6 @@ module.exports = {
'test/integration/commands/srem.js',
'test/integration/commands/sscan.js',
'test/integration/commands/sscanStream.js',
'test/integration/commands/strlen.js',
'test/integration/commands/subscribe.js',
'test/integration/commands/sunion.js',
'test/integration/commands/sunionstore.js',
Expand Down
2 changes: 2 additions & 0 deletions src/commands/strlen.js
@@ -1,3 +1,5 @@
export function strlen(key) {
return this.data.has(key) ? this.data.get(key).length : 0
}

export const strlenBuffer = strlen
34 changes: 20 additions & 14 deletions test/integration/commands/strlen.js
@@ -1,23 +1,29 @@
import Redis from 'ioredis'

describe('strlen', () => {
it('should return 0 on keys that do not exist', () => {
const redis = new Redis()
// eslint-disable-next-line import/no-relative-parent-imports
import { runTwinSuite } from '../../../test-utils'

return redis.strlen('nonexisting').then(result => {
return expect(result).toBe(0)
})
})
runTwinSuite('strlen', command => {
describe(command, () => {
it('should return 0 on keys that do not exist', async () => {
const redis = new Redis()

expect(await redis[command]('nonexisting')).toBe(0)

it('should return string length of keys that do exist', () => {
const redis = new Redis({
data: {
mykey: 'Hello world',
},
redis.disconnect()
})

return redis.strlen('mykey').then(result => {
return expect(result).toBe(11)
it('should return string length of keys that do exist', async () => {
const redis = new Redis({
data: {
mykey: 'Hello world',
},
})
await redis.set('mykey', 'Hello world')

expect(await redis[command]('mykey')).toBe(11)

redis.disconnect()
})
})
})

0 comments on commit 6f82dd8

Please sign in to comment.