-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
83 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import {describe, test, expect} from 'vitest'; | ||
import KeyvRedis, {createCluster} from '../src/index.js'; | ||
|
||
const defaultClusterOptions = { | ||
rootNodes: [ | ||
{ | ||
url: 'redis://localhost:7001', | ||
}, | ||
{ | ||
url: 'redis://localhost:7002', | ||
}, | ||
{ | ||
url: 'redis://localhost:7003', | ||
}, | ||
], | ||
useReplicas: true, | ||
}; | ||
|
||
describe('KeyvRedis Cluster', () => { | ||
test('should be able to connect to a cluster', async () => { | ||
const cluster = createCluster(defaultClusterOptions); | ||
|
||
const keyvRedis = new KeyvRedis(cluster); | ||
|
||
expect(keyvRedis).toBeDefined(); | ||
expect(keyvRedis.client).toEqual(cluster); | ||
}); | ||
|
||
test('should be able to send in cluster options', async () => { | ||
const keyvRedis = new KeyvRedis(defaultClusterOptions); | ||
expect(keyvRedis.isCluster()).toBe(true); | ||
}); | ||
|
||
test('shoudl be able to set the redis cluster client', async () => { | ||
const cluster = createCluster(defaultClusterOptions); | ||
|
||
const keyvRedis = new KeyvRedis(); | ||
expect(keyvRedis.isCluster()).toBe(false); | ||
|
||
keyvRedis.client = cluster; | ||
expect(keyvRedis.client).toEqual(cluster); | ||
expect(keyvRedis.isCluster()).toBe(true); | ||
}); | ||
|
||
test('should be able to set a value', async () => { | ||
const cluster = createCluster(defaultClusterOptions); | ||
|
||
const keyvRedis = new KeyvRedis(cluster); | ||
|
||
await keyvRedis.set('test-cl', 'test'); | ||
|
||
const result = await keyvRedis.get('test-cl'); | ||
|
||
expect(result).toBe('test'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters