Skip to content

Commit 686cf9d

Browse files
committed
#RI-4139 - add formatRedisReply to plugin sdk
1 parent ec2b91d commit 686cf9d

File tree

5 files changed

+70
-2
lines changed

5 files changed

+70
-2
lines changed

redisinsight/ui/src/packages/redisinsight-plugin-sdk/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,43 @@ try {
120120
console.error(e);
121121
}
122122
```
123+
124+
### formatRedisReply(response, command)
125+
126+
Util function to parse Redis response
127+
128+
Returns string with parsed cli-like response
129+
130+
**Returns:**
131+
* `Promise<string>`
132+
133+
```js
134+
/**
135+
* @async
136+
* @param {any} response
137+
* @param {String} command
138+
* @returns {Promise.<string>} data
139+
* @throws {Error}
140+
*/
141+
```
142+
143+
**Example:**
144+
145+
```js
146+
import { formatRedisReply } from 'redisinsight-plugin-sdk';
147+
148+
try {
149+
const parsedReply = await formatRedisReply(data[0].response, command);
150+
151+
/*
152+
parsedReply:
153+
154+
1) 1) "COUNT(a)"
155+
2) 1) 1) "0"
156+
3) 1) "Cached execution: 1"
157+
2) "Query internal execution time: 3.134125 milliseconds"
158+
*/
159+
} catch (e) {
160+
console.error(e);
161+
}
162+
```

redisinsight/ui/src/packages/redisinsight-plugin-sdk/events.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ export const POST_MESSAGE_EVENTS = {
22
setHeaderText: 'setHeaderText',
33
executeRedisCommand: 'executeRedisCommand',
44
getState: 'getState',
5-
setState: 'setState'
5+
setState: 'setState',
6+
formatRedisReply: 'formatRedisReply',
67
}

redisinsight/ui/src/packages/redisinsight-plugin-sdk/index.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,10 @@ export function setState<State>(state?: State): Promise<State>
2121
*
2222
*/
2323
export function getState(): Promise<any>
24+
25+
/**
26+
* Parse Redis response
27+
* Returns string with parsed cli-like response
28+
*
29+
*/
30+
export function formatRedisReply(response: any, command?: string): Promise<string>

redisinsight/ui/src/packages/redisinsight-plugin-sdk/index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,23 @@ export const setState = (state) => new Promise((resolve, reject) => {
6868
requestId: callbacks.counter++
6969
})
7070
})
71+
72+
/**
73+
* Parse Redis response
74+
* Returns string with parsed cli-like response
75+
*
76+
* @async
77+
* @param {any} response
78+
* @param {String} command
79+
* @returns {Promise.<string>} data
80+
* @throws {Error}
81+
*/
82+
export const formatRedisReply = (response, command = '') => new Promise((resolve, reject) => {
83+
callbacks[callbacks.counter] = { resolve, reject }
84+
sendMessageToMain({
85+
event: POST_MESSAGE_EVENTS.formatRedisReply,
86+
iframeId,
87+
data: { response, command },
88+
requestId: callbacks.counter++
89+
})
90+
})

redisinsight/ui/src/packages/redisinsight-plugin-sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"redis",
77
"redis-gui"
88
],
9-
"version": "1.0.1",
9+
"version": "1.1.0",
1010
"author": {
1111
"name": "Redis",
1212
"email": "redisinsight@redis.com"

0 commit comments

Comments
 (0)