grails / gorm-redis

GORM for Redis
Apache License 2.0
14 stars 2 forks source link

Initial save() require manual flush to write to the database #1

Open joemccall86 opened 7 years ago

joemccall86 commented 7 years ago

Reproduced with a sample application.

When I create a new GORM instance and call save(), the expected behavior is for the data to be written when the session is flushed automatically.

What appears to be happening is that the insert never happens completely, though redis-cli monitor prints

1490915589.935292 [0 127.0.0.1:49638] "INCR" "gorm.redis.test.Book.next_id"

When I change it to save(flush: true), the data persists as expected.

While I understand 100% GORM-hibernate compatibility is not the goal, I would expect that calling save() would still allow the underlying implementation to handle flushing the session for me.

Example project: https://github.com/joemccall86/gorm-redis-test

Instructions: Run the grails app, and use cURL according to the following examples:

# Using hibernate
[~/code/gorm-redis-test]$ curl http://localhost:8080/book/save
saved%
[~/code/gorm-redis-test]$ curl http://localhost:8080/book/index
Author: John Doe, Pages: 300
1 books total
# Using mapWith="redis"
[~/code/gorm-redis-test]$ curl http://localhost:8080/book/save
saved%
[~/code/gorm-redis-test]$ curl http://localhost:8080/book/index
0 books total

Tested with "org.grails.plugins:redis-gorm:6.0.4" and gormVersion=6.1.0.RELEASE.

prokhor-ozornin commented 6 years ago

I am having the same issue with both hibernate and redis-gorm plugins installed.

  1. When saving redis-mapped entity with save() method and without flush: true argument, changes are not persisted to redis and subsequent call of refresh() method or querying from another thread clearly shows it.
  2. When saving redis-mapped entity with flush: true argument, changes are successfully persisted, but indexed properties become broken, so subsequent querying by indexed property does not return entity instance, while it should. However, list() method (and list().find { it.someIndexedProperty = someValue }) returns the instance as usual. This is a major index/saving issue that breaks its effectiveness.