generated from tiramisulabs/monorepo
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(RedisAdapter): change redis client
- Loading branch information
Showing
5 changed files
with
126 additions
and
11 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,72 @@ | ||
const { strict } = require("node:assert/strict"); | ||
const { test, describe, after, before } = require('node:test'); | ||
const { RedisAdapter } = require('../lib/adapter'); | ||
|
||
describe('RedisAdapter', async () => { | ||
const bulk = [['key1', { value: 'value1' }], ['key2', { value: 'value2' }]] | ||
|
||
const adapter = new RedisAdapter({ | ||
redisOptions: { | ||
host: 'localhost', | ||
port: 6379, | ||
}, | ||
namespace: 'test', | ||
}); | ||
|
||
before(async () => { | ||
// Clean the Redis instance before each test | ||
await adapter.flush(); | ||
|
||
}); | ||
|
||
await test('constructor', () => { | ||
strict.strictEqual(adapter.isAsync, true); | ||
strict.strictEqual(adapter.namespace, 'test'); | ||
}); | ||
|
||
await test('get', async () => { | ||
const result = await adapter.get('testKey'); | ||
strict.deepStrictEqual(result, undefined); | ||
}); | ||
|
||
await test('set', async () => { | ||
await strict.doesNotReject(async () => { | ||
await adapter.set('testKey', { value: 'testValue' }); | ||
}); | ||
}); | ||
|
||
await test('bulkSet', async () => { | ||
await strict.doesNotReject(async () => { | ||
await adapter.bulkSet(bulk); | ||
}); | ||
}); | ||
|
||
await test('bulkGet', async () => { | ||
const result = await adapter.bulkGet(['key1', 'key2']); | ||
strict.deepStrictEqual(result, bulk.map(x => x[1])); | ||
}); | ||
|
||
|
||
|
||
await test('patch', async () => { | ||
await strict.doesNotReject(async () => { | ||
await adapter.patch(false, 'testKey', { newValue: 'updatedValue' }); | ||
}); | ||
}); | ||
|
||
await test('bulkPatch', async () => { | ||
await strict.doesNotReject(async () => { | ||
await adapter.bulkPatch(false, [['key1', { newValue: 'updatedValue1' }], ['key2', { newValue: 'updatedValue2' }]]); | ||
}); | ||
}); | ||
|
||
await test('scan', async () => { | ||
const result = await adapter.scan('test*'); | ||
strict.strictEqual(result.length, 3); | ||
}); | ||
|
||
after(async () => { | ||
await adapter.flush(); | ||
await adapter.client.quit(); | ||
}); | ||
}); |
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,37 @@ | ||
const { describe, test, after, before } = require('node:test'); | ||
const { Cache, Client } = require('seyfert'); | ||
const { RedisAdapter } = require('../lib/index'); | ||
const { doesNotReject } = require('node:assert/strict'); | ||
const { setTimeout } = require('node:timers/promises'); | ||
const { doesNotThrow } = require('node:assert/strict'); | ||
|
||
// all intents | ||
const intents = 53608447; | ||
|
||
describe('Test Adapter cache', async t => { | ||
const adapter = new RedisAdapter({ | ||
redisOptions: { | ||
host: 'localhost', | ||
port: 6379, | ||
}, | ||
namespace: 'test_cache', | ||
}); | ||
|
||
test('discord cache', async () => { | ||
doesNotThrow(async () => { | ||
const client = new Client({ getRC: () => ({ intents }) }); | ||
client.setServices({ | ||
cache: { | ||
adapter, | ||
} | ||
}) | ||
await client.cache.testAdapter(); | ||
}); | ||
await setTimeout(5000); | ||
}); | ||
|
||
after(async () => { | ||
await adapter.flush() | ||
await adapter.client.quit(); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.