moaxaca / async-redis Goto Github PK
View Code? Open in Web Editor NEWFirst class async & promise support for redis.
License: Other
First class async & promise support for redis.
License: Other
HI!
in order to have a more complete API in replacement of redis
I'd suggest to add the redis.print method.
https://github.com/NodeRedis/node-redis
If it's need, I can create a PR with that.
Ty for all your work!
const client = require('async-redis').createClient('6379', '127.0.0.1');
const logger = require('tracer').console();
client.on("error", err => logger.log(err));
(async () => {
await client.set("string key", "stringvalue");
const value = await client.get("string key");
logger.log(value);
await client.flushall("string key");
})();
show result:
(node:2828) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): ReplyError: ERR wrong number of arguments for 'flushall' command
(node:2828) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
I'm a beginner,I want answers,thanks!
From version 1.1.3 on using the module with typescript gives an error:
server.ts(13,29): error TS2306: File ./node_modules/async-redis/index.d.ts' is not a module.
Line 13 reads:
import * as asyncRedis from 'async-redis';
version 1.1.2 and below works fine.
Hope this helps.
Regards,
Wessel
Hi!
Thanks for a great module! ๐
Since version 2.0.0 async-redis is no longer working with typescript. it seems like tsc is loading src/index.d.ts file instead of src/index.js.
Reproducible steps:
import { createClient } from 'async-redis';
tsc index.ts
I am using typescript 4.3.2 version.
master
is behind the latest npm release. specifically, i'm looking at this: #37
Both variants do not return to console.
const asyncRedis = require("async-redis");
const client = asyncRedis.createClient();
// (async () => {
// console.log("hello")
// })()
console.log("hello")
createClient is to blame
Currently, we have to specify in the package.json the mocha file if we follow convention. Mocha can pick this up on it's own.
It would be great if .decorate
didn't change the supplied redis object but rather returned a new one.
It would be nice to have typescript type definitions!
Could we import the DefinitelyTyped types here? (https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/async-redis/index.d.ts)
OR
Remove the published types entirely and rely on DefinitelyTyped?
The mismatch is causing issues for me.
Thank you!
My Redis has a password, advised by every quickstart guide:
ReplyError: Ready check failed: NOAUTH Authentication required.
I pretty much expected this -- but I oddly saw no mention of passwords in the README despite being such a general thing: How to simply include the redis password when connecting?
I am using connect-redis as a Redis session store backed by node_redis. Everything is fine if I use a normal redisClient without decorating it by async-redis. However after I decorated redisClient with async-redis, the connect-redis module seem didn't work anymore.
I hope it would be better if decorate function does not change the original redisClient and returning a new object instead
node-redlock is not working with async-redis, sample code
// ...do something here...
will never execute.
Scenario:
watch
on a keymulti
+ modifying the keyClient 2 returns true
, whereas it should return null
, since the watched key has been modified from another client.
I tested the same scenario with redis and it works as expected. The problem is that I have to promisify it with Bluebird.
Just abstract example:
(async f1() {
const client1 = asyncRedis.createClient();
await client1.blpop("some", 0);
})()
(async f2() {
const client2 = asyncRedis.createClient();
await client2.lpush("some", 42);
})()
f2's lpush will never be called as client1 and client2 share same connection due to new implementation
in case await command get stuck there forever
FYI: The current build is failing due to some code coverage checks failing.
Update the package.json with typescript definitions and write a ts example.
When using the async library the createClient method ignores the host and port and connects to localhost
Hello, I try to do something like:
await client.set('key', 'value', {
EX: 10
});
But getting err :>> Error: node_redis: The SET command contains a invalid argument type. Only strings, dates and buffers are accepted. Please update your code to use valid argument types.
const asyncRedisClient = require("async-redis").createClient(1111, '8.8.8.8');
It looks like the second argument ("8.8.8.8") is being ignored:
Error: Redis connection to 127.0.0.1:1111 failed - connect ECONNREFUSED 127.0.0.1:1111
Edit: Just found this workaround:
const asyncRedisClient = require("async-redis").createClient(`redis://8.8.8.8:1111`);
Node: v12.18.2
redis: 5.0.5 (docker image)
async-redis: 2.0.0
Error occur as " AbortError: BLPOP can't be processed. The connection is already closed. "
This is ample code where an error occurs.
const redis = require('async-redis')
let client = redis.createClient("redis://localhost:6379");
let cnt = 0;
async function reconnect() {
try {
await client.quit()
client = null
client = redis.createClient("redis://localhost:6379");
console.log('reconnect');
} catch (error) {
console.log(error);
}
}
(async () => {
while (true) {
try {
cnt++
const v = await client.blpop('*', 1)
if (cnt%5 === 0) {
throw Error("Test")
}
} catch (error) {
console.error(error);
await reconnect()
}
}
})()
But below code work well.
There seems to be a problem with clients with the same option as they connected before.
is it bug?
const redis = require('async-redis')
let client = redis.createClient("redis://localhost:6379");
let cnt = 0;
async function reconnect() {
try {
await client.quit()
client = null
client = redis.createClient("redis://localhost:6379", {
customOption: Date.now(), // Here
});
console.log('reconnect');
} catch (error) {
console.log(error);
}
}
(async () => {
while (true) {
try {
cnt++
const v = await client.blpop('*', 1)
if (cnt%5 === 0) {
throw Error("Test")
}
} catch (error) {
console.error(error);
await reconnect()
}
}
})()
Add documentation for commands that redis offers this directly proxies redis_node commands and their documentation doesn't highlight all of the https://redis.io/commands.
Hey ๐,
Could you update redis
and redis-command
to their latest version?
Because right now, this version of redis require hiredis
which is deal breaking for me.
using this code:
const redis = require("redis"),
rejson = require("redis-rejson"),
asyncRedis = require("async-redis");
rejson(redis); /* important - this must come BEFORE creating the client */
let redisClient = redis.createClient();
let asyncRedisClient = asyncRedis.decorate(redisClient);
retrieving any value is fine, like:
myString = await asyncRedisClient.get("myKey1");
but I always get a boolean true value in myJson if
myJson = await asyncRedisClient.json_get("myKey2", ".")
should it work with redis-rejson ?
thanks
using the following, for example, does not work
await client.multi().set('a','b').exec()
temporary fix:
const redis = require("redis")
const asyncRedis = require("async-redis")
const client = redis.createClient()
const asyncRedisClient = asyncRedis.decorate(client)
const res = await new Promise((resolve, reject)=>{
multistack = asyncRedisClient.multi()
multistack.set('a','b')
multistack.hset('h','x','y')
multistack.exec((err,results)=>{
resolve(results)
})
})
Hi,
First of all, thanks for this library. It is much appreciated. Good work. :)
I ran into an issue yesterday and I managed to narrow it down to the way the createClient
method works within AsyncRedis
.
It seems that the method will not create two distinct client instances with the same configuration - as opposed to what the base Redis
method implementation would. Instead, it keeps track of created clients and stores them in an internal array, so that a the same instance will be returned when equivalent options are a match.
I'm not sure why it was designed that way. There may be a very valid reason I'm simply unaware of. In any case, this is a problem for situations in which you do need two distinct clients on the same database, such as when one acts as a subscriber and the other as a publisher. You'd be calling createClient
method twice on two distinct variables and use them as pub/sub pattern dictates; still, the code would fail at runtime with the following error message:
ERR only (P)SUBSCRIBE / (P)UNSUBSCRIBE / PING / QUIT allowed in this context
The workaround I came up with was to create clients out of base Redis
library, then use AsyncRedis.decorate
on them. Works like a charm and still allows using promises.
If pooling of client instances really is the intended design for createClient
, then I suggest documenting the method accordingly.
Thanks! :)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.