Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding in etcd as iterable #1228

Merged
merged 2 commits into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/etcd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"devDependencies": {
"@keyv/test-suite": "*",
"c8": "^10.1.2",
"keyv": "*",
"keyv": "workspace:*",
"requirable": "^1.0.5",
"rimraf": "^6.0.1",
"ts-node": "^10.9.2",
Expand Down
2 changes: 2 additions & 0 deletions packages/etcd/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type KeyvEtcdOptions = {
uri?: string;
ttl?: number;
busyTimeout?: number;
dialect?: 'etcd';
};

export class KeyvEtcd<Value = any> extends EventEmitter {
Expand Down Expand Up @@ -42,6 +43,7 @@ export class KeyvEtcd<Value = any> extends EventEmitter {
url: '127.0.0.1:2379',
...url,
...options,
dialect: 'etcd',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the dialect: 'etcd' option when initializing KeyvEtcd.

};

this.opts.url = this.opts.url!.replace(/^etcd:\/\//, '');
Expand Down
21 changes: 20 additions & 1 deletion packages/etcd/test/test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import * as test from 'vitest';
import Keyv from 'keyv';
import keyvTestSuite from '@keyv/test-suite';
import keyvTestSuite, {keyvIteratorTests} from '@keyv/test-suite';
import KeyvEtcd from '../src/index';

const etcdUrl = 'etcd://127.0.0.1:2379';

const store = () => new KeyvEtcd({uri: etcdUrl, busyTimeout: 3000});

keyvTestSuite(test, Keyv, store);
keyvIteratorTests(test, Keyv, store);

test.beforeEach(async () => {
const keyv = new KeyvEtcd(etcdUrl);
Expand All @@ -18,6 +19,7 @@ test.it('default options', t => {
const store = new KeyvEtcd();
t.expect(store.opts).toEqual({
url: '127.0.0.1:2379',
dialect: 'etcd',
});
});

Expand All @@ -26,6 +28,7 @@ test.it('enable ttl using default url', t => {
t.expect(store.opts).toEqual({
url: '127.0.0.1:2379',
ttl: 1000,
dialect: 'etcd',
});
t.expect(store.ttlSupport).toBeTruthy();
});
Expand All @@ -36,15 +39,30 @@ test.it('disable ttl using default url', t => {
t.expect(store.opts).toEqual({
url: '127.0.0.1:2379',
ttl: true,
dialect: 'etcd',
});
t.expect(store.ttlSupport).toBeFalsy();
});

test.it('enable ttl using url', t => {
const store = new KeyvEtcd({
url: '127.0.0.1:2379',
ttl: 1000,
});
t.expect(store.opts).toEqual({
url: '127.0.0.1:2379',
ttl: 1000,
dialect: 'etcd',
});
t.expect(store.ttlSupport).toBeTruthy();
});

test.it('enable ttl using url and options', t => {
const store = new KeyvEtcd('127.0.0.1:2379', {ttl: 1000});
t.expect(store.opts).toEqual({
url: '127.0.0.1:2379',
ttl: 1000,
dialect: 'etcd',
});
t.expect(store.ttlSupport).toBeTruthy();
});
Expand All @@ -55,6 +73,7 @@ test.it('disable ttl using url and options', t => {
t.expect(store.opts).toEqual({
url: '127.0.0.1:2379',
ttl: true,
dialect: 'etcd',
});
t.expect(store.ttlSupport).toBeFalsy();
});
Expand Down
1 change: 1 addition & 0 deletions packages/keyv/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ const iterableAdapters = [
'mongo',
'redis',
'valkey',
'etcd',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add etcd to iterableAdapters.

];

export class Keyv<GenericValue = any> extends EventManager {
Expand Down
Loading