首先,让我们从错误开始。
node:internal/process/esm_loader:94
internalBinding('errors').triggerUncaughtException(
^
[ErrorReply: ERR unknown command 'JSON.SET', with args beginning with: 'Album:01GAZ32CZWSPB78HE8M75VH1GR' '.' '{"artist":"Mushroomhead","title":"The Righteous & The Butterfly","year":2014,"genres":["m' ]
我的redis-server
在后台运行,并查看与Redis一起使用的主要数据库的情况,我去了redis-om-node。我将一些片段放在一起,试图了解整个流程。
import { Client, Entity, Schema, Repository } from "redis-om";
const client = new Client();
await client.open("redis://localhost:6379");
class Album extends Entity {}
const albumSchema = new Schema(Album, {
artist: { type: "string" },
title: { type: "text" },
year: { type: "number" },
genres: { type: "string[]" },
outOfPublication: { type: "boolean" }
});
const albumRepository = client.fetchRepository(albumSchema);
const album = albumRepository.createEntity();
album.artist = "Mushroomhead";
album.title = "The Righteous & The Butterfly";
album.year = 2014;
album.genres = ["metal"];
album.outOfPublication = true;
const id = await albumRepository.save(album); // '01FJYWEYRHYFT8YTEGQBABJ43J'
console.log(id);
任何从redis-om-node或redis-om中脱脂的人都会识别此代码。
在package.json
文件中,我已经安装了这些软件包,因为我将主数据库从 mongodb 更改为 redis 。
。
...
"dependencies": {
"bcrypt": "^5.0.0",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"joi": "^17.6.0",
"joi-password": "^3.0.1",
"jsonwebtoken": "^8.5.1",
"morgan": "^1.10.0",
"morgan-json": "^1.1.0",
"redis": "^4.2.0",
"redis-om": "^0.3.6",
"winston": "^3.7.2"
},
...
遇到一个错误,不知道它来自何处或什么是我现在已经处理过的事情了。我知道我不是奥利人。因此,请继续推动。
我以为不是我,而是代码或其他东西,所以我开始挖掘Google和Stackoverflow和Dev.to。我发现我可以创建一个新的存储库,而不是像我那样取出它,或者在这里完成了,const albumRepository = client.fetchRepository(albumSchema);
我更新了代码。
import { Client, Entity, Schema, Repository } from "redis-om";
const client = new Client();
await client.open("redis://localhost:6379");
class Album extends Entity {}
const albumSchema = new Schema(
Album,
{
artist: { type: "string" },
title: { type: "text" },
year: { type: "number" },
genres: { type: "string[]" },
outOfPublication: { type: "boolean" }
},
{ dataStructure: "JSON" }
);
// const albumRepository = client.fetchRepository(albumSchema);
const repository = new Repository(client, albumSchema);
// const album = albumRepository.createEntity();
const album = repository.createEntity();
album.artist = "Mushroomhead";
album.title = "The Righteous & The Butterfly";
album.year = 2014;
album.genres = ["metal"];
album.outOfPublication = true;
// const id = await albumRepository.save(album);
const id = await repository.save(album);
console.log(id);
猜猜什么?有一个与以前的错误不同。
/home/user/Projects/web/ARMS-redis/node_modules/redis-om/dist/index.js:907
const id = this.schema.generateId();
^
TypeError: this.schema.generateId is not a function
at Repository.createEntity (/home/user/Projects/web/ARMS-redis/node_modules/redis-om/dist/index.js:907:28)
at file:///home/user/Projects/web/ARMS-redis/src/index.js:24:26
at processTicksAndRejections (node:internal/process/task_queues:96:5)
我去了/home/user/Projects/web/ARMS-redis/node_modules/redis-om/dist/index.js:907
createEntity(data = {}) {
const id = this.schema.generateId();
return new this.schema.entityCtor(this.schema, id, data);
}
这是具有或指向不存在的generateId
函数的createEntity
。同一文件中有一个类,var Schema = class { ... }
,它具有generateId
函数。
我回到了挖掘,发现存储库中的另一种方法createAndSave({})
。 express-redis-om-workshop。
我进行了修改:
import { Client, Entity, Schema, Repository } from "redis-om";
const client = new Client();
await client.open("redis://localhost:6379");
class Album extends Entity {}
const albumSchema = new Schema(
Album,
{
artist: { type: "string" },
title: { type: "text" },
year: { type: "number" },
genres: { type: "string[]" },
outOfPublication: { type: "boolean" }
},
{ dataStructure: "JSON" }
);
// const albumRepository = client.fetchRepository(albumSchema);
const repository = new Repository(client, albumSchema);
// const album = albumRepository.createEntity();
// const album = repository.createEntity();
// album.artist = "Mushroomhead";
// album.title = "The Righteous & The Butterfly";
// album.year = 2014;
// album.genres = ["metal"];
// album.outOfPublication = true;
// const id = await albumRepository.save(album);
// const id = await repository.save(album);
const id = await repository.createAndSave({
artist: "Mushroomhead",
title: "The Righteous & The Butterfly",
title: "The Righteous & The Butterfly",
year: 2014,
genres: ["metal"],
outOfPublication: true
});
console.log(id);
仍然,
/home/user/Projects/web/ARMS-redis/node_modules/redis-om/dist/index.js:907
const id = this.schema.generateId();
^
TypeError: this.schema.generateId is not a function
at Repository.createEntity (/home/user/Projects/web/ARMS-redis/node_modules/redis-om/dist/index.js:907:28)
at Repository.createAndSave (/home/user/Projects/web/ARMS-redis/node_modules/redis-om/dist/index.js:915:25)
at file:///home/user/Projects/web/ARMS-redis/src/index.js:34:29
at processTicksAndRejections (node:internal/process/task_queues:96:5)
此刻,我可以感觉到头骨(幽灵骑手)的压力和疲倦。我看了一些动漫,走了一点。首先,我回到了有关黑客马拉松的主要文章,然后我开始仔细阅读,寻找线索。 redis.io。两者之间有什么不同的redis.com?我不知道,所以我不知道。 redis.io,我读过,The open source, in-memory data store used by millions of developers as a database, cache, streaming engine, and message broker.
,我记得我之前已经读过它或类似的东西。我像任何开发人员一样,单击 docs ,并且在我知道自己在redis-stack之前。我意识到, redis-stack 不仅与 redis 相同,还与Extends Redis with modern data models and processing engines. Includes documentation for the bundled Redis modules and RedisInsight.
得出结论,我浪费了整天的方向,做正确的事。我安装了 redis-stack ,并使用此解决方案来修复另一个Could not create server TCP listening socket *:6379。
我将因此入睡。我想我明天会做得很好。