Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
|Python Versions| |License| |Build Status| |Coverage Status|
The Pythonic Redis Client
Why Redisworks?
Have you ever used PyRedis and wondered why you have to think about types all the time? That you have to constantly convert objects to strings and back and forth since Redis keeps most things as strings?
Redis works provides a Pythonic interface to Redis. Let Redisworks take care of type conversions for you.
Behind the scene, Redisworks uses
DotObject <https://github.com/seperman/dotobject>
__ to provide
beautiful dot notation objects and lazy Redis queries.
pip install redisworks
Note that RedisWorks needs Redis server 2.4+.
let’s say if you want all the keys in Redis to start with the word
root
. Then you:
.. code:: py
root = Root() # connects to Redis on local host by default
Or if you want to be more specific:
.. code:: py
root = Root(host='localhost', port=6379, db=0)
Any other parameter that you pass to Root will be passed down to PyRedis. For example:
.. code:: py
root = Root(host='localhost', port=6379, db=0, password='mypass')
Saving to Redis is as simple as assigning objects to attributes of root or attributes of attributes of root (you can go as deep as you want.) Make sure you are not using any Python’s reserved words in the key’s name.
Example:
.. code:: py
from redisworks import Root import datetime root = Root() root.my.list = [1, 3, 4] root.my.other.list = [1, [2, 2]]
some_date = datetime.datetime(2016, 8, 22, 10, 3, 19) root.time = some_date
root.the.mapping.example = {1:1, "a": {"b": 10}}
Redis works will automatically convert your object to the proper Redis type and immediately write it to Redis as soon as you assign an element!
The respective keys for the above items will be just like what you type:
root.my.list
, root.time
, root.the.mapping.example
:
If you use redis-cli, you will notice that the data is saved in the proper Redis data type:
::
127.0.0.1:6379> scan 0
Reading the data is as simple as if it was just saved in Python memory!
Redis works returns Lazy queries just like how Django returns lazy queries. In fact the lazy objects code is borrowed from Django!
If you ran the example from Saving to Redis <#saving-to-redis>
__, run
a flush root.flush()
to empty Redisworks Cache. This is so it goes
and gets the objects from Redis instead of reading its own current copy
of data:
.. code:: py
from redisworks import Root root = Root() thetime = root.time thelist = root.my.list mydict = root.the.mapping.example mydict # is not evalurated yet!
print(mydict)
{1:1, "a": {"b": 10}} # Now all the 3 objects are read from Redis!
mydict {1:1, "a": {"b": 10}} root.my.list [1, 3, 4] root.my.other.list [1, [2, 2]] root.time 2016-08-22 10:03:19
Every key name by default starts with the word root
. If you want to
use another name, you have two options:
Option 1, pass a namespace:
.. code:: py
mynamespace = Root(conn=redis_conn, namespace='mynamespace') mynamespace.foo = 'bar'
Option 2, simply subclass Root
:
.. code:: py
from redisworks import Root class Post(Root): ... pass post=Post() post.item1 = "something" # saves to Redis ... print(post.item1) # loads from Redis something
Let’s say you want root.1
as a key name. Python does not allow
attribute names start with numbers.
All you need to do is start the number with the character i
so
Redisworks takes care of it for you:
.. code:: py
root.i1 = 10 print(root.i1) 10
The actual key in Redis will be root.1
.. code:: py
path1 = 'blah' path2 = 'blah.here`'
root[path1] = 'foo' root[path2] = 'foo bar'
root.blah foo root.blah.here foo bar
You can use the with_ttl
helper.
.. code:: py
from redisworks import Root, with_ttl self.root.myset = with_ttl([1, 2, 3], ttl=1) self.root.flush() self.root.myset [1, 2, 3] time.sleep(1.2) self.root.flush() self.root.myset
Take a look at example.py <example.py>
__
Seperman (Sep Dehpour)
Github <https://github.com/seperman>
__Linkedin <http://www.linkedin.com/in/sepehr>
__ZepWorks <https://zepworks.com>
__.. |Python Versions| image:: https://img.shields.io/pypi/pyversions/redisworks.svg?style=flat .. |License| image:: https://img.shields.io/pypi/l/redisworks.svg?version=latest .. |Build Status| image:: https://travis-ci.org/seperman/redisworks.svg?branch=master :target: https://travis-ci.org/seperman/redisworks .. |Coverage Status| image:: https://coveralls.io/repos/github/seperman/redisworks/badge.svg?branch=master :target: https://coveralls.io/github/seperman/redisworks?branch=master
FAQs
Pythonic Redis Client.
We found that redisworks demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.