Comments (3)
not found for a few seconds.
So it shows up, just slowly?
Can you tell me a bit about how you're deploying Redis? And what the model definition / secondary indexes are doing?
from walrus.
@coleifer I have a class called "Presence" that needs to be queried and changed in a matter of seconds.
I noticed 2 "big" problems:
-
When I am changing the status of a record (type of negotiating conversation to initiating conversation), I have a loop in a worker that checks if the two users are still active and if it is not, it interrupts the connection. It turns out that at the time of changing the status does not return the object in the worker's query and he understands that the person "died". But this takes 1 or 2 seconds, so it affects 2 or 3 calls every 10 attempts.
-
Another problem is that there is a type of a cache in the information. I change the status and then I search the old status and continue bringing the modified object. A few seconds later the searches work correctly.
I made the comment in 2 steps, in the code itself.
class Presence(walrus.Model):
__database__ = redis_db
channel_name = walrus.TextField(primary_key=True)
user = walrus.UUIDField(index=True, default='00000000-0000-0000-0000-000000000000')
last_seen = walrus.DateTimeField(default=datetime.datetime.now, index=True)
is_accessible = walrus.IntegerField(index=True, default=0)
connection_user = walrus.UUIDField(index=True, default='00000000-0000-0000-0000-000000000000')
connection_state = walrus.IntegerField(default=4, index=True)
connection_update = walrus.DateTimeField(default=datetime.datetime.now, index=True)
def seeking_connection(presence):
try:
query = (Presence.is_accessible == 1) \
& (Presence.connection_state == 4) \
& (Presence.user != presence.user)
presences = Presence.query(query)
user_selected = random.choice(list(presences))
###See that the query has exactly the IF below, it was necessary to make an IF to reinforce the query because it is up to the query to deliver old data.
if user_selected.is_accessible != 1 or user_selected.connection_state != 4:
print("Query did not work")
return
except Exception:
return
presence.is_accessible = 1
presence.connection_state = 1
presence.connection_user = user_selected.user
presence.save()
user_selected.connection_state = 1
user_selected.connection_user = presence.user
user_selected.save()
###Second step I just did to validate, also returns old values.
##From the query I made until I got here, those variables should be right. But the error of not finding the object is intermittent (it's type 2 or 3 times for every 10 queries)
try:
Presence.get((Presence.user == presence.connection_user)
& (Presence.connection_state != 4)
& (Presence.is_accessible == 1))
except Exception as exeption:
raise NotFound
from walrus.
I'm not positive what could be causing you to receive inconsistent results. Since Redis server is single-threaded I would have assumed that your operations would proceed synchronously, i.e., if you call save() the redis client will block until it's finished all operations...and save() can incur quite a few operations. Are you deploying Redis in some kind of multi-server/replicated environment? Is the Redis client returning from executing commands before they've actually been processed?
from walrus.
Related Issues (20)
- cache.cached doesn't work if the function returns None HOT 1
- "lock.event:" pollution HOT 4
- [feature]Any plan for supporting model relationship mapping? HOT 1
- Consumer group pending exception HOT 1
- VSCode type checking can't identify RedisPy's Redis as parent HOT 2
- Database() is falsy when database is empty HOT 2
- Empty queries in graph HOT 1
- A problem with query in graph.py HOT 1
- Lock event keys never expire HOT 1
- There is a problem. HOT 3
- Walrus Support for Redis Python Client 4.x+ HOT 2
- Is Expiring Hashes supported in Walrus? HOT 3
- Missing argument in method calling
- Support from_url database connection HOT 2
- Extending Containers with custom behavior HOT 1
- Not compatible with Redis Python Client 5.0.0 HOT 5
- examples in docs use Python 2 syntax
- Handling json HOT 3
- regex error HOT 1
- regex syntax warning
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 walrus.