gpt4 book ai didi

spring - java.lang.IllegalArgumentException : IN (1): [IsIn, In]不支持redis查询派生 - Redis

转载 作者:可可西里 更新时间:2023-11-01 11:14:53 30 4
gpt4 key购买 nike

看起来 Spring Data Redis 还不支持 IsIn, In 查询。我不确定是否有任何其他方法可以作为其非常基本的查询。它可以使用 Spring Data RedisRestTemplate 来实现。

java.lang.IllegalArgumentException: IN (1): [IsIn, In]is not supported for redis query derivation
at org.springframework.data.redis.repository.query.RedisQueryCreator.from(RedisQueryCreator.java:67)
at org.springframework.data.redis.repository.query.RedisQueryCreator.create(RedisQueryCreator.java:53)
at org.springframework.data.redis.repository.query.RedisQueryCreator.create(RedisQueryCreator.java:41)
at org.springframework.data.repository.query.parser.AbstractQueryCreator.createCriteria(AbstractQueryCreator.java:119)
at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:95)
at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:81)
at org.springframework.data.keyvalue.repository.query.KeyValuePartTreeQuery.createQuery(KeyValuePartTreeQuery.java:211)
at org.springframework.data.keyvalue.repository.query.KeyValuePartTreeQuery.prepareQuery(KeyValuePartTreeQuery.java:148)
at org.springframework.data.keyvalue.repository.query.KeyValuePartTreeQuery.execute(KeyValuePartTreeQuery.java:106)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:602)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:590)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
at com.sun.proxy.$Proxy76.findByNameIn(Unknown Source)
at com.mastercard.customer.program.UserGroupTest.test(UserGroupTest.java:58)

组.java

@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
@RedisHash("groups")
public class Group {
@Id
private Long groupId;
private String name;
}

用户.java

@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
@RedisHash("users")
public class User {
@Id
private Long userId;
private String name;
}

用户组测试.java

@Log4j
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
public class UserGroupTest extends RepositoryTestSupport{
@Autowired UserRepository userRepository;
@Autowired GroupRepository groupRepository;

@Before
public void setUp() {
User user1 = User.builder().userId(1L).name("John").build();
User user2 = User.builder().userId(2L).name("Sally").build();
User user3 = User.builder().userId(3L).name("Chris").build();

Group group1 = Group.builder().groupId(1L).name("Nature-Group").build();
Group group2 = Group.builder().groupId(2L).name("Music-Group").build();
Group group3 = Group.builder().groupId(3L).name("Sports-Group").build();

userRepository.save(user1);
userRepository.save(user2);
userRepository.save(user3);

groupRepository.save(group1);
groupRepository.save(group2);
groupRepository.save(group3);
}

@Test
public void test() {
List<User> users = userRepository.findByNameIn(Arrays.asList("John", "Sally"));
System.out.println(users.size());
}
}

最佳答案

Spring Data Redis 2.1.2(撰写本文时的最新版本)不支持通过查询推导进行的In 查询。有一个ticket支持 In 查询类型。

关于spring - java.lang.IllegalArgumentException : IN (1): [IsIn, In]不支持redis查询派生 - Redis,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53264718/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com