简体   繁体   中英

Grails .findBy doesn't work with redis

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

ie .findBy doesn't work.

Hibernate在执行查询之前会进行刷新(在本例中为findByGroupName ),但是NoSQL GORM Datastore实现尚未实现(因此),因此我假设您只需要刷新就可以将保存的实例推送到数据存储中,以便查询将其提取:

everyoneGroup.save(flush: true)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM