Gathering detailed insights and metrics for redis-resp-handler
Gathering detailed insights and metrics for redis-resp-handler
Gathering detailed insights and metrics for redis-resp-handler
Gathering detailed insights and metrics for redis-resp-handler
npm install redis-resp-handler
Typescript
Module System
Node Version
NPM Version
69.8
Supply Chain
99.3
Quality
79.3
Maintenance
100
Vulnerability
99.6
License
TypeScript (99.26%)
JavaScript (0.74%)
Built with Next.js • Fully responsive • SEO optimized • Open source ready
Total Downloads
565
Last Day
1
Last Week
1
Last Month
15
Last Year
565
13 Commits
1 Watchers
1 Branches
1 Contributors
Updated on Sep 24, 2024
Latest Version
1.2.3
Package Id
redis-resp-handler@1.2.3
Unpacked Size
22.25 kB
Size
5.98 kB
File Count
16
NPM Version
10.2.4
Node Version
20.11.0
Published on
Sep 24, 2024
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
-80%
1
Compared to previous week
Last Month
87.5%
15
Compared to previous month
Last Year
0%
565
Compared to previous year
1
3
redis-resp-handler is a fast and lightweight utility for parsing and serializing RESP (Redis Serialization Protocol) messages in Node.js. It supports a variety of data types including arrays, strings, integers, null values, and error messages, making it ideal for handling Redis communication.
1npm install redis-resp-handler
1yarn add redis-resp-handler
To serialize a RESP message, simply call the serializeToRESP
function and pass in the data (data types: null, boolean, number, string, array, or object) you want to serialize.
1import { serializeToRESP } from "redis-resp-handler"; 2 3const message = serializeToRESP("Hello, Redis!"); 4console.log(message); // Outputs: $12\r\nHello, Redis!\r\n
To parse a RESP message, use the parseRESPMessage
function and pass in the string representation of the message. It will return an array of the parsed elements.
1import { parseRESPMessage } from "redis-resp-handler"; 2 3const data = "*2\r\n$3\r\nfoo\r\n$3\r\nbar\r\n"; 4const result = parseRESPMessage(data); 5console.log(result); // Outputs: [ ['foo', 'bar'] ]
serializeToRESP(data: any): string
: Serializes a JavaScript object into a RESP message string.data
(any): The data to serialize (supports strings, numbers, arrays, objects, booleans, null).Error
if the data type is unsupported.parseRESPMessage(data: string): any[]
: Parses a RESP message string into JavaScript objects.data
(string): The RESP message to parse.Error
if the RESP message is malformed.nullToRESP(): string
: Converts null
to the RESP format.null
(e.g., _\r\n
).booleanToRESP(bool: boolean): string
: Converts a boolean value to the RESP format.bool
(boolean): The boolean value to serialize.#t\r\n
for true or #f\r\n
for false).numberToRESP(num: number): string
: Converts a number to the RESP format. Handles integers, floating-point numbers, and special cases like Infinity
and NaN
.num
(number): The number to serialize.:42\r\n
,3.14\r\n
Infinity
: ,inf\r\n
NaN
: ,nan\r\n
Error
if the number is too large or small for safe integer serialization.stringToRESP(str: string, type: "bulk" | "simple" = "bulk"): string
: Converts a string to the RESP format.str
(string): The string to serialize.type
(string, optional): The type of string, either "bulk"
(default) or "simple"
.$11\r\nHello, Redis!\r\n
+OK\r\n
Error
if an unsupported string type is provided.arrayToRESP(arr: Array<any>): string
: Converts an array to the RESP format. Recursively serializes all elements of the array.arr
(Array2\r\n$3\r\nfoo\r\n$3\r\nbar\r\n
objectToRESP(obj: Record<string, any>): string
: Converts an object (key-value pairs) to the RESP format. The keys are serialized as strings, and the values are recursively serialized.obj
(Record<string, any>): The object to serialize.%2\r\n$3\r\nfoo\r\n$3\r\nbar\r\n$3\r\nbaz\r\n:42\r\n
Error
objects.null
.A full-fledged unit test suite is available for both serializeToRESP
and parseRESPMessage
functions, covering all test cases and edge cases.
You can visit the repository and run yarn test
to execute the tests or modify and add more test cases to ensure reliability and robustness.
This package is licensed under the MIT License.
Contributions are welcome! Please open an issue or submit a pull request.
No vulnerabilities found.