question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug? keyPrefix not added to the KEYS command

See original GitHub issue

Hi, 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:closed
  • Created 8 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
luincommented, Jan 28, 2016

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. For keys (as well as scan) command, Redis tells ioredis that it doesn’t contain a key, so that ioredis won’t prefix it.

0reactions
Voloxcommented, Feb 2, 2016

Thanks to all for the support, I see there is no easy solution for this.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found