You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
RedisJSON
This commit is contained in:
@@ -1,16 +1,17 @@
|
||||
import { BlobStringReply, NullReply, UnwrapReply } from '@redis/client/dist/lib/RESP/types';
|
||||
import ARRAPPEND from './ARRAPPEND';
|
||||
import ARRINDEX from './ARRINDEX';
|
||||
import ARRINSERT from './ARRINSERT';
|
||||
import ARRLEN from './ARRLEN';
|
||||
// import ARRPOP from './ARRPOP';
|
||||
import ARRPOP from './ARRPOP';
|
||||
import ARRTRIM from './ARRTRIM';
|
||||
import CLEAR from './CLEAR';
|
||||
import DEBUG_MEMORY from './DEBUG_MEMORY';
|
||||
import DEL from './DEL';
|
||||
import FORGET from './FORGET';
|
||||
// import GET from './GET';
|
||||
import GET from './GET';
|
||||
import MERGE from './MERGE';
|
||||
// import MGET from './MGET';
|
||||
import MGET from './MGET';
|
||||
import MSET from './MSET';
|
||||
import NUMINCRBY from './NUMINCRBY';
|
||||
import NUMMULTBY from './NUMMULTBY';
|
||||
@@ -22,6 +23,7 @@ import STRAPPEND from './STRAPPEND';
|
||||
import STRLEN from './STRLEN';
|
||||
import TOGGLE from './TOGGLE';
|
||||
import TYPE from './TYPE';
|
||||
import { isNullReply } from '@redis/client/dist/lib/commands/generic-transformers';
|
||||
|
||||
export default {
|
||||
ARRAPPEND,
|
||||
@@ -32,8 +34,8 @@ export default {
|
||||
arrInsert: ARRINSERT,
|
||||
ARRLEN,
|
||||
arrLen: ARRLEN,
|
||||
// ARRPOP,
|
||||
// arrPop: ARRPOP,
|
||||
ARRPOP,
|
||||
arrPop: ARRPOP,
|
||||
ARRTRIM,
|
||||
arrTrim: ARRTRIM,
|
||||
CLEAR,
|
||||
@@ -44,12 +46,12 @@ export default {
|
||||
del: DEL,
|
||||
FORGET,
|
||||
forget: FORGET,
|
||||
// GET,
|
||||
// get: GET,
|
||||
GET,
|
||||
get: GET,
|
||||
MERGE,
|
||||
merge: MERGE,
|
||||
// MGET,
|
||||
// mGet: MGET,
|
||||
MGET,
|
||||
mGet: MGET,
|
||||
MSET,
|
||||
mSet: MSET,
|
||||
NUMINCRBY,
|
||||
@@ -80,29 +82,19 @@ export default {
|
||||
type: TYPE
|
||||
};
|
||||
|
||||
// https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
||||
interface RedisJSONArray extends Array<RedisJSON> { }
|
||||
interface RedisJSONObject {
|
||||
export type RedisJSON = null | boolean | number | string | Date | Array<RedisJSON> | {
|
||||
[key: string]: RedisJSON;
|
||||
[key: number]: RedisJSON;
|
||||
}
|
||||
export type RedisJSON = null | boolean | number | string | Date | RedisJSONArray | RedisJSONObject;
|
||||
};
|
||||
|
||||
export function transformRedisJsonArgument(json: RedisJSON): string {
|
||||
return JSON.stringify(json);
|
||||
}
|
||||
|
||||
export function transformRedisJsonReply(json: string): RedisJSON {
|
||||
return JSON.parse(json);
|
||||
export function transformRedisJsonReply(json: BlobStringReply): RedisJSON {
|
||||
return JSON.parse((json as unknown as UnwrapReply<typeof json>).toString());
|
||||
}
|
||||
|
||||
export function transformRedisJsonNullReply(json: string | null): RedisJSON | null {
|
||||
if (json === null) return null;
|
||||
|
||||
return transformRedisJsonReply(json);
|
||||
}
|
||||
|
||||
export function transformNumbersReply(reply: string): number | Array<number> {
|
||||
return JSON.parse(reply);
|
||||
export function transformRedisJsonNullReply(json: NullReply | BlobStringReply): NullReply | RedisJSON {
|
||||
return isNullReply(json) ? json : transformRedisJsonReply(json);
|
||||
}
|
||||
|
Reference in New Issue
Block a user