Skip to content

Commit

Permalink
feat: add hincrbyfloatBuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan committed Jan 30, 2022
1 parent c843034 commit 81abd47
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 60 deletions.
2 changes: 1 addition & 1 deletion README.md
@@ -1,4 +1,4 @@
# ioredis-mock · [![npm](https://img.shields.io/npm/dm/ioredis-mock.svg?style=flat-square)](https://npm-stat.com/charts.html?package=ioredis-mock) [![npm version](https://img.shields.io/npm/v/ioredis-mock.svg?style=flat-square)](https://www.npmjs.com/package/ioredis-mock) [![Redis Compatibility: 41%](https://img.shields.io/badge/redis-41%25-red.svg?style=flat-square)](compat.md) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)](https://github.com/semantic-release/semantic-release)
# ioredis-mock · [![npm](https://img.shields.io/npm/dm/ioredis-mock.svg?style=flat-square)](https://npm-stat.com/charts.html?package=ioredis-mock) [![npm version](https://img.shields.io/npm/v/ioredis-mock.svg?style=flat-square)](https://www.npmjs.com/package/ioredis-mock) [![Redis Compatibility: 42%](https://img.shields.io/badge/redis-42%25-red.svg?style=flat-square)](compat.md) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)](https://github.com/semantic-release/semantic-release)

This library emulates [ioredis](https://github.com/luin/ioredis) by performing
all operations in-memory. The best way to do integration testing against redis
Expand Down
3 changes: 1 addition & 2 deletions compat.md
@@ -1,4 +1,4 @@
## Supported commands ![Commands Coverage: 41%](https://img.shields.io/badge/coverage-41%25-red.svg)
## Supported commands ![Commands Coverage: 42%](https://img.shields.io/badge/coverage-42%25-red.svg)

| redis | ioredis | ioredis-mock |
| ---------------------- | :----------------: | :----------------: |
Expand Down Expand Up @@ -219,7 +219,6 @@

- [evalBuffer][1]
- [evalshaBuffer][1]
- [hincrbyfloatBuffer][1]
- [hlenBuffer][1]
- [hscanBuffer][1]
- [hsetnxBuffer][1]
Expand Down
2 changes: 2 additions & 0 deletions src/commands/hincrbyfloat.js
Expand Up @@ -11,3 +11,5 @@ export function hincrbyfloat(key, field, increment) {
this.data.set(key, hash)
return hash[field]
}

export const hincrbyfloatBuffer = hincrbyfloat
115 changes: 58 additions & 57 deletions test/integration/commands/hincrbyfloat.js
@@ -1,73 +1,74 @@
import Redis from 'ioredis'

describe('hincrbyfloat', () => {
it('should increment an float with passed increment', () => {
const redis = new Redis({
data: {
mykey: { field: '10.50' },
},
})
// eslint-disable-next-line import/no-relative-parent-imports
import { runTwinSuite } from '../../../test-utils'

return redis
.hincrbyfloat('mykey', 'field', 0.1)
.then(result => {
return expect(result).toBe('10.6')
})
.then(() => {
return redis.hincrbyfloat('mykey', 'field', -5)
})
.then(result => {
return expect(result).toBe('5.6')
})
.then(() => {
return expect(redis.data.get('mykey').field).toBe('5.6')
runTwinSuite('hincrbyfloat', command => {
describe(command, () => {
it('should increment an float with passed increment', () => {
const redis = new Redis({
data: {
mykey: { field: '10.50' },
},
})
})

it('should support exponents', () => {
const redis = new Redis({
data: {
mykey: { field: '5.0e3' },
},
return redis[command]('mykey', 'field', 0.1)
.then(result => {
return expect(result).toBe('10.6')
})
.then(() => {
return redis[command]('mykey', 'field', -5)
})
.then(result => {
return expect(result).toBe('5.6')
})
.then(() => {
return expect(redis.data.get('mykey').field).toBe('5.6')
})
})

return redis
.hincrbyfloat('mykey', 'field', '2.0e2')
.then(result => {
return expect(result).toBe('5200')
})
.then(() => {
return expect(redis.data.get('mykey').field).toBe('5200')
it('should support exponents', () => {
const redis = new Redis({
data: {
mykey: { field: '5.0e3' },
},
})
})

it('should create hash if not exists', () => {
const redis = new Redis()
return redis[command]('mykey', 'field', '2.0e2')
.then(result => {
return expect(result).toBe('5200')
})
.then(() => {
return expect(redis.data.get('mykey').field).toBe('5200')
})
})

return redis
.hincrbyfloat('stats', 'health', 0.5)
.then(result => {
return expect(result).toBe('0.5')
})
.then(() => {
return expect(redis.data.get('stats').health).toBe('0.5')
})
})
it('should create hash if not exists', () => {
const redis = new Redis()

it('should create field in hash if not exists', () => {
const redis = new Redis({
data: {
stats: {},
},
return redis[command]('stats', 'health', 0.5)
.then(result => {
return expect(result).toBe('0.5')
})
.then(() => {
return expect(redis.data.get('stats').health).toBe('0.5')
})
})

return redis
.hincrbyfloat('stats', 'health', 0.5)
.then(result => {
return expect(result).toBe('0.5')
})
.then(() => {
return expect(redis.data.get('stats').health).toBe('0.5')
it('should create field in hash if not exists', () => {
const redis = new Redis({
data: {
stats: {},
},
})

return redis[command]('stats', 'health', 0.5)
.then(result => {
return expect(result).toBe('0.5')
})
.then(() => {
return expect(redis.data.get('stats').health).toBe('0.5')
})
})
})
})

0 comments on commit 81abd47

Please sign in to comment.