pilat / redis-astra Goto Github PK
View Code? Open in Web Editor NEWPython light ORM for Redis
License: MIT License
Python light ORM for Redis
License: MIT License
Hello, I have a question about the pk arguments.In my understanding, pk means the line of the table. If the developer create the model with the same pk, then the last one will be active and the old one will be covered. So, the developer will remember what's the current pk.
Currently, I use different global variables to save the pk for the different modules. It is not convenient and after program restart, the value will miss. So I will store it into redis later.
Do you have any idea about the correct way to pk ?
The following is the code.
`
devices_orm = DevicesModel(pk=1)
devices_orm_pk = 0
models_orm_pk = 0
def insert_redis(device):
global devices_orm
global devices_orm_pk
global models_orm_pk
devices_orm_pk = devices_orm_pk + 1
device_obj = DeviceModel(pk=devices_orm_pk)
device_obj.device_id = device["device_id"]
for model_object in device["models"]:
models_orm_pk = 1 + models_orm_pk
device_obj.models_list.lpush(
MachineLearningModel(pk=models_orm_pk, name=model_object["name"], version=model_object["version"],
status=model_object["status"]))
devices_orm.devices_list.lpush(device_obj)
`
for example
class SiteObject(models.Model):
name = models.CharHash()
site1 = SiteObject(pk="site_pk_1")
site2 = SiteObject(pk="site_pk_1")
site1.name="pig"
print(site1.name)
site1.name = "cat"
print(site1.name)
print(site2.name)
site2.name="dog"
print(site2.name)
print(site1.name)
pig
cat
cat
dog
cat
As shown above, when site1.name is called, the data in redis is retrieved and stored in the site1 self._astra_hash
object, so is site2, Therefore, the query of site1 will not be affected after the change of site2
Redis is so fast, I think the design might need to be rethought
I think this is a very good project and I hope more and more people will know about it.
How much work would it need to support 2.7?
Nice work @pilat !
Redis-astra will be shared in our next RedisWeekly tomorrow morning!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.