'ioredis - I can't filter data
First, I created a form. Every time users type an entry, it shouldn't be overwritten. so it needs to be added as an extra, I found the append command in redis and applied it. But now I don't know how to filter and fetch the data.
Append command, here I am making the data JSON
const newEntry = {
owner_id,
message,
created_at: Date.now(),
score: 1,
ip: 'NA',
}
await redis.append('features', JSON.stringify(newEntry))
JSON example, I need to filter with owner_id:
{"owner_id":30902468,"message":"test","created_at":1643755923014,"score":1,"ip":"NA"}
Solution 1:[1]
The APPEND works on strings, it's not exactly what you are looking for...
You can use lists and create a list for each user:
const newEntry = {
owner_id,
message,
created_at: Date.now(),
score: 1,
ip: 'NA'
};
await redis.rpush(`features:${owner_id}`, JSON.stringify(newEntry));
await redis.lrange(`features:${owner_id}`, 0, -1);
In case you need to run more complicated queries, you should consider RediSearch + RedisJSON
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Leibale Eidelman |
