bug? keyPrefix not added to the KEYS command
See original GitHub issueHi,
i have a problem with the KEYS command and the use of keyPrefix
. It seems that using a prefixed connection the prefix is not passed to the KEYS command.
I created a simple snippet of code to reproduce the problem.
'use strict';
let Promise = require( 'bluebird' );
let Redis = require( 'ioredis' );
const prefix = 'NS:'
// Create an unprefixed connection
let redisNP = new Redis();
// Create an prefixed connection
let redisP = new Redis( {
keyPrefix: prefix,
} );
let key = 'test:namespace:test';
let matchKey = 'test:*:test';
const data = {
mytest: 'true',
'my test2': 5,
};
// Add a namespaced(prefixed) key
redisP.hmset( key, data )
.then( () => {
// Issue the keys command to the connections
return Promise
.props( {
// Try the prefixed connection
prefix: redisP.keys( matchKey ),
// Try the unprefixed connection
noPrefix: redisNP.keys( matchKey ),
// Try to manual add the prefix to the unprefixed connection
manualPrefix: redisNP.keys( prefix+matchKey ),
} );
} )
.then( results => {
// I have 0 prefixed keys, should be 1
console.log( 'Should be 1', results.prefix.length );
// I have 0 unprefixed keys, OK
console.log( 'Should be 0', results.noPrefix.length );
// I have 1 manually prefixed keys, OK
console.log( 'Should be 1', results.manualPrefix.length );
console.log( 'Results: %j', results );
} )
.catch( err => console.error( err, err.stack ) )
.then( () => {
return [
redisP.quit(),
redisNP.quit(),
];
} );
Issue Analytics
- State:
- Created 8 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Bind key prefix + ; to open command-prompt in tmux
I am too lazy to hit the shift key. When I put this in my tmux.conf : bind-key ; command-prompt , I get...
Read more >KEYS - Redis
This command is intended for debugging and special operations, such as changing your keyspace layout. Don't use KEYS in your regular application code....
Read more >key-value | Nimbella Docs - Nimbella Account | Nimbella Docs
An error is returned when the value stored at key is not a list. USAGE. $ nim key-value llen KEY.
Read more >Working with object metadata - Amazon Simple Storage Service
Name Description Can user modify the value?
Date Current date and time. No
Content‑Disposition Object presentational information. Yes
Content‑Length Object size in bytes. No
Read more >Redis Namespace and Other Keys to Developing with Redis
Learn about Redis namespace, Redis delete keys with prefixes, & Redis database ... This behavior is unlike that of the (hiss) KEYS command, ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Actually it’s not a bug. ioredis relies on the
COMMAND
command of Redis to get the position of the keys in a command’s parameters. Forkeys
(as well asscan
) command, Redis tells ioredis that it doesn’t contain a key, so that ioredis won’t prefix it.Thanks to all for the support, I see there is no easy solution for this.