Skip to content

Commit 81ac816

Browse files
author
arthosofteq
authored
Merge pull request #745 from RedisInsight/feature/RI-1453-pub-sub
#RI-3030 BE for subscribe/unsubscribe base implementation
2 parents bae716b + 9479093 commit 81ac816

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2004
-4
lines changed

redisinsight/api/src/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { PluginModule } from 'src/modules/plugin/plugin.module';
1212
import { CommandsModule } from 'src/modules/commands/commands.module';
1313
import { WorkbenchModule } from 'src/modules/workbench/workbench.module';
1414
import { SlowLogModule } from 'src/modules/slow-log/slow-log.module';
15+
import { PubSubModule } from 'src/modules/pub-sub/pub-sub.module';
1516
import { SharedModule } from './modules/shared/shared.module';
1617
import { InstancesModule } from './modules/instances/instances.module';
1718
import { BrowserModule } from './modules/browser/browser.module';
@@ -43,6 +44,7 @@ const PATH_CONFIG = config.get('dir_path');
4344
PluginModule,
4445
CommandsModule,
4546
ProfilerModule,
47+
PubSubModule,
4648
SlowLogModule,
4749
EventEmitterModule.forRoot(),
4850
...(SERVER_CONFIG.staticContent

redisinsight/api/src/app.routes.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { RedisSentinelModule } from 'src/modules/redis-sentinel/redis-sentinel.m
66
import { CliModule } from 'src/modules/cli/cli.module';
77
import { WorkbenchModule } from 'src/modules/workbench/workbench.module';
88
import { SlowLogModule } from 'src/modules/slow-log/slow-log.module';
9+
import { PubSubModule } from 'src/modules/pub-sub/pub-sub.module';
910

1011
export const routes: Routes = [
1112
{
@@ -28,6 +29,10 @@ export const routes: Routes = [
2829
path: '/:dbInstance',
2930
module: SlowLogModule,
3031
},
32+
{
33+
path: '/:dbInstance',
34+
module: PubSubModule,
35+
},
3136
],
3237
},
3338
{

redisinsight/api/src/modules/cli/utils/getUnsupportedCommands.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { getUnsupportedCommands } from './getUnsupportedCommands';
22

33
describe('cli unsupported commands', () => {
44
it('should return correct list', () => {
5-
const expectedResult = ['monitor', 'subscribe', 'psubscribe', 'sync', 'psync', 'script debug'];
5+
const expectedResult = ['monitor', 'subscribe', 'psubscribe', 'ssubscribe', 'sync', 'psync', 'script debug'];
66

77
expect(getUnsupportedCommands()).toEqual(expectedResult);
88
});

redisinsight/api/src/modules/cli/utils/getUnsupportedCommands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export enum CliToolUnsupportedCommands {
66
Monitor = 'monitor',
77
Subscribe = 'subscribe',
88
PSubscribe = 'psubscribe',
9+
SSubscribe = 'ssubscribe',
910
Sync = 'sync',
1011
PSync = 'psync',
1112
ScriptDebug = 'script debug',

redisinsight/api/src/modules/profiler/models/log-file.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export class LogFile {
124124
this.writeStream?.close();
125125
this.writeStream = null;
126126
const size = this.getFileSize();
127-
fs.unlink(this.filePath);
127+
fs.unlinkSync(this.filePath);
128128

129129
this.analyticsEvents.get(TelemetryEvents.ProfilerLogDeleted)(this.instanceId, size);
130130
} catch (e) {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
export enum PubSubClientEvents {
2+
Subscribe = 'subscribe',
3+
Unsubscribe = 'unsubscribe',
4+
}
5+
6+
export enum PubSubServerEvents {
7+
Exception = 'exception',
8+
}
9+
10+
export enum SubscriptionType {
11+
Subscribe = 's',
12+
PSubscribe = 'p',
13+
SSubscribe = 'ss',
14+
}
15+
16+
export enum RedisClientStatus {
17+
Connecting = 'connecting',
18+
Connected = 'connected',
19+
Error = 'error',
20+
End = 'end',
21+
}
22+
23+
export enum RedisClientEvents {
24+
Connected = 'connected',
25+
ConnectionError = 'connection_error',
26+
Message = 'message',
27+
End = 'end',
28+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { get } from 'lodash';
2+
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
3+
import { UserClient } from 'src/modules/pub-sub/model/user-client';
4+
5+
export const Client = createParamDecorator(
6+
(data: unknown, ctx: ExecutionContext): UserClient => {
7+
const socket = ctx.switchToWs().getClient();
8+
9+
return new UserClient(socket.id, socket, get(socket, 'handshake.query.instanceId'));
10+
},
11+
);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from './subscribe.dto';
2+
export * from './subscription.dto';
3+
export * from './messages.response';
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { IMessage } from 'src/modules/pub-sub/interfaces/message.interface';
2+
3+
export class MessagesResponse {
4+
messages: IMessage[];
5+
6+
count: number;
7+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {
2+
IsNotEmpty, IsString,
3+
} from 'class-validator';
4+
import { ApiProperty } from '@nestjs/swagger';
5+
6+
export class PublishDto {
7+
@ApiProperty({
8+
type: String,
9+
description: 'Message to send',
10+
example: '{"hello":"world"}',
11+
})
12+
@IsNotEmpty()
13+
@IsString()
14+
message: string;
15+
16+
@ApiProperty({
17+
type: String,
18+
description: 'Chanel name',
19+
example: 'channel-1',
20+
})
21+
@IsNotEmpty()
22+
@IsString()
23+
channel: string;
24+
}

0 commit comments

Comments
 (0)