Comments (5)
done. pushed to master
from johm.
I think, this is not the right way to solve id problem. We need more generic approach to support different id types such as String. At least because redis is key-value store.
from johm.
Anton - a String id is not a very efficient mechanism for anything. At some level, it will have to be transformed to an integer like what Redis does by converting to 64-bit signed int. Actually, if we forget about Redis and focus on our clients, can you give an example where a JOhm client will be better served by having an id String like "94588" instead of just a long/integer type? Apart from String's slowness, we are opening us up to potential number format exceptions. With that tradeoff in mind, unless there is a compelling case where a client will be using String id's (example?), I have never been convinced we should go down that route.
from johm.
My minor goal is go possibly close to JPA specification. This allow easier to migrate from RDBMS.
I don't know how Redis and clients work - it's not my domain. If you say it's bad idea, then it's bad idea :)
Specially in my use case I store user session in Redis (I see Redis/Memcached storages for jetty and tomcat, but not for both containers) and for use JOhm I must generate Long session id's and result is:
UserSessionModel:1215265415737719425
Another cases: coupons and short-url-services, or generally string to whatever mappings.
I can imagine user defined functions to generate id's - this allow generate not only sequential id's as with incr(), ex.:
@model(generator=MyIdGenerator.class)
class MyModel() [...]
class MyIdGenerator {
public static Object generateId(Class entity) {
SecureRandom sr = new SecureRandom().nextLong();
Long id;
do {
id = sr.nextLong();
while ( JOhm.exists(entity, id) );
return id;
}
Sorry, if it's nonsense :)
from johm.
I see what you are saying and this is good thinking and a real-world use-case. So, what you are suggesting is a pluggable IdGenerator option which I like as an idea. I was confused by your earlier suggestion of the string id type: "different id types such as String".
So, now we need to think about global uniqueness in the presence of multiple clients generating id's using the custom IdGenerators and then having to persist to Redis objects loaded with these id's. You could have 15 nodes with JOhm deployments for application persistence all writing to a Redis backing instance and in-memory IdGenerators with potential id conflicts - you get the point.
That brings us back to the search for a reliable globally unique IdGenerator-as-a-service (something like Twitter's specialized service Snowflake). Or a poor man's db-sequence or incr() function :-)
Single-node IdGeneration is relatively trivial but I would love to hear your thoughts on a cheap way (think cross-node IO) to produce global id's. And plugging into JOhm is not a problem - we can easily inject a remote IdGenerationServiceProxy into JOhm and even batch-fetch like 1000 id's and cache client-side for quick-use. Maybe we can keep it simple and just 'extend' the data retrieved by an incr() call by adding some alphanumeric fields to elongate the id.
from johm.
Related Issues (20)
- support for Date fields HOT 4
- add support for searches
- Expire time for an object
- Commands "select" and "flushdb" or "exists" on database
- Commands "select" and "flushdb" or "exists" on database
- If a JOhm references itself, it leads to infinite recursion
- At least one attribute with a value appears to be required
- Collections Need to Implement Hashcode Equals
- Getting error redis.clients.johm.JOhmException: java.lang.IllegalArgumentException: Can not set java.lang.Long field User.id to java.lang.Integer HOT 3
- JOhm doesn't support Jedis 2.0.0 HOT 1
- Feature Request: Any plans to support enums or Arrays anytime soon ?
- what 's the reason of "nest.cat("all").sadd(String.valueOf(JOhmUtils.getId(model)));" ?
- avoid to parse classes and work on model at runtime HOT 1
- Allow multiple instances of JOhm
- the Integer.parseInt in RedisMap
- Reading NULL into Long fails with NullPointerException
- Feature Request: Ability to use String or UUID as @Id HOT 1
- Does JOhm support ShardedJedisPool?
- Out of date. Abandoned? HOT 8
- Connection pool gets exhausted after a while HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from johm.