Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keyPrefix doesn't works well with Buffer key. #1486

Closed
runningrunning opened this issue Jan 7, 2022 · 3 comments
Closed

keyPrefix doesn't works well with Buffer key. #1486

runningrunning opened this issue Jan 7, 2022 · 3 comments

Comments

@runningrunning
Copy link

runningrunning commented Jan 7, 2022

ioredis 4.28.0. node 14.18.2.

Once the keyPrefix is used, the key used for stroring seems like keyPrefix + String(key). So for 0xef it will be '�'.

>DEBUG=ioredis:* node
> redis = require('ioredis')(); redis.set(Buffer.from([0xef]), Buffer.from([0xff])).then(()=>redis.getBuffer(Buffer.from(['0xef'])).then(console.log));
>   ioredis:redis status[127.0.0.1:6379]: connecting -> connect +7ms
  ioredis:redis write command[127.0.0.1:6379]: 0 -> info([]) +0ms
  ioredis:redis status[127.0.0.1:6379]: connect -> ready +2ms
  ioredis:connection send 1 commands in offline queue +0ms
  ioredis:redis write command[127.0.0.1:6379]: 0 -> set([ <Buffer ef>, <Buffer ff> ]) +0ms
  ioredis:redis write command[127.0.0.1:6379]: 0 -> get([ <Buffer ef> ]) +1ms
<Buffer ff>
> redis2 = require('ioredis')({keyPrefix:'test'}); redis2.set(Buffer.from([0xef]), Buffer.from([0xff])).then(()=>redis2.getBuffer(Buffer.from(['0xef'])).then(console.log));
>   ioredis:redis status[127.0.0.1:6379]: connecting -> connect +1ms
  ioredis:redis write command[127.0.0.1:6379]: 0 -> info([]) +1ms
  ioredis:redis status[127.0.0.1:6379]: connect -> ready +0ms
  ioredis:connection send 1 commands in offline queue +29s
  ioredis:redis write command[127.0.0.1:6379]: 0 -> set([ 'test�', <Buffer ff> ]) +0ms
  ioredis:redis write command[127.0.0.1:6379]: 0 -> get([ 'test�' ]) +1ms
<Buffer ff>
> redis3 = require('ioredis')({keyPrefix:Buffer.from([0xaf])}); redis3.setBuffer(Buffer.from([0xef]), Buffer.from([0xff])).then(()=>redis3.getBuffer(Buffer.from(['0xef'])).then(console.log));
>   ioredis:redis status[127.0.0.1:6379]: connecting -> connect +3ms
  ioredis:redis write command[127.0.0.1:6379]: 0 -> info([]) +0ms
  ioredis:redis status[127.0.0.1:6379]: connect -> ready +2ms
  ioredis:connection send 1 commands in offline queue +7m
  ioredis:redis write command[127.0.0.1:6379]: 0 -> set([ '��', <Buffer ff> ]) +1ms
  ioredis:redis write command[127.0.0.1:6379]: 0 -> get([ '��' ]) +1ms
<Buffer ff>
> redis4 = require('ioredis')({keyPrefix:Buffer.from([0xaf])}); redis4.setBuffer(Buffer.from([0xef]), Buffer.from([0xff])).then(()=>redis4.get(Buffer.from(['0xef'])).then(console.log));
>   ioredis:redis status[127.0.0.1:6379]: connecting -> connect +2ms
  ioredis:redis write command[127.0.0.1:6379]: 0 -> info([]) +0ms
  ioredis:redis status[127.0.0.1:6379]: connect -> ready +1ms
  ioredis:connection send 1 commands in offline queue +37s
  ioredis:redis write command[127.0.0.1:6379]: 0 -> set([ '��', <Buffer ff> ]) +0ms
  ioredis:redis write command[127.0.0.1:6379]: 0 -> get([ '��' ]) +1ms
��
@luin luin closed this as completed in 6942cec Mar 19, 2022
github-actions bot pushed a commit that referenced this issue Mar 19, 2022
# [5.0.0-beta.4](v5.0.0-beta.3...v5.0.0-beta.4) (2022-03-19)

### Bug Fixes

* add missing declaration for callBuffer ([08c9072](08c9072))
* keyPrefix should work with Buffer ([6942cec](6942cec)), closes [#1486](#1486)
@github-actions
Copy link

🎉 This issue has been resolved in version 5.0.0-beta.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

@runningrunning
Copy link
Author

赞~!

github-actions bot pushed a commit that referenced this issue Mar 26, 2022
# [5.0.0](v4.28.5...v5.0.0) (2022-03-26)

### Bug Fixes

* add @ioredis/interface-generator to dev deps ([aa3b3e9](aa3b3e9))
* add missing declaration for callBuffer ([08c9072](08c9072))
* add the missing typing for Redis#call() ([747dd30](747dd30))
* better support for CJS importing ([687d3eb](687d3eb))
* disable slotsRefreshInterval by default ([370fa62](370fa62))
* Fix the NOSCRIPT behavior when using pipelines ([bc1b168](bc1b168))
* improve typing for auto pipelining ([4e8c567](4e8c567))
* improve typing for pipeline ([d18f3fe](d18f3fe))
* keyPrefix should work with Buffer ([6942cec](6942cec)), closes [#1486](#1486)
* make fields private when possible ([d5c2f20](d5c2f20))
* parameter declaration of Redis#duplicate ([a29d9c4](a29d9c4))
* pipeline fails when cluster is not ready ([af60bb0](af60bb0)), closes [#1460](#1460)
* remove dropBufferSupport option ([04e68ac](04e68ac))
* remove unused Command#isCustomCommand ([46ade6b](46ade6b))
* rename interfaces by dropping prefix I ([d1d9dba](d1d9dba))
* Reset loaded script hashes to force a reload of scripts after reconnect of redis ([60c2af9](60c2af9))
* support passing keyPrefix via redisOptions ([6b0dc1e](6b0dc1e))

### Features

* add [@SInCE](https://github.com/since) to method comments ([13eff8e](13eff8e))
* add declarations for methods ([1e10c95](1e10c95))
* add tests for cluster ([1eba58b](1eba58b))
* always parse username passed via URI ([c6f41f6](c6f41f6))
* drop support of Node.js 10 ([f9a5071](f9a5071))
* drop support of third-party Promise libraries ([2001ec6](2001ec6))
* expose official declarations ([7a436b1](7a436b1))
* improve typings for cluster ([06782e6](06782e6))
* improve typings for pipeline ([334242b](334242b))
* improve typings for smismember ([487c3a0](487c3a0))
* improve typings for transformers ([94c1e24](94c1e24))
* improve typings for xread ([96cc335](96cc335))
* Pipeline-based script loading ([8df6ee2](8df6ee2))
* prepare v5 stable release ([#1538](#1538)) ([fe32ce7](fe32ce7))
* Refactor code with modern settings ([a8ffa80](a8ffa80))
* skip ready check on NOPERM error ([b530a0b](b530a0b)), closes [#1293](#1293)
* support commands added in Redis v7 ([53ca412](53ca412))
* support defining custom commands via constructor options ([f293b97](f293b97))
* support Redis Functions introduced in Redis 7.0 ([32eb381](32eb381))

### BREAKING CHANGES

* `slotsRefreshInterval` is disabled by default,
previously, the default value was 5000.
* `allowUsernameInURI` is removed and ioredis will always
use the username passed via URI.
Previously, the `username` part in `new Redis("redis://username:authpassword@127.0.0.1:6380/4")`
was ignored unless `allowUsernameInURI` is specified: `new Redis("redis://username:authpassword@127.0.0.1:6380/4?allowUsernameInURI=true")`.
Now, if you don't want to send username to Redis, just leave the username part empty:
`new Redis("redis://:authpassword@127.0.0.1:6380/4")`
* `Redis#serverInfo` is removed. This field is never documented so
you very likely have never used it.
* Support for third-party Promise libraries is dropped. Related methods (`exports.Promise = require('bluebird')`) are kept but they don't take any effects. The native Promise will always be used.
* We now require Node.js v10.12.0 or newer.
* We now only work with Redis v3.0.0 or newer.
* `Redis` can't be called as a function anymore as it's now a class.
Please change `Redis()` to `new Redis()`. Note that `Redis()` was already deprecated
in the previous version.
@github-actions
Copy link

🎉 This issue has been resolved in version 5.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

janus-dev87 added a commit to janus-dev87/ioredis-work that referenced this issue Mar 1, 2024
# [5.0.0-beta.4](redis/ioredis@v5.0.0-beta.3...v5.0.0-beta.4) (2022-03-19)

### Bug Fixes

* add missing declaration for callBuffer ([08c9072](redis/ioredis@08c9072))
* keyPrefix should work with Buffer ([6942cec](redis/ioredis@6942cec)), closes [#1486](redis/ioredis#1486)
janus-dev87 added a commit to janus-dev87/ioredis-work that referenced this issue Mar 1, 2024
# [5.0.0](redis/ioredis@v4.28.5...v5.0.0) (2022-03-26)

### Bug Fixes

* add @ioredis/interface-generator to dev deps ([aa3b3e9](redis/ioredis@aa3b3e9))
* add missing declaration for callBuffer ([08c9072](redis/ioredis@08c9072))
* add the missing typing for Redis#call() ([747dd30](redis/ioredis@747dd30))
* better support for CJS importing ([687d3eb](redis/ioredis@687d3eb))
* disable slotsRefreshInterval by default ([370fa62](redis/ioredis@370fa62))
* Fix the NOSCRIPT behavior when using pipelines ([bc1b168](redis/ioredis@bc1b168))
* improve typing for auto pipelining ([4e8c567](redis/ioredis@4e8c567))
* improve typing for pipeline ([d18f3fe](redis/ioredis@d18f3fe))
* keyPrefix should work with Buffer ([6942cec](redis/ioredis@6942cec)), closes [#1486](redis/ioredis#1486)
* make fields private when possible ([d5c2f20](redis/ioredis@d5c2f20))
* parameter declaration of Redis#duplicate ([a29d9c4](redis/ioredis@a29d9c4))
* pipeline fails when cluster is not ready ([af60bb0](redis/ioredis@af60bb0)), closes [#1460](redis/ioredis#1460)
* remove dropBufferSupport option ([04e68ac](redis/ioredis@04e68ac))
* remove unused Command#isCustomCommand ([46ade6b](redis/ioredis@46ade6b))
* rename interfaces by dropping prefix I ([d1d9dba](redis/ioredis@d1d9dba))
* Reset loaded script hashes to force a reload of scripts after reconnect of redis ([60c2af9](redis/ioredis@60c2af9))
* support passing keyPrefix via redisOptions ([6b0dc1e](redis/ioredis@6b0dc1e))

### Features

* add [@SInCE](https://github.com/since) to method comments ([13eff8e](redis/ioredis@13eff8e))
* add declarations for methods ([1e10c95](redis/ioredis@1e10c95))
* add tests for cluster ([1eba58b](redis/ioredis@1eba58b))
* always parse username passed via URI ([c6f41f6](redis/ioredis@c6f41f6))
* drop support of Node.js 10 ([f9a5071](redis/ioredis@f9a5071))
* drop support of third-party Promise libraries ([2001ec6](redis/ioredis@2001ec6))
* expose official declarations ([7a436b1](redis/ioredis@7a436b1))
* improve typings for cluster ([06782e6](redis/ioredis@06782e6))
* improve typings for pipeline ([334242b](redis/ioredis@334242b))
* improve typings for smismember ([487c3a0](redis/ioredis@487c3a0))
* improve typings for transformers ([94c1e24](redis/ioredis@94c1e24))
* improve typings for xread ([96cc335](redis/ioredis@96cc335))
* Pipeline-based script loading ([8df6ee2](redis/ioredis@8df6ee2))
* prepare v5 stable release ([#1538](redis/ioredis#1538)) ([fe32ce7](redis/ioredis@fe32ce7))
* Refactor code with modern settings ([a8ffa80](redis/ioredis@a8ffa80))
* skip ready check on NOPERM error ([b530a0b](redis/ioredis@b530a0b)), closes [#1293](redis/ioredis#1293)
* support commands added in Redis v7 ([53ca412](redis/ioredis@53ca412))
* support defining custom commands via constructor options ([f293b97](redis/ioredis@f293b97))
* support Redis Functions introduced in Redis 7.0 ([32eb381](redis/ioredis@32eb381))

### BREAKING CHANGES

* `slotsRefreshInterval` is disabled by default,
previously, the default value was 5000.
* `allowUsernameInURI` is removed and ioredis will always
use the username passed via URI.
Previously, the `username` part in `new Redis("redis://username:authpassword@127.0.0.1:6380/4")`
was ignored unless `allowUsernameInURI` is specified: `new Redis("redis://username:authpassword@127.0.0.1:6380/4?allowUsernameInURI=true")`.
Now, if you don't want to send username to Redis, just leave the username part empty:
`new Redis("redis://:authpassword@127.0.0.1:6380/4")`
* `Redis#serverInfo` is removed. This field is never documented so
you very likely have never used it.
* Support for third-party Promise libraries is dropped. Related methods (`exports.Promise = require('bluebird')`) are kept but they don't take any effects. The native Promise will always be used.
* We now require Node.js v10.12.0 or newer.
* We now only work with Redis v3.0.0 or newer.
* `Redis` can't be called as a function anymore as it's now a class.
Please change `Redis()` to `new Redis()`. Note that `Redis()` was already deprecated
in the previous version.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant