Giter Site home page Giter Site logo

Comments (5)

kiddouk avatar kiddouk commented on September 24, 2024

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.

tonycpsu avatar tonycpsu commented on September 24, 2024

@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.

kiddouk avatar kiddouk commented on September 24, 2024

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.

tonycpsu avatar tonycpsu commented on September 24, 2024

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.

kiddouk avatar kiddouk commented on September 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.