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.

is it possible to get a list of keys matching a pattern?

See original GitHub issue

something like

db.keys('foo*', function(err,  keys) { 
  if (err) return;
  db.batch( keys.map(function(key) {  return {type: 'del', key: key }; } ), done );
});

or maybe using a regexp

db.match(/foo.*/, function(err,  keys) { 
  if (err) return;
  db.batch( keys.map(function(key) {  return {type: 'del', key: key }; } ), done );
});

kind of hoped node-level-multiply to handle that for second, but I am not sure it’s possible.

Thanks

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
cheslescommented, Sep 29, 2014

There’s a createKeyStream method, which you should be able to use the standard lt, lte, gt, gte range operators with:

var keys = db.createKeyStream({gte: 'foo!', lte: 'foo~'})
var batch = []
keys.on('data', function(key) {
  batch.push({ type: "del", key: key })
})
keys.on('end', function() {
  db.batch(batch)
})
0reactions
hit9commented, Oct 13, 2014

@rvagg Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Redis: Find keys matching a pattern - Stack Overflow
Use a set for storing the key names of the pattern you want. When you add a new we key, add the name...
Read more >
Get number of keys, matching a pattern - Google Groups
googlegroups.com. Hi, list. I have a zillion keys in my redis DB. Sometimes, very rarely, I need to count all of them, matching...
Read more >
Find and Delete multiple keys matching by a pattern in Redis
Use scanstream to find and pipeline to delete keys matching pattern.Find and Delete multiple keys matching by a pattern in Redis in a...
Read more >
KEYS pattern
Returns all keys matching pattern . While the time complexity for this operation is O(N), the constant times are fairly low.
Read more >
KEYS - Redis
O(N) with N being the number of keys in the database, under the assumption that the key names in the database and the...
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