Can I use JSON and Search (like RedisJSON, RediSearch)?

Idk about full text search, tbh I’m only using redis since some days, learned just enough to do my things

Yes

import { SchemaFieldTypes } from 'redis';
import { redis } from '..';

redis.ft
    .CREATE(
        'index:channels',
        {
            '$.id': {
                type: SchemaFieldTypes.TEXT,
                AS: 'id',
                SORTABLE: true,
            },
            '$.guildId': {
                type: SchemaFieldTypes.TEXT,
                AS: 'guildId',
                SORTABLE: true,
            },
            '$.name': {
                type: SchemaFieldTypes.TEXT,
                AS: 'name',
                SORTABLE: true,
            },
            '$.parentId': {
                type: SchemaFieldTypes.TEXT,
                AS: 'parentId',
                SORTABLE: true,
            },
            '$.permissionOverwrites': {
                type: SchemaFieldTypes.TEXT,
                AS: 'permissionOverwrites',
            },
            '$.position': {
                type: SchemaFieldTypes.NUMERIC as any,
                AS: 'position',
                SORTABLE: true,
            },
            '$.type': {
                type: SchemaFieldTypes.NUMERIC as any,
                AS: 'type',
                SORTABLE: true,
            },
        },
        {
            ON: 'JSON',
            PREFIX: 'channels',
        }
    )
    .catch(() => null);

This is for channels, if that helps

nice!

it’s something that we could do but it’s still a substantial task

So like I’d have to get all and filter maybe or something like that?

can you send me a sample query for filtering?

I want this to be scalable too, as it’s kinda in a medium - big scale so I do have a lot of keys like this

From redis search?

yes, like you did with create

how many keys? orders of magnitude?

I made a custom function actually but it’s more or less like main one only, here’s an example:

await utils.redisSearch('index:channels', `@guildId:${id}`);

Here, id being the guildId

And utils.redisSearch is ```ts
async redisSearch(index: string, query: string, options?: SearchOptions) {
const max = (await redis.ft.search(index, query, { LIMIT: { from: 0, size: 0 } })).total;

return await redis.ft.search(index, query, { ...options, LIMIT: { from: 0, size: max } });

}

Not too much, but about 10m for channels. I do have other indexes too (like members, roles), they both can vary a lot but I would say the roles would be like 1m - 10m, and members is unpredictable but yea, usually in less than 50m

Actually didn’t think about this, do you understand the above code?

yes, I wrote my first nodejs program 3 days ago :slightly_smiling_face:

It’s essentially like FT.SEARCH "index:channels" "@guildId:123" LIMIT 0 MAX in redis cli

yes, I can read nodejs much better than I can write it :slightly_smiling_face:

Where MAX being the number of total channels in the server

Aight

So yeah, that’s my use case, do you think something can be done regarding this?