RedisModuleCallReply *replay = RedisModule_Call(ctx, "GET", "s", argv[1]);
switch (RedisModule_CallReplyType(replay)) {
case REDISMODULE_REPLY_STRING:
break;
default:
RedisModule_ReplyWithLongLong(ctx, 0);
return REDISMODULE_OK;
}
const char *proto_ptr = RedisModule_CallReplyStringPtr(replay, &proto_len);
const char *expect_ptr = RedisModule_StringPtrLen(argv[2], &expect_len);
if (proto_len != expect_len || memcmp(expect_ptr, proto_ptr, proto_len) != 0) {
RedisModule_ReplyWithLongLong(ctx, 0);
return REDISMODULE_OK;
}
}
RedisModule_DeleteKey(key);
RedisModule_Replicate(ctx, "DEL", "s", argv[1]);
可以看到,从比较值到删除是不能保证原子性的,这方面是怎么处理的使得CAD保证原子性的呢.
实在没看明白,希望解答,感谢感谢~