-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Labels
status: good-first-issueAn issue that can only be worked on by brand new contributorsAn issue that can only be worked on by brand new contributors
Milestone
Description
Bug Report
Current Behavior
Stack trace
org.springframework.data.redis.RedisSystemException: Error in execution; nested exception is io.lettuce.core.RedisReadOnlyException: READONL
Y You can't write against a read only replica.
at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:54)
at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:52)
at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:41)
at org.springframework.data.redis.PassThroughExceptionTranslationStrategy.translate(PassThroughExceptionTranslationStrategy.java:44)
at org.springframework.data.redis.FallbackExceptionTranslationStrategy.translate(FallbackExceptionTranslationStrategy.java:42)
at org.springframework.data.redis.connection.lettuce.LettuceConnection.convertLettuceAccessException(LettuceConnection.java:272)
at org.springframework.data.redis.connection.lettuce.LettuceConnection.await(LettuceConnection.java:1063)
at org.springframework.data.redis.connection.lettuce.LettuceConnection.lambda$doInvoke$4(LettuceConnection.java:920)
at org.springframework.data.redis.connection.lettuce.LettuceInvoker$Synchronizer.invoke(LettuceInvoker.java:673)
at org.springframework.data.redis.connection.lettuce.LettuceInvoker$DefaultSingleInvocationSpec.get(LettuceInvoker.java:589)
at org.springframework.data.redis.connection.lettuce.LettuceGeoCommands.geoRadius(LettuceGeoCommands.java:211)
at org.springframework.data.redis.connection.DefaultedRedisConnection.geoRadius(DefaultedRedisConnection.java:1520)
at org.springframework.data.redis.core.DefaultGeoOperations.lambda$radius$7(DefaultGeoOperations.java:185)
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:223)
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:190)
at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:97)
at org.springframework.data.redis.core.DefaultGeoOperations.radius(DefaultGeoOperations.java:185)
at org.springframework.data.redis.core.DefaultBoundGeoOperations.radius(DefaultBoundGeoOperations.java:144)
at org.ggcc.commons.utils.RedisGeographyUtil.nearbyListByPosition(RedisGeographyUtil.java:64)
at org.ggcc.ticket.service.impl.OperatorMiniServiceImpl.getShopInfoListByPosition(OperatorMiniServiceImpl.java:213)
at org.ggcc.ticket.service.impl.OperatorMiniServiceImpl.getShopTypeList(OperatorMiniServiceImpl.java:490)
at org.ggcc.ticket.controller.OperatorMiniController.sw$original$getShopTypeList$ua8s811(OperatorMiniController.java:83)
at org.ggcc.ticket.controller.OperatorMiniController.sw$original$getShopTypeList$ua8s811$accessor$sw$b61kld3(OperatorMiniController.java)
at org.ggcc.ticket.controller.OperatorMiniController$sw$auxiliary$rign841.call(Unknown Source)
at org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstMethodsInter.intercept(InstMethodsInter.java:86)
Input Code
Input Code
@ConditionalOnProperty(value = "spring.redis.replica-preferred", havingValue = "true")
@Component
@Slf4j
public class RedisPreferredLettuceClientConfigurationBuilderCustomizer implements LettuceClientConfigurationBuilderCustomizer, InitializingBean {
@Override
public void customize(LettuceClientConfiguration.LettuceClientConfigurationBuilder clientConfigurationBuilder) {
log.info("RedisPreferredLettuceClientConfigurationBuilderCustomizer.customize");
clientConfigurationBuilder.readFrom(ReadFrom.REPLICA_PREFERRED);
}
@Override
public void afterPropertiesSet() throws Exception {
log.info("RedisPreferredLettuceClientConfigurationBuilderCustomizer inited");
}
}
public List<GeographyDTO<T>> nearbyListByPosition(String key, double longitude, double latitude, int distance, int limit, Class<T> clazz) {
BoundGeoOperations<String, Object> boundGeoOperations = geoRedisTemple.boundGeoOps(key);
RedisGeoCommands.GeoRadiusCommandArgs geoRadiusCommandArgs = RedisGeoCommands.GeoRadiusCommandArgs
.newGeoRadiusArgs().includeDistance().limit(limit).sortAscending();
List<GeoResult<RedisGeoCommands.GeoLocation<Object>>> geoResultList = Objects.requireNonNull(
/**
*
* the under line caused the bug
*/
boundGeoOperations.radius(new Circle(new Point(longitude, latitude), distance), geoRadiusCommandArgs)
).getContent();
if (CollectionUtil.isEmpty(geoResultList)) {
log.info("缓存中没有推荐数据!");
return Lists.newArrayList();
}
return geoResultList.stream().map(geoResult -> {
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(geoResult));
GeographyDTO<T> geography = new GeographyDTO<>();
geography.setObject(JSON
.parseObject(JSON.toJSONString(JSON.parseObject(JSON.toJSONString(jsonObject.get("content")))
.get("name")),clazz));
geography.setDistance(geoResult.getDistance().getValue());
return geography;
}).collect(Collectors.toList());
}
Expected behavior/code
Environment
- Lettuce version(s): [6.1.8.RELEASE]. lettuce-core
- Redis version: [6.2.6]. READ_ONLY NONE
Possible Solution
Additional context
Metadata
Metadata
Assignees
Labels
status: good-first-issueAn issue that can only be worked on by brand new contributorsAn issue that can only be worked on by brand new contributors