问题描述
环境
$ node -v v16.14.0 # redis-cli 127.0.0.1:6379> info # Server redis_version:5.0.5
版本 package.json
{ "dependencies": { "redis": "^4.2.0" } }
代码
import { createClient } from 'redis' const REDIS_URL = "redis://root:123456@127.0.0.1:6379" export async function getRedisClient() { // 连接redis const client = createClient({ url: REDIS_URL, }) await client.connect() return client }
报错
node:internal/process/promises:265 triggerUncaughtException(err, true /* fromPromise */); ^ [ErrorReply: ERR wrong number of arguments for 'auth' command]
解决办法
明明是按照格式写的,却报错了
redis[s]://[[username][:password]@][host][:port][/db-number]
按照github上的issues,如果是默认username, 那么需要省略
const REDIS_URL = "redis://:123456@127.0.0.1:6379"
参考