Comments (5)
The way I solve that for now is by doing :
class Game(models.Model):
_players_id = None
@property
def players(self):
if _players_id is None:
self._players_id = Set("%s:%s:players_id" % (self.__class__.__name__, self.id)
return [Player.objects.get_by_id(pid) for pid in self._players_id]
def add_player(self, player):
self._players_id.add(player.id)
This is slightly hackish since you have to manually check for not triggering MissingID exception and play so on, But that way, you use a Native Redis object to store your data.
from redisco.
@kiddouk, that is indeed a good workaround -- I do think explicitly supporting ListFields composed of ReferenceFields would be cleaner, but your solution is still pretty clean.
As to how to actually make it work the cleaner way... Python's collections.defaultdict supports this sort of nested structure by allowing you to pass in a callable that creates the class you want to create a defaultdict of. e.g.
defaultdict(int)
for a dict of ints defaulting to 0, or
defaultdict(lambda: defaultdict(int))
Fir a dict of dicts of ints defaulting to 0
Might this approach work in redisco to allow this sort of nesting?
from redisco.
That is definitely worth looking at. Do you fancy creating a pull request for testing that out maybe ?
We also have to consider the amount of time lost in making too many requests for get the data. I believe it is a trade of between convenience, object related things and performance.
Let's also have a look at what Ohm is doing (since the project is inspired by Ohm).
from redisco.
I'm afraid my Ruby knowledge is too rudimentary to make head or tail of what Ohm is doing with lists and references. I also just started working with Redis this past weekend, so I'm afraid I might not be the best candidate to give this a go in redisco, either. :/
from redisco.
So I got to look at Ohm behavior. It seems that they haven't decided to take the "duplication" approach. We may want to do the same in Redisco. I will mockup something and submit it to see if that could match our expectations.
from redisco.
Related Issues (20)
- Some architecture questions HOT 2
- Default port ?
- Dumping pickled data HOT 2
- Indexing for DateTimeField and auto_now_add
- Saving twice causes model to become non-unique.
- DateTimeField getting corrupted on save if microsecond part has less then 6 positions
- Add a `unique_together` option
- Missing "zrevrangebyscore" function on SortedSet
- Redisco should be TimeZone Aware
- Operations like ZADD and PUSH should return redis returned value
- filter and chained zfilter prevent filter to be applied
- get_by_id should be aware of previous filters
- Pipelining or Bulk_Create? HOT 1
- ImportError HOT 2
- Recursion issue with ListField of ReferenceField
- Using Mixins to add common fields to a model doesn't work HOT 1
- Self-reference (recursive) ManyToOne/OneToMany relationships available?
- Storing utc datetime values for auto_now_add HOT 2
- DateTimeField save wrong value
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 redisco.