如何在Redis中存储复杂数据?

时间:2018-07-06 23:45:46

标签: redis

我想以以下样式在Redis数据库中存储数据:

 { _id: 5b3a60cdccbdf81bcc5343e6,
    id: 5b3a60cdccbdf81bcc5343e5,
    position: 'Web dveloper',
    type: 'Contract',
    Skills: 'html, bootstrap,php',
    location: 'Boston',
    job_id: 1,
    Experience: '0-6 months',
    Description: 'Developer for websites and web apps',
    __v: 0 },
  { _id: 5b3a6151ccbdf81bcc5343e8,
    id: 5b3a6151ccbdf81bcc5343e7,
    position: 'Data analyst',
    type: 'contract',
    Skills: 'big data, hadoop,python',
    location: 'boston',
    job_id: 2,
    Experience: '1yr',
    Description: 'for analysing incoming data',
    __v: 0 },
  { _id: 5b3a6207ccbdf81bcc5343ea,
    id: 5b3a6207ccbdf81bcc5343e9,
    position: 'Content Writer',
    type: 'Permanent',
    Skills: 'Technical wirtting,Custmer engagement',
    location: 'new jersey',
    job_id: 3,
    Experience: '0-6 months',
    Description: 'for writting website content',
    __v: 0 },
  { _id: 5b3a62c4ccbdf81bcc5343ec,
    id: 5b3a62c4ccbdf81bcc5343eb,
    position: 'node js specialist',
    type: 'Permanent',
    Skills: 'node js ,express js , mean stack',
    location: 'boston',
    job_id: 4,
    Experience: '1yr',
    Description: 'for the web apps',
    __v: 0 },
  { _id: 5b3a6362ccbdf81bcc5343ee,
    id: 5b3a6362ccbdf81bcc5343ed,
    position: 'database expert',
    type: 'temporary',
    Skills: 'sql , no sql, mysql,sql server,mongo db',
    location: 'boston',
    job_id: 5,
    Experience: '2 yrs',
    Description: 'for desinging and maintaing databases',
    __v: 0 },
  { _id: 5b3a8639c8323b2cfc179969,
    id: 5b3a8639c8323b2cfc179968,
    position: 'Social media manager',
    type: 'Permanent',
    Skills: 'Social media marketing,Digital marketing',
    location: 'Boston',
    job_id: 4,
    Experience: '1yr',
    Description: 'For managing company socail media accounts',
    __v: 0 }

我已经查看过Redis的官方文档,但没有发现任何问题。谁能指导我可以使用什么结构存储以及如何在表中检索这些数据?

2 个答案:

答案 0 :(得分:1)

Redis Hash data结构是您可以用来存储数据的替代方法之一。使用Redis哈希结构,您可以使用ID作为键存储实体,然后使用HMSET command将其余字段映射到Redis哈希。

推荐的Node.js客户端是npm Redis package。这将提供与Redis交互所需的所有功能。

最终,您的查询模式将确定数据的最佳结构。使用散列是解决该问题的非常基本的实体映射方法,但是它可能不是构造数据的最佳方法。可能会有更有效的方法来构造数据,具体取决于您打算如何使用它。

答案 1 :(得分:-1)

Redis没有直接提供这么多的结构,但是有分层的库可以提供。我正在尝试使用Python图书馆Walrus,该图书馆在Redis之上提供了该功能。

相关问题