Grails .findBy 不适用于 redis
我有一个非常简单的测试用例,我用它来尝试理解 redis。我安装了 redis-gorm 插件。
域对象:
class BenchGroup {
String groupName
/*static mapWith = "redis"
static mapping = {
groupName(index:true)
}*/
static constraints = {
}
}
引导代码:
def everyoneGroup = new BenchGroup(groupName:'everyoneGroup')
everyoneGroup.save()
if(everyoneGroup.hasErrors()){
println everyoneGroup.errors
}
println everyoneGroup
def dammit = BenchGroup.findByGroupName('everyoneGroup')
println dammit
当我将redis映射行注释掉时,它使用HSQL并输出:
stupidbenchmarks.BenchGroup : 2
stupidbenchmarks.BenchGroup : 2
当我切换到redis时,它会执行以下操作:
stupidbenchmarks.BenchGroup : 2
null
即.findBy不起作用。
I have a very simple test case I am using to try to understand redis. I did install-plugin redis-gorm.
Domain Object:
class BenchGroup {
String groupName
/*static mapWith = "redis"
static mapping = {
groupName(index:true)
}*/
static constraints = {
}
}
Bootstrap Code:
def everyoneGroup = new BenchGroup(groupName:'everyoneGroup')
everyoneGroup.save()
if(everyoneGroup.hasErrors()){
println everyoneGroup.errors
}
println everyoneGroup
def dammit = BenchGroup.findByGroupName('everyoneGroup')
println dammit
When I leave the redis map line commented it uses HSQL and outputs this:
stupidbenchmarks.BenchGroup : 2
stupidbenchmarks.BenchGroup : 2
When I switch to redis it does this:
stupidbenchmarks.BenchGroup : 2
null
i.e. .findBy doesn't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Hibernate 在执行查询之前刷新(在本例中为
findByGroupName
),但 NoSQL GORM 数据存储实现还没有,所以我假设您只需要刷新即可将保存的实例推送到数据存储,以便查询选择起来:Hibernate flushes before doing queries (in this case
findByGroupName
) but the NoSQL GORM Datastore implementations don't (yet) so I assume you just need a flush to push the saved instance to the datastore so the query picks it up: