Skip to content
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

Improved storage capabilities #60

Closed
wants to merge 2 commits into from
Closed

Improved storage capabilities #60

wants to merge 2 commits into from

Conversation

Kariton
Copy link
Contributor

@Kariton Kariton commented Jun 2, 2024

because the current implementation of storage.read() or storage.save() do not work well when they run simultaneously i moved the _redis from storage class to redis.
now the entire redis class is available within the storage class.
furthermore storage.delete() is now a thing.

i have a command that fetches content from a website. this takes time.
to make sure a user never receives the same post twice i used to:

  1. storage.read()
  2. do stuff
  3. storage_result.append(new_id)
  4. storage.save()

if the user runs the same command twice in a row it might happen that both coroutines read the same data and only the last one is actually saved.

now this is possible:

if c.bot.storage.redis is not None: # 'None' is default if storage is not redis
    c.bot.storage.redis.smembers(storage_key) # use redis.Redis().smembers() - list the set of stored data
    c.bot.storage.redis.sadd(storage_key, item["id"]) # use redis.Redis().sadd() - add item to the end of the existing data

ill close #35 in favor of this PR.
does not: fixes #29

typo: does not fix 29

@Kariton
Copy link
Contributor Author

Kariton commented Jun 2, 2024

i was ahead of my own commits... fixed

@Kariton Kariton closed this by deleting the head repository Jun 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use "phonenumbers" to Validate Phone Number
1 participant