-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from streamich/server
Server
- Loading branch information
Showing
30 changed files
with
607 additions
and
77 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 @@ | ||
// npx ts-node src/__bench__/GET.bench.ts | ||
|
||
/* tslint:disable no-console */ | ||
|
||
import {Suite} from 'benchmark'; | ||
import * as net from 'net'; | ||
import {StandaloneClient} from '../standalone'; | ||
import * as config from '../__tests__/config'; | ||
import {RespEncoder} from 'json-joy/es2020/json-pack/resp'; | ||
import {RespStreamingDecoder} from 'json-joy/es2020/json-pack/resp/RespStreamingDecoder'; | ||
import {Redis} from 'ioredis'; | ||
import {createClient} from 'redis'; | ||
import {ReconnectingSocket} from '../util/ReconnectingSocket'; | ||
|
||
const host = config.standalone.host; | ||
const port = config.standalone.port; | ||
const client = new StandaloneClient({ | ||
socket: new ReconnectingSocket({ | ||
createSocket: () => net.connect({host, port}), | ||
}), | ||
encoder: new RespEncoder(), | ||
decoder: new RespStreamingDecoder(), | ||
}); | ||
client.start(); | ||
|
||
const ioredis = new Redis({ | ||
host, | ||
port, | ||
}); | ||
|
||
const key = '{partition}:scope:this_is_a_key'; | ||
const value = 'b45165ed3cd437b9ffad02a2aad22a4ddc69162470e2622982889ce5826f6e3d'; | ||
|
||
const main = async () => { | ||
const redis = await createClient() | ||
.on('error', (err) => console.log('Redis Client Error', err)) | ||
.connect(); | ||
|
||
await client.cmd(['SET', 'a', 'b']); | ||
await ioredis.set('a', 'b'); | ||
await redis.set('a', 'b'); | ||
|
||
const suite = new Suite(); | ||
suite | ||
.add('redis-joy', async () => { | ||
await client.cmd(['SET', key, value]); | ||
const res = await client.cmd(['GET', key], {utf8Res: true}); | ||
if (res !== value) throw new Error('Unexpected response'); | ||
}) | ||
.add('ioredis', async () => { | ||
await ioredis.set(key, value); | ||
const res = await ioredis.get(key); | ||
if (res !== value) throw new Error('Unexpected response'); | ||
}) | ||
.add('redis', async () => { | ||
await redis.set(key, value); | ||
const res = await redis.get(key); | ||
if (res !== value) throw new Error('Unexpected response'); | ||
}) | ||
.on('cycle', (event: any) => { | ||
console.log(String(event.target)); | ||
}) | ||
.on('complete', () => { | ||
console.log('Fastest is ' + suite.filter('fastest').map('name')); | ||
}) | ||
.run({async: true}); | ||
}; | ||
|
||
main().catch((err) => { | ||
console.error(err); | ||
process.exit(1); | ||
}); |
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,4 @@ | ||
import {setupStandalone} from '../../setupStandalone'; | ||
import * as PSUBSCRIBE from './PSUBSCRIBE'; | ||
|
||
PSUBSCRIBE.standalone(setupStandalone); |
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,4 @@ | ||
import {setupStandalone} from '../../setupStandalone'; | ||
import * as SSUBSCRIBE from './SSUBSCRIBE'; | ||
|
||
SSUBSCRIBE.standalone(setupStandalone); |
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,4 @@ | ||
import {setupStandalone} from '../../setupStandalone'; | ||
import * as SUBSCRIBE from './SUBSCRIBE'; | ||
|
||
SUBSCRIBE.standalone(setupStandalone); |
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,5 @@ | ||
import {setupStandalone} from '../../setupStandalone'; | ||
import * as GET from './GET'; | ||
|
||
GET.run(setupStandalone); | ||
GET.standalone(setupStandalone); |
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 |
---|---|---|
|
@@ -8,4 +8,5 @@ export const cluster = { | |
export const standalone = { | ||
host: '127.0.0.1', | ||
port: 6379, | ||
// port: 9999, | ||
}; |
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,35 @@ | ||
import * as net from 'net'; | ||
import {StandaloneClient} from '../standalone/StandaloneClient'; | ||
import {StandaloneTestSetup} from './types'; | ||
import {RespEncoder} from 'json-joy/es2020/json-pack/resp/RespEncoder'; | ||
import {RespStreamingDecoder} from 'json-joy/es2020/json-pack/resp/RespStreamingDecoder'; | ||
import {ReconnectingSocket} from '../util/ReconnectingSocket'; | ||
import * as config from './config'; | ||
|
||
const host = config.standalone.host; | ||
const port = config.standalone.port; | ||
const clients: StandaloneClient[] = []; | ||
|
||
export const setupStandalone: StandaloneTestSetup = async () => { | ||
const client = new StandaloneClient({ | ||
socket: new ReconnectingSocket({ | ||
createSocket: () => net.connect({host, port}), | ||
}), | ||
encoder: new RespEncoder(), | ||
decoder: new RespStreamingDecoder(), | ||
}); | ||
// client.onError.listen((err) => { | ||
// console.error('onError', err); | ||
// }); | ||
// client.onPush.listen((push) => { | ||
// console.log(push); | ||
// }); | ||
client.start(); | ||
clients.push(client); | ||
await client.whenReady; | ||
return {client}; | ||
}; | ||
|
||
afterAll(() => { | ||
for (const client of clients) client.stop(); | ||
}); |
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 |
---|---|---|
@@ -1,40 +1,6 @@ | ||
import * as net from 'net'; | ||
import {RedisClient} from '../node/RedisClient'; | ||
import {StandaloneTestSetup} from './types'; | ||
import * as commands from './commands'; | ||
import {ReconnectingSocket} from '../node'; | ||
import {RespEncoder} from 'json-joy/es2020/json-pack/resp/RespEncoder'; | ||
import {RespStreamingDecoder} from 'json-joy/es2020/json-pack/resp/RespStreamingDecoder'; | ||
import * as config from './config'; | ||
|
||
const host = config.standalone.host; | ||
const port = config.standalone.port; | ||
const clients: RedisClient[] = []; | ||
|
||
const setupCluster: StandaloneTestSetup = async () => { | ||
const client = new RedisClient({ | ||
socket: new ReconnectingSocket({ | ||
createSocket: () => net.connect({host, port}), | ||
}), | ||
encoder: new RespEncoder(), | ||
decoder: new RespStreamingDecoder(), | ||
}); | ||
// client.onError.listen((err) => { | ||
// console.error('onError', err); | ||
// }); | ||
// client.onPush.listen((push) => { | ||
// console.log(push); | ||
// }); | ||
client.start(); | ||
clients.push(client); | ||
await client.whenReady; | ||
return {client}; | ||
}; | ||
import {setupStandalone} from './setupStandalone'; | ||
|
||
describe('standalone (client per test)', () => { | ||
commands.standalone(setupCluster); | ||
}); | ||
|
||
afterAll(() => { | ||
for (const client of clients) client.stop(); | ||
commands.standalone(setupStandalone); | ||
}); |
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
Oops, something went wrong.