Reputation: 75
I have a question, is it possible to create a LIKE
operator search in Redis? Similar to relational (mysql/oracle) database.
I have complex json:
{"_id" : ObjectId("581c8b8854fdcd1ff8c944e0"),
"Objectcode" : "xxxxx",
"Objecttype" : "xxxx",
"docid" : "581c8b8554fdcd1ff8c93d10",
"description" : "Tags based search .... ",
"metaTags" : [
"tag1",
"tag2",
"tag3",
"tag5",
"tag6",
"tag7",
"tag8",
"tag9",
"tag10"
],
"__v" : 0
}
and i want to search on array of metaTags how can i do it?
Thanks
Upvotes: 3
Views: 9569
Reputation: 4035
You can use Redis *SCAN commands http://redis.io/commands/scan, depending of your type of data to filter by a pattern:
Never use KEYS in app code, because it may ruin performance.
The two major nodejs redis client libraries node_redis and ioredis support it, with some syntax sugar:
const keys = [];
const redis = new Redis(); // ioredis
redis.mset('foo1', 1, 'foo2', 1, 'foo3', 1, 'foo4', 1, 'foo10', 1, () => {
const stream = redis.scanStream();
stream.on('data', data => {
keys = keys.concat(data);
});
stream.on('end', () => {
assert.equal(keys.sort(), ['foo1', 'foo10', 'foo2', 'foo3', 'foo4']);
});
});
Upvotes: 0
Reputation: 2645
You can use MATCH commands to search data.
Eg: scan 0 MATCH *11*
Refer: http://redis.io/commands/scan
Upvotes: 1