Skip to content

feat: [缓存] 给 auth 添加 redis 缓存#53

Merged
zzswang merged 4 commits intomainfrom
feat/issue44
Jan 25, 2025
Merged

feat: [缓存] 给 auth 添加 redis 缓存#53
zzswang merged 4 commits intomainfrom
feat/issue44

Conversation

@magiccaptain
Copy link
Contributor

@magiccaptain
Copy link
Contributor Author

magiccaptain commented Jan 22, 2025

测试user加缓存的个接口的set和unset缓存情况:

async function user() {
  const userId = '678df3f10c92661e5658c688';
  const employeeId = '6667c4c1c74fc105e50564b4';
  const username = 'eva';
  const phone = '1888888' + faker.string.numeric(4);

  // 获取用户
  await request(url)
    .get(`/users/${userId}`)
    .expect(200)
    .set('x-api-key', apiKey)
    .then((res) => {
      console.log('Get User');
    });

  // 更新用户
  await request(url)
    .patch(`/users/${userId}`)
    .set('x-api-key', apiKey)
    .send({
      employeeId,
    })

    .expect(200)
    .then((res) => {
      console.log('Update User');
    });

  //Upsert user by employeeId
  await request(url)
    .post(`/users/${employeeId}/@upsertUserByEmployeeId`)
    .send({
      phone,
    })
    .expect(201)
    .set('x-api-key', apiKey)
    .then((res) => {
      console.log('Upsert user by employeeId');
    });

  // upsert user by username
  await request(url)
    .post(`/users/${username}/@upsertUserByUsername`)
    .send({
      phone,
    })
    .expect(201)
    .set('x-api-key', apiKey)
    .then((res) => {
      console.log('Upsert user by username');
    });

  // upsert user by phone
  await request(url)
    .post(`/users/${phone}/@upsertUserByPhone`)
    .send({
      phone: '1888888' + faker.string.numeric(4),
    })
    .expect(201)
    .set('x-api-key', apiKey)
    .then((res) => {
      console.log('Upsert user by phone');
    });

  // update password
  await request(url)
    .post(`/users/${userId}/@updatePassword`)
    .send({
      oldPassword: 'eva@36node.com',
      newPassword: 'eva@36node.com2',
    })
    .expect(204)
    .set('x-api-key', apiKey)
    .then((res) => {
      console.log('Update password');
    });

  // delete user
  await request(url)
    .delete(`/users/${userId}`)
    .expect(204)
    .set('x-api-key', apiKey)
    .then((res) => {
      console.log('Delete user');
    });
}

测试结果:
image

@magiccaptain
Copy link
Contributor Author

namespace 测试:

async function namespaces() {
  // get namespace by key
  await request(url)
    .get(`/namespaces/key1`)
    .expect(200)
    .set('x-api-key', apiKey)
    .then((res) => {
      console.log('Get namespace by key');
    });

  // get namespace by id
  await request(url)
    .get(`/namespaces/6790577ba570fcb8cb15a83f`)
    .expect(200)
    .set('x-api-key', apiKey)
    .then((res) => {
      console.log('Get namespace by id');
    });

  // update namespace by key
  await request(url)
    .patch(`/namespaces/key1`)
    .send({
      name: 'name2',
    })
    .expect(200)
    .set('x-api-key', apiKey)
    .then((res) => {
      console.log('Update namespace by key');
    });

  // update namespace by id
  await request(url)
    .patch(`/namespaces/6790577ba570fcb8cb15a83f`)
    .send({
      name: 'name2',
    })
    .expect(200)
    .set('x-api-key', apiKey)
    .then((res) => {
      console.log('Update namespace by id');
    });

  //delete namespace
  await request(url)
    .delete(`/namespaces/6790577ba570fcb8cb15a83f`)
    .expect(204)
    .set('x-api-key', apiKey)
    .then((res) => {
      console.log('Delete namespace');
    });
}

测试结果:

image

@magiccaptain magiccaptain requested a review from zzswang January 22, 2025 06:04
@zzswang zzswang merged commit 94a01d2 into main Jan 25, 2025
4 checks passed
@zzswang zzswang deleted the feat/issue44 branch January 25, 2025 12:42
zzswang pushed a commit that referenced this pull request Feb 9, 2025
🤖 I have created a release *beep* *boop*
---


## [2.5.0](v2.4.0...v2.5.0)
(2025-02-09)


### Features

* [缓存] 给 auth 添加 redis 缓存
([#53](#53))
([94a01d2](94a01d2))


### Bug Fixes

* openapi
([742d087](742d087))
* user level
([0872969](0872969))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[缓存] 给 auth 添加 redis 缓存

2 participants