admin管理员组

文章数量:1419228

I need to receive data from IoT sensors and store the latest data information in Valkey.

At this time, there is a logic that checks whether the key already exists, and if it does not, it logs the event in another database. However, we occasionally observe cases where the log is recorded even though the key already exists.

A peculiar observation is that we are currently testing with only two sensors, and both sensors' logs appear at the same time when this issue occurs. Additionally, at that moment, a log stating "DB saved on disk" appears in Valkey.

Is there any way to resolve this issue? In the settings, both snapshot and AOF are already disabled.

I'm using docker compose and below is the configuration file of valkey.


notify-keyspace-events Ex

io-threads 4



################################## PERSISTENCE ###############################
# Disable RDB snapshot saving
save ""


################################## MEMORY ###################################
# Max memory usage (optional, adjust as needed)
maxmemory 512mb
maxmemory-policy allkeys-lru

# Disable AOF
appendonly no

I need to receive data from IoT sensors and store the latest data information in Valkey.

At this time, there is a logic that checks whether the key already exists, and if it does not, it logs the event in another database. However, we occasionally observe cases where the log is recorded even though the key already exists.

A peculiar observation is that we are currently testing with only two sensors, and both sensors' logs appear at the same time when this issue occurs. Additionally, at that moment, a log stating "DB saved on disk" appears in Valkey.

Is there any way to resolve this issue? In the settings, both snapshot and AOF are already disabled.

I'm using docker compose and below is the configuration file of valkey.


notify-keyspace-events Ex

io-threads 4



################################## PERSISTENCE ###############################
# Disable RDB snapshot saving
save ""


################################## MEMORY ###################################
# Max memory usage (optional, adjust as needed)
maxmemory 512mb
maxmemory-policy allkeys-lru

# Disable AOF
appendonly no
Share Improve this question asked Jan 29 at 14:34 Sehun ParkSehun Park 1431 gold badge2 silver badges11 bronze badges 1
  • The save setting only automates RDB saving. Is it safe to assume there is no SAVE or BGSAVE commands being called? Also, if you test for existence (using SET XX I hope), how can it fail the test? It could be evicted if you're running out of memory. – LeoMurillo Commented Jan 29 at 23:40
Add a comment  | 

1 Answer 1

Reset to default 1

In order to verify if a key already exist in Valkey you can use the set if not exist command.

You can use the following example code in node.js, client library valkey-glide. This is only an example, any client library in any language will do the work.

const { GlideClient } = require('@valkey/valkey-glide');
const client = await GlideClient.createClient({
            addresses: [{
                host: config.host,
                port: config.port
            }],
            useTLS: config.useTls
        });
        await client.set('custom:key', 'custom:value', {
            conditionalSet: "onlyIfDoesNotExist",
            returnOldValue: true});

For more info see https://valkey.io/commands/set/

Alternative solution is to use Lua script for more complex atomic operation. Depends on your use case.

本文标签: ioCannot disable persistence of redisStack Overflow