-
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.
redis - adding in cluster type to constructor (#1219)
* redis - adding in cluster type to constructor * specify which client as they are unique * moving to centralized type * adding in lint fixes * adding in iterator and clear on cluster masters * adding in export of RedisClusterType and RedisClusterOptions * adding in jsDoc * adding in tests but will break * adding in redis cluster compose * updating tls and test:services:start * adding in docker compose stop * throwing errors if cluster on clear and iterator * updating contributing * adding in context on clustering issues because of no SCAN * adding in valkey * updating contributing instructions
- Loading branch information
Showing
12 changed files
with
233 additions
and
43 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
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,39 @@ | ||
x-redis-cluster-base: &redis-cluster-base | ||
image: docker.io/bitnami/redis-cluster:latest | ||
network_mode: host | ||
|
||
services: | ||
redis-cluster-1: | ||
container_name: redis-cluster-1 | ||
<<: *redis-cluster-base | ||
environment: | ||
- 'ALLOW_EMPTY_PASSWORD=yes' | ||
- 'REDIS_NODES=127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003' | ||
- 'REDIS_CLUSTER_DYNAMIC_IPS=no' | ||
- 'REDIS_CLUSTER_ANNOUNCE_IP=127.0.0.1' | ||
- 'REDIS_PORT_NUMBER=7001' | ||
|
||
redis-cluster-2: | ||
container_name: redis-cluster-2 | ||
<<: *redis-cluster-base | ||
environment: | ||
- 'ALLOW_EMPTY_PASSWORD=yes' | ||
- 'REDIS_NODES=127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003' | ||
- 'REDIS_CLUSTER_DYNAMIC_IPS=no' | ||
- 'REDIS_CLUSTER_ANNOUNCE_IP=127.0.0.1' | ||
- 'REDIS_PORT_NUMBER=7002' | ||
|
||
redis-cluster-3: | ||
container_name: redis-cluster-3 | ||
<<: *redis-cluster-base | ||
depends_on: | ||
- redis-cluster-1 | ||
- redis-cluster-2 | ||
environment: | ||
- 'ALLOW_EMPTY_PASSWORD=yes' | ||
- 'REDIS_NODES=127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003' | ||
- 'REDIS_CLUSTER_DYNAMIC_IPS=no' | ||
- 'REDIS_CLUSTER_ANNOUNCE_IP=127.0.0.1' | ||
- 'REDIS_PORT_NUMBER=7003' | ||
- 'REDIS_CLUSTER_REPLICAS=0' | ||
- 'REDIS_CLUSTER_CREATOR=yes' |
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,100 @@ | ||
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.delete('test-cl1'); | ||
|
||
const undefinedResult = await keyvRedis.get('test-cl1'); | ||
expect(undefinedResult).toBeUndefined(); | ||
|
||
await keyvRedis.set('test-cl1', 'test'); | ||
|
||
const result = await keyvRedis.get('test-cl1'); | ||
|
||
expect(result).toBe('test'); | ||
|
||
await keyvRedis.delete('test-cl1'); | ||
}); | ||
|
||
test('should thrown an error on clear', async () => { | ||
const cluster = createCluster(defaultClusterOptions); | ||
|
||
const keyvRedis = new KeyvRedis(cluster); | ||
|
||
let errorThrown = false; | ||
try { | ||
await keyvRedis.clear(); | ||
} catch (error) { | ||
expect(error).toBeDefined(); | ||
errorThrown = true; | ||
} | ||
|
||
expect(errorThrown).toBe(true); | ||
}); | ||
|
||
test('should throw an error on iterator', async () => { | ||
const cluster = createCluster(defaultClusterOptions); | ||
|
||
const keyvRedis = new KeyvRedis(cluster); | ||
|
||
let errorThrown = false; | ||
try { | ||
const keys = []; | ||
const values = []; | ||
for await (const [key, value] of keyvRedis.iterator('foo')) { | ||
keys.push(key); | ||
values.push(value); | ||
} | ||
} catch (error) { | ||
expect(error).toBeDefined(); | ||
errorThrown = true; | ||
} | ||
|
||
expect(errorThrown).toBe(true); | ||
}); | ||
}); |
Oops, something went wrong.