New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how does a struct saved by the zoom #7
Comments
Great question. All the fields for the struct are stored in a hash with the key When you call Save, the model's id is also added to a set of all ids for a given type. The key for the set is Lastly if you add the Here's a concrete example. Let's say you have a Person type: type Person struct {
Name string
Age int `zoom:"index"`
zoom.DefaultData
} And you create and save a new person like so: person := &Person{
Name: "Bob",
Age: 27,
}
if err := zoom.Save(person); err != nil {
// handle err
} When you call Save, a random id will be generated for the model. For the sake of simplicity let's say the id that was generated was "foo". Here are the redis commands that will be run: # Add the fields to the main model hash
HMSET Person:foo Name Bob Age 27
# Add the model id to the set of all person ids
SADD Person:all foo
# Index the Age field in a sorted set
ZADD Person:Age 27 foo Note that I left out string indexes because those are a bit more complicated. However, I'm happy to share if you are curious. In order to get the fields for the model from redis, you need to know the id. In the above example, you could use Let me know if you have any other questions. Otherwise, I will add all this information to the documentation and then close this issue. |
By the way, in the rewrite branch there are methods to get all the keys that are used for storing a model in redis. I'm not sure when I will be able to merge it into master, but I'm working on the rewrite branch almost every day. |
Thank you for your great answer. I 'm looking forward to the rewrite branch. |
@xiaoao I have written a wiki page which provides more information about how Zoom works under the hood. I may add more information to it later, but I believe it is sufficient. I'm going to close this issue for now. Please let me know if you feel there is any information missing from the wiki page. |
set, hash, or list? and how can I get it by redis-cli?
The text was updated successfully, but these errors were encountered: