handy-redis
Advanced tools
Comparing version 1.1.2 to 1.2.0
@@ -5,2 +5,3 @@ "use strict"; | ||
const flatten_1 = require("./flatten"); | ||
const overrides_1 = require("./overrides"); | ||
exports.createHandyClient = (...clientArgs) => { | ||
@@ -13,11 +14,14 @@ const nodeRedis = (typeof clientArgs[0] === "object" && typeof clientArgs[0].zscan === "function") | ||
const func = nodeRedis[key]; | ||
handyClient[key] = (...args) => new Promise((resolve, reject) => { | ||
const flattened = flatten_1.flattenDeep(args); | ||
func.apply(nodeRedis, flattened.concat([(err, data) => err ? reject(err) : resolve(data)])); | ||
}); | ||
if (overrides_1.useUnderlyingImpl.has(key)) { | ||
handyClient[key] = func.bind(nodeRedis); | ||
} | ||
else { | ||
handyClient[key] = (...args) => new Promise((resolve, reject) => { | ||
const flattened = flatten_1.flattenDeep(args); | ||
func.apply(nodeRedis, flattened.concat([(err, data) => err ? reject(err) : resolve(data)])); | ||
}); | ||
} | ||
}); | ||
Object.assign(handyClient, overrides_1.additionalFunctions); | ||
return handyClient; | ||
// return _createHandyClient(args[0]); | ||
// } | ||
// return _createHandyClient(createClient.apply(null, args)); | ||
}; |
{ | ||
"name": "handy-redis", | ||
"version": "1.1.2", | ||
"version": "1.2.0", | ||
"description": "A wrapper around node_redis with Promise and TypeScript support.", | ||
@@ -13,3 +13,3 @@ "main": "dist/index.js", | ||
"compile": "tsc -p .", | ||
"prebuild": "ts-node scripts/generate-types && ts-node scripts/generate-tests", | ||
"prebuild": "ts-node -D scripts/generate-types && ts-node scripts/generate-tests", | ||
"build": "tsc -p .", | ||
@@ -16,0 +16,0 @@ "lint": "tslint **/*.ts", |
@@ -50,2 +50,26 @@ # handy-redis | ||
### Examples | ||
See the [snapshot tests](https://github.com/mmkal/handy-redis/blob/master/test/generated/commands/snapshots) for tons of usage examples (look at the `.md` files). | ||
### Multi | ||
Most members of node_redis's `multi` type don't need to be promisified, because they execute synchronously. Only `exec` is async. To use a promisified version of that, use `execMulti`: | ||
```JavaScript | ||
import { createHandyClient } from 'handy-redis'; | ||
(async function() { | ||
const client = createHandyClient(); | ||
const multi = client.multi().set("z:foo", "987").keys("z:*").get("z:foo"); | ||
const result = await client.execMulti(multi); | ||
console.log(result); // ["OK", ["z:foo"], "987"] | ||
})(); | ||
``` | ||
`execMulti` is generic, so in TypeScript you can use something like `const strings = await client.execMulti<string>(multi)` if you know all results will be strings. Otherwise the type will default to `{}`. | ||
## Development | ||
@@ -52,0 +76,0 @@ |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
544057
11
13965
92
0