Skip to content

bug? keyPrefix not added to the KEYS command #239

Closed
@Volox

Description

@Volox

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(),
  ];
} );

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions