Skip to content

Commit

Permalink
redis - fixing lint issues and clean up (#1218)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredwray authored Nov 17, 2024
1 parent 20aacd4 commit 6c96788
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 29 deletions.
23 changes: 4 additions & 19 deletions packages/redis/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,6 @@
"test:ci": "xo && vitest --run --sequence.setupFiles=list",
"clean": "rimraf ./node_modules ./coverage ./dist"
},
"xo": {
"rules": {
"import/no-named-as-default": "off",
"unicorn/prefer-module": "off",
"unicorn/prefer-event-target": "off",
"unicorn/prefer-node-protocol": "off",
"unicorn/no-typeof-undefined": "off",
"import/extensions": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-return": "off",
"unicorn/prefer-ternary": "off",
"unicorn/no-array-callback-reference": "off",
"import/no-extraneous-dependencies": "off",
"@typescript-eslint/no-confusing-void-expression": "off"
}
},
"repository": {
"type": "git",
"url": "git+https://github.com/jaredwray/keyv.git"
Expand All @@ -58,14 +41,16 @@
},
"homepage": "https://github.com/jaredwray/keyv",
"dependencies": {
"redis": "^4.7.0",
"keyv": "*"
"keyv": "*",
"redis": "^4.7.0"
},
"devDependencies": {
"@keyv/test-suite": "*",
"@vitest/coverage-v8": "^2.1.5",
"rimraf": "^6.0.1",
"timekeeper": "^2.3.1",
"tsd": "^0.31.2",
"vitest": "^2.1.5",
"xo": "^0.59.3"
},
"tsd": {
Expand Down
12 changes: 5 additions & 7 deletions packages/redis/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import EventEmitter from 'events';
import EventEmitter from 'node:events';
import {createClient, type RedisClientType, type RedisClientOptions} from 'redis';
import {Keyv, type KeyvStoreAdapter} from 'keyv';

Expand Down Expand Up @@ -47,7 +47,7 @@ export type KeyvRedisEntry<T> = {
*/
ttl?: number;
};

// eslint-disable-next-line unicorn/prefer-event-target
export default class KeyvRedis extends EventEmitter implements KeyvStoreAdapter {
private _client: RedisClientType = createClient() as RedisClientType;
private _namespace: string | undefined;
Expand Down Expand Up @@ -193,6 +193,7 @@ export default class KeyvRedis extends EventEmitter implements KeyvStoreAdapter
public async set(key: string, value: string, ttl?: number): Promise<void> {
const client = await this.getClient();
key = this.createKeyPrefix(key, this._namespace);
// eslint-disable-next-line unicorn/prefer-ternary
if (ttl) {
// eslint-disable-next-line @typescript-eslint/naming-convention
await client.set(key, value, {PX: ttl});
Expand Down Expand Up @@ -295,11 +296,7 @@ export default class KeyvRedis extends EventEmitter implements KeyvStoreAdapter
const client = await this.getClient();
key = this.createKeyPrefix(key, this._namespace);
let deleted = 0;
if (this._useUnlink) {
deleted = await client.unlink(key);
} else {
deleted = await client.del(key);
}
deleted = await (this._useUnlink ? client.unlink(key) : client.del(key));

return deleted > 0;
}
Expand Down Expand Up @@ -437,6 +434,7 @@ export default class KeyvRedis extends EventEmitter implements KeyvStoreAdapter
}

if (keys.length > 0) {
// eslint-disable-next-line unicorn/prefer-ternary
if (this._useUnlink) {
// eslint-disable-next-line no-await-in-loop
await client.unlink(keys);
Expand Down
2 changes: 1 addition & 1 deletion packages/redis/test/suite.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as test from 'vitest';
import keyvTestSuite, {keyvIteratorTests} from '@keyv/test-suite';
import Keyv from 'keyv';
import {Keyv} from 'keyv';
import KeyvRedis from '../src/index.js';

const redisUrl = 'redis://localhost:6379/5';
Expand Down
3 changes: 2 additions & 1 deletion packages/redis/test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ describe('KeyvRedis', () => {
expect(keyv).toBeDefined();
await keyv.set('mykey', 'myvalue');
await keyv.set('mykey2', {foo: 'bar'});
const value = await keyv.get('mykey');
const value = await keyv.get<string>('mykey');
expect(value).toBe('myvalue');
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const value2 = await keyv.get('mykey2');
expect(value2).toEqual({foo: 'bar'});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/redis/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {defineConfig, mergeConfig} from 'vitest/config';
import vitestConfig from '../../vitest.general.config';
import vitestConfig from '../../vitest.general.config.js';

export default mergeConfig(vitestConfig, defineConfig({}));

0 comments on commit 6c96788

Please sign in to comment.