Skip to content

Commit

Permalink
fix: remove legacy nodev6 buffer support
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan committed Mar 23, 2021
1 parent 1a52d23 commit 2d745e7
Show file tree
Hide file tree
Showing 20 changed files with 29 additions and 73 deletions.
6 changes: 0 additions & 6 deletions src/buffer.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/commands/append.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import createBuffer from '../buffer';


export function append(key, value) {
if (!this.data.has(key)) {
Expand All @@ -7,7 +7,7 @@ export function append(key, value) {
if (value instanceof Buffer) {
this.data.set(
key,
Buffer.concat([createBuffer(this.data.get(key)), value])
Buffer.concat([Buffer.from(this.data.get(key)), value])
);
} else {
this.data.set(key, this.data.get(key) + value);
Expand Down
4 changes: 2 additions & 2 deletions src/commands/brpoplpushBuffer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { brpoplpush } from './brpoplpush';
import createBuffer from '../buffer';


export function brpoplpushBuffer(source, destination) {
const valP = brpoplpush.apply(this, [source, destination]);
return valP.then((val) => (val ? createBuffer(val) : val));
return valP.then((val) => (val ? Buffer.from(val) : val));
}
3 changes: 1 addition & 2 deletions src/commands/getBuffer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { get } from './get';
import createBuffer from '../buffer';

export function getBuffer(key) {
const val = get.apply(this, [key]);
return val ? createBuffer(val) : val;
return val ? Buffer.from(val) : val;
}
3 changes: 1 addition & 2 deletions src/commands/hgetBuffer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { hget } from './hget';
import createBuffer from '../buffer';

export function hgetBuffer(key, hashKey) {
const val = hget.apply(this, [key, hashKey]);
return val ? createBuffer(val) : val;
return val ? Buffer.from(val) : val;
}
3 changes: 1 addition & 2 deletions src/commands/hgetallBuffer.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { hgetall } from './hgetall';
import createBuffer from '../buffer';

export function hgetallBuffer(key) {
const val = hgetall.apply(this, [key]);
Object.keys(val).forEach((keyInObject) => {
val[keyInObject] = createBuffer(val[keyInObject]);
val[keyInObject] = Buffer.from(val[keyInObject]);
});

return val;
Expand Down
3 changes: 1 addition & 2 deletions src/commands/hmgetBuffer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { hmget } from './hmget';
import createBuffer from '../buffer';

export function hmgetBuffer(key, ...fields) {
const val = hmget.apply(this, [key, ...fields]);
return val.map((payload) => (payload ? createBuffer(payload) : payload));
return val.map((payload) => (payload ? Buffer.from(payload) : payload));
}
3 changes: 1 addition & 2 deletions src/commands/lpopBuffer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { lpop } from './lpop';
import createBuffer from '../buffer';

export function lpopBuffer(key) {
const val = lpop.apply(this, [key]);
return val ? createBuffer(val) : val;
return val ? Buffer.from(val) : val;
}
6 changes: 2 additions & 4 deletions src/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import Set from 'es6-set';
import Map from 'es6-map';
import { assign } from 'lodash';

import createBuffer from './buffer';

export default function createData(
expiresInstance,
initial = {},
Expand Down Expand Up @@ -34,7 +32,7 @@ export default function createData(
}

if (Buffer.isBuffer(value)) {
return createBuffer(value);
return Buffer.from(value);
}

if (value instanceof Set) {
Expand Down Expand Up @@ -67,7 +65,7 @@ export default function createData(
if (Array.isArray(val)) {
item = val.slice();
} else if (Buffer.isBuffer(val)) {
item = createBuffer(val);
item = Buffer.from(val);
} else if (val instanceof Set) {
item = new Set(val);
} else if (val instanceof Map) {
Expand Down
21 changes: 0 additions & 21 deletions test/buffer.js

This file was deleted.

5 changes: 2 additions & 3 deletions test/command.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import createBuffer from '../src/buffer';
import command from '../src/command';

describe('basic command', () => {
Expand All @@ -14,9 +13,9 @@ describe('basic command', () => {
});

it('should convert non-buffer arguments to strings', () => {
const args = [createBuffer('foo'), 'bar', 1, null, undefined];
const args = [Buffer.from('foo'), 'bar', 1, null, undefined];
return stub(...args).then((reply) =>
expect(reply).toEqual([createBuffer('foo'), 'bar', '1', '', ''])
expect(reply).toEqual([Buffer.from('foo'), 'bar', '1', '', ''])
);
});

Expand Down
3 changes: 1 addition & 2 deletions test/commands/brpoplpushBuffer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import MockRedis from 'ioredis';
import createBuffer from '../../src/buffer';

describe('brpoplpushBuffer', () => {
it('should remove one item from the tail of the source list', () => {
Expand Down Expand Up @@ -63,7 +62,7 @@ describe('brpoplpushBuffer', () => {
});

it('should return buffer values correctly', () => {
const bufferVal = createBuffer('bar');
const bufferVal = Buffer.from('bar');
const redis = new MockRedis({
data: {
foo: ['foo', bufferVal],
Expand Down
3 changes: 1 addition & 2 deletions test/commands/getBuffer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import MockRedis from 'ioredis';
import createBuffer from '../../src/buffer';

describe('getBuffer', () => {
it('should return null on keys that do not exist', () => {
Expand All @@ -22,7 +21,7 @@ describe('getBuffer', () => {
});

it('should return buffer values correctly', () => {
const bufferVal = createBuffer('bar');
const bufferVal = Buffer.from('bar');
const redis = new MockRedis({
data: {
foo: bufferVal,
Expand Down
3 changes: 1 addition & 2 deletions test/commands/hgetBuffer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import MockRedis from 'ioredis';
import createBuffer from '../../src/buffer';

describe('hgetBuffer', () => {
it('should fetch a property in a hash', () => {
Expand All @@ -13,7 +12,7 @@ describe('hgetBuffer', () => {

return redis.hgetBuffer('emails', 'clark@daily.planet').then((userId) => {
expect(Buffer.isBuffer(userId)).toBeTruthy();
expect(userId).toEqual(createBuffer('1'));
expect(userId).toEqual(Buffer.from('1'));
});
});

Expand Down
5 changes: 2 additions & 3 deletions test/commands/hgetallBuffer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import MockRedis from 'ioredis';
import createBuffer from '../../src/buffer';

describe('hgetallBuffer', () => {
it('should return all the keys and values in a hash map as buffer', () => {
Expand All @@ -8,8 +7,8 @@ describe('hgetallBuffer', () => {
'bruce@wayne.enterprises': '2',
};
const expected = {
'clark@daily.planet': createBuffer('1'),
'bruce@wayne.enterprises': createBuffer('2'),
'clark@daily.planet': Buffer.from('1'),
'bruce@wayne.enterprises': Buffer.from('2'),
};
const redis = new MockRedis({
data: {
Expand Down
5 changes: 2 additions & 3 deletions test/commands/hmgetBuffer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import MockRedis from 'ioredis';
import createBuffer from '../../src/buffer';

describe('hmgetBuffer', () => {
it('should return the values as buffers of specified keys in a hash map', () => {
Expand All @@ -15,8 +14,8 @@ describe('hmgetBuffer', () => {
expect(Buffer.isBuffer(values[1])).toBeTruthy();
expect(Buffer.isBuffer(values[2])).toBeFalsy();
expect(values).toEqual([
createBuffer('1'),
createBuffer('bruce@wayne.enterprises'),
Buffer.from('1'),
Buffer.from('bruce@wayne.enterprises'),
null,
]);
});
Expand Down
7 changes: 3 additions & 4 deletions test/commands/lpopBuffer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import MockRedis from 'ioredis';
import createBuffer from '../../src/buffer';

describe('lpopBuffer', () => {
it('should remove and return first element of list', () => {
Expand All @@ -11,12 +10,12 @@ describe('lpopBuffer', () => {

return redis
.lpopBuffer('foo')
.then((result) => expect(result).toEqual(createBuffer('3')))
.then((result) => expect(result).toEqual(Buffer.from('3')))
.then(() => expect(redis.data.get('foo')).toEqual(['2', '1']));
});

it('should return buffer values correctly as buffer', () => {
const bufferVal = createBuffer('bar');
const bufferVal = Buffer.from('bar');
const redis = new MockRedis({
data: {
foo: [bufferVal, '2', '1'],
Expand All @@ -32,7 +31,7 @@ describe('lpopBuffer', () => {
})
.then((result) => {
expect(Buffer.isBuffer(result)).toBeTruthy();
expect(result).toEqual(createBuffer('2'));
expect(result).toEqual(Buffer.from('2'));
});
});

Expand Down
3 changes: 1 addition & 2 deletions test/commands/rpopBuffer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import MockRedis from 'ioredis';
import createBuffer from '../../src/buffer';

describe('rpopBuffer', () => {
it('should remove and return last element of list', () => {
Expand All @@ -16,7 +15,7 @@ describe('rpopBuffer', () => {
});

it('should return buffer values correctly', () => {
const bufferVal = createBuffer('bar');
const bufferVal = Buffer.from('bar');
const redis = new MockRedis({
data: {
foo: ['1', '2', bufferVal],
Expand Down
3 changes: 1 addition & 2 deletions test/commands/rpoplpushBuffer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import MockRedis from 'ioredis';
import createBuffer from '../../src/buffer';

describe('rpoplpushBuffer', () => {
it('should remove one item from the tail of the source list', () => {
Expand Down Expand Up @@ -60,7 +59,7 @@ describe('rpoplpushBuffer', () => {
});

it('should return buffer values correctly', () => {
const bufferVal = createBuffer('bar');
const bufferVal = Buffer.from('bar');
const redis = new MockRedis({
data: {
foo: ['foo', bufferVal],
Expand Down
9 changes: 4 additions & 5 deletions test/data.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Set from 'es6-set';

import createBuffer from '../src/buffer';
import createData from '../src/data';
import createExpires from '../src/expires';

Expand Down Expand Up @@ -34,7 +33,7 @@ describe('get', () => {
data = createData(createExpires(), {
myString: 'qwerty',
mySet: new Set([1, 2, 3]),
myBuffer: createBuffer([0x31, 0x32, 0x33]),
myBuffer: Buffer.from([0x31, 0x32, 0x33]),
myArray: [1, 2, 3],
myObject: { a: 1, b: 2, c: 3 },
});
Expand Down Expand Up @@ -65,7 +64,7 @@ describe('get', () => {
it('should return buffer copies from the cache', () => {
const myBuffer = data.get('myBuffer');
myBuffer[0] = 0x32;
expect(data.get('myBuffer')).toEqual(createBuffer([0x31, 0x32, 0x33]));
expect(data.get('myBuffer')).toEqual(Buffer.from([0x31, 0x32, 0x33]));
});
});

Expand Down Expand Up @@ -103,9 +102,9 @@ describe('set', () => {
});

it('should set copies of buffers in the cache', () => {
const myBuffer = createBuffer([0x31, 0x32, 0x33]);
const myBuffer = Buffer.from([0x31, 0x32, 0x33]);
data.set('myBuffer', myBuffer);
myBuffer[0] = 0x32;
expect(data.get('myBuffer')).toEqual(createBuffer([0x31, 0x32, 0x33]));
expect(data.get('myBuffer')).toEqual(Buffer.from([0x31, 0x32, 0x33]));
});
});

0 comments on commit 2d745e7

Please sign in to comment.