5.7 Redis forwarding for positions

dilkh2 years ago

Good afternoon.
What configuration should I use to make a forward for Redis with a choice of db Redis?

Or if possible, please write where you can see configuration examples for version 5.7.
(Auto-registration filtering by a regular expression,Automatic command triggering by events,Raw network data forwarding in original format etc)
Thanks.

Anton Tananaev2 years ago

The Redis configuration should look something like this:

<entry key='forward.type'>redis</entry>
<entry key='forward.url'>redis://host:port</entry>
dilkh2 years ago

Спасибо.
А как выбрать номер БД в которую будет forward?
(select 1,2 ...)
Или по дефолту в 1 бд?

Anton Tananaev2 years ago

I think you can do something like this:

redis://host:port/database
dilkh2 years ago

Thank you very much!
I will try.
I would be very grateful if you would share the configuration about forwarding "Forwarding raw network data in the original format" and software "Automatic execution of the command by events".

Anton Tananaev2 years ago

Check other forum threads. Those have been discussed already.

dilkh2 years ago

Thank.

dilkh2 years ago

I started everything.
In Redis, it is obtained in the LIST traccar saves type.
And when Traccar creates a key of the LIST type, does it specify a limit on the length of the LIST ? Or should I make a wrapper and delete the old one?
Or as an option to use LTRIM ?

Anton Tananaev2 years ago

Here's the code if you're interested in more details on how it works:

https://github.com/traccar/traccar/blob/master/src/main/java/org/traccar/forward/PositionForwarderRedis.java

We don't have any limits and we don't delete anything.

dilkh2 years ago

Yes, thanks.
The code uses lpush.
So either need to write a wrapper to delete old records.
Or in PositionForwarderRedis.java to do ltrim

jedis.ltrim(key, 100);

Otherwise, redis will grow rapidly and fall due to lack of memory.

dilkh2 years ago
        try (Jedis jedis = new Jedis(url)) {
            jedis.lpush(key, value);
            jedis.ltrim(key, 100);
        }

You can even put 100 in a configuration variable.
100 - the number of deleted entries in the LIST

Anton Tananaev2 years ago

Do you mean it's a number of positions we keep?

dilkh2 years ago

LTRIM обрежет список созданный LPUSH до 100 элементов
LTRIM x,y
x=100;
y=-1;
оставит последние x записей и обрежет после x записи до конца списка -1

https://redis.io/commands/ltrim/

dilkh2 years ago

В текущем варианте используется по сути создание мини-копии БД в памяти. Насколько это удобно будет при количестве устройств более 200 и сколько потребуется ресурсов в памяти.. По практике 200 устройств за месяц делают в mariadb около 10 гигабайт записей.
Могу предложить другой вариант.
Использовать SET и в качестве ключа будет uniq трекера. В json вложить таймштамп создания в redis.
В этом варианте будет всегда быстрый доступ к последним данным минуя api или sql.

Anton Tananaev2 years ago

We could make it configurable. Feel free to send a PR or create a ticket on GitHub.