我想刪除一個redis鍵,但由於某種原因它不是刪除,但也沒有拋出異常。這裏是我的代碼刪除:春季Redis刪除不刪除密鑰
import com.example.service.CustomerService;
import com.example.model.Customer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import java.math.BigInteger;
import java.util.*;
@Service
public class RedisCustomerService implements CustomerService {
@Autowired
private RedisTemplate<String, Object> redisTemplate;
private String uniqueIdKey = "customerId";
private BigInteger uniqueId() {
long uniqueId = this.redisTemplate.opsForValue().increment(uniqueIdKey, 1);
return BigInteger.valueOf(uniqueId);
}
private String lastNameKey(BigInteger id) {
return "customer:ln:" + id;
}
private String firstNameKey(BigInteger id) {
return "customer:fn:" + id;
}
@Override
public void deleteCustomer(BigInteger id) {
redisTemplate.opsForValue().getOperations().delete(String.valueOf(id));
}
}
從Redis的-CLI中使用監控命令查看發送到Redis的服務器,命令。 http://redis.io/commands/monitor –
是你的redis一個主實例嗎?如果您嘗試刪除從機實例上的密鑰,您的行爲就會發生。 – user1151446