spring-boot - 在 Aerospike 中更新单个字段的最佳方法

标签 spring-boot caching redis aerospike aerospike-loader

我有一个 Aerospike 缓存,由具有 json 结构值的数据列表组成。

示例值:{"name": "John", "count": 10}

我想扫描所有记录并将计数重置为零。解决这个问题的好选择是什么?

最佳答案

我认为最好的方法是利用后台操作...我刚刚在 Aerospike sandbox 上尝试了以下代码它确实将“报告”映射中的所有“形状”条目更新为更新的形状。 (免责声明:我不是开发人员,因此一般来说,在 Java 中做事的方法可能非常糟糕,但这希望展示如何在 Aerospike 中进行后台操作扫描)

运行“设置”选项卡,然后将其复制粘贴到创建选项卡(或空白选项卡)中并运行:

import com.aerospike.client.task.ExecuteTask;
import com.aerospike.client.task.Task;
import com.aerospike.client.query.Statement;
import com.aerospike.client.query.Filter;
import com.aerospike.client.Operation;
import com.aerospike.client.exp.Exp;

AerospikeClient client = new AerospikeClient("127.0.0.1", 3000);

try {
    WritePolicy writePolicy = new WritePolicy();
    MapPolicy mapPolicy = new MapPolicy();
    String mapBinName = "report";
    String mapKeyName = "shape";

    Statement stmt = new Statement();
    stmt.setNamespace("sandbox");
    stmt.setSetName("ufodata");

    ExecuteTask task = client.execute(
      writePolicy, stmt, MapOperation.put(mapPolicy, mapBinName, 
                                          Value.get(mapKeyName), Value.get("updated shape")));

    if(task != null) {
        System.out.format("Task ID: %s\nTask Status: %s", 
            task.getTaskId(), task.queryStatus());    
    }
    else {
        System.out.format("Task seems null!");
    }
}

catch (AerospikeException ae) {
    System.out.format("Error: %s", ae.getMessage());
}

您可以将其更改为二级索引查询(如果已定义)或在 map 箱本身上添加更多过滤器...

这里有一些教程可能会有所帮助:

关于spring-boot - 在 Aerospike 中更新单个字段的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73282994/

相关文章:

java - 在 spring boot 中通过动态键读取属性

php - 当前在线访问者逻辑在 PHP 中

Redis:迭代/扫描按值排序的所有键

redis - 从 Lua 脚本调用的未知 Redis 命令

Java 服务层方法 - 主键或 Hibernate 实体参数?如果使用 Spring Boot,哪个更惯用?

spring - 如何在 Intellij 中以 Debug模式调试 spring boot maven 项目?

java - Spring boot 不生成 json 并显示白页

php - Laravel 4 Cache::remember 永远不会返回具有给定 ID 的响应

java - 如何在 Dropwizard 中实现 Guava 缓存?

java - 无法使用 Spring Data Redis 持久化数据