Documentation

Managing Domain Objects with Redis Hashes

Simon Prickett
Author
Simon Prickett, Principal Developer Advocate at Redis

Coding Exercise#

// EXERCISE: Get user's full name.
router.get(
  '/user/:userId/fullname',
  [param('userId').isInt({ min: 1 }), apiErrorReporter],
  async (req, res) => {
    const { userId } = req.params;
    /* eslint-disable no-unused-vars */
    const userKey = redis.getKeyName('users', userId);
    /* eslint-enable */

    // TODO: Get the firstName and lastName fields from the
    // user hash whose key is in userKey.
    // HINT: Check out the HMGET command...
    // https://redis.io/commands/hmget
    const [firstName, lastName] = ['TODO', 'TODO'];

    res.status(200).json({ fullName: `${firstName} ${lastName}` });
  },
);
$ npm run dev
{
  "fullName": "TODO TODO"
}
{
  "fullName": "Alejandro Reyes"
}

External Resources#