Skip to content

Commit

Permalink
Merge bbfcdbe into 7a4b92a
Browse files Browse the repository at this point in the history
  • Loading branch information
dwighthubbard committed May 24, 2019
2 parents 7a4b92a + bbfcdbe commit 1e87d2d
Show file tree
Hide file tree
Showing 7 changed files with 202 additions and 199 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ sudo: false
python: 2.7
env:
- TOX_ENV=py27
- TOX_ENV=py34
- TOX_ENV=py35
- TOX_ENV=py36
- TOX_ENV=pypy
notifications:
irc: "chat.freenode.net#redislite"
Expand Down
255 changes: 107 additions & 148 deletions README.rst → README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,14 @@
Redislite
*********
# Redislite

.. image:: https://img.shields.io/travis/yahoo/redislite.svg
:target: https://travis-ci.org/yahoo/redislite

.. image:: https://img.shields.io/coveralls/yahoo/redislite.svg
:target: https://coveralls.io/r/yahoo/redislite

.. image:: https://img.shields.io/pypi/v/redislite.svg
:target: https://pypi.python.org/pypi/redislite/

.. image:: https://img.shields.io/badge/python-2.7,3.4,pypy-blue.svg
:target: https://pypi.python.org/pypi/redislite/

.. image:: https://img.shields.io/pypi/l/redislite.svg
:target: https://pypi.python.org/pypi/redislite/

.. image:: https://readthedocs.org/projects/redislite/badge/?version=latest
:target: http://redislite.readthedocs.org/en/latest/
:alt: Documentation Status
[![Build Status](https://cd.screwdriver.cd/pipelines/2880/badge)](https://cd.screwdriver.cd/pipelines/2880)
[![Coverage](https://img.shields.io/coveralls/yahoo/redislite.svg)](https://coveralls.io/r/yahoo/redislite)
[![Current Version](https://img.shields.io/pypi/v/redislite.svg)](https://pypi.python.org/pypi/redislite/)
[![Supported Python Versions](https://img.shields.io/badge/python-2.7,3.5,3.6,3.7,3.8,pypy-blue.svg)](https://pypi.python.org/pypi/redislite/)
[![License](https://img.shields.io/pypi/l/redislite.svg)](https://pypi.python.org/pypi/redislite/)
[![Documentation](https://readthedocs.org/projects/redislite/badge/?version=latest)](http://redislite.readthedocs.org/en/latest/)

.. image:: https://img.shields.io/badge/IRC-redislite-blue.svg
:target: http://webchat.freenode.net/?channels=%23redislite&uio=d4
:alt: IRC

.. image:: https://img.shields.io/badge/Group-pythonredislite-blue.svg
:target: https://groups.yahoo.com/neo/groups/pythonredislite/info
:alt: Yahoo Group pythonredislite



Description
===========
## Description

Redislite is a self contained Python interface to the Redis key-value store.

Expand All @@ -42,72 +19,61 @@ It provides enhanced versions of the Redis-Py Python bindings for Redis. That p
* **Compatible** - It provides enhanced versions of the Redis-Py python Redis bindings as well as functions to patch them to allow most existing code that uses them to run with little or no modifications.
* **Secure** - It uses a secure default Redis configuraton that is only accessible by the creating user on the computer system it is run on.

Requirements
------------
## Requirements

The redislite module requires Python 2.7 or higher.


Installing on Linux
~~~~~~~~~~~~~~~~~~~
### Installing requirements on Linux

Make sure Python development headers are available when installing redislite.

On Ubuntu/Debian systems, install them with:

.. code-block::
apt-get install python-dev
`apt-get install python-dev`

On Redhat/Fedora systems, install them with:

.. code-block::
`yum install python-devel`

yum install python-devel
Installing on Mac OSX
~~~~~~~~~~~~~~~~~~~~~
### Installing requirements on Mac OSX

Redislite for OSX comes as a wheel package by default that can be installed
using current versions of pip.

To install Redislite on MacOSX using the sdist package instead you will need
the XCode command line utilities installed. If you do not have xcode
installed on recent OSX releases they can be installed by
running::
running:

xcode-select --install
`xcode-select --install`

Installing on Microsoft Windows
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
### Installing requirements on Microsoft Windows

Redislite can be installed on newer releases of Windows 10 under the Bash on Ubuntu shell.

Install it using the instructions at https://msdn.microsoft.com/commandline/wsl/install_guide

Then start the bash shell and install the python-dev package as follows::
Then start the bash shell and install the python-dev package as follows:

apt-get install python-dev
`apt-get install python-dev`

Installation
============
## Installation

To install redislite, simply:

.. code-block::
$ pip install redislite
```console
$ pip install redislite
```

or from source:

.. code-block::
```console
$ python setup.py install
```

$ python setup.py install

Getting Started
===============
## Getting Started

redislite provides enhanced versions of the redis-py redis.Redis() and
redis.StrictRedis() classes that take the same arguments as the corresponding
Expand All @@ -119,125 +85,118 @@ redislite also provides functions to MonkeyPatch the redis.Redis and
redis.StrictRedis classes to use redislite, so existing python code that uses
Redis can use the redislite version.

Examples
========
## Examples

Here are some examples of using the redislite module.

Setting a value
---------------
### Setting a value

Here we open a Python shell and set a key in our embedded Redis db. Redislite will automatically start the Redis server when
the Redis() object is created and shut it down cleanly when the Python interpreter exits.

.. code-block:: python
```python
>>> from redislite import Redis
>>> redis_connection = Redis('/tmp/redis.db')
>>> redis_connection.keys()
[]
>>> redis_connection.set('key', 'value')
True
>>> redis_connection.get('key')
'value'
```

>>> from redislite import Redis
>>> redis_connection = Redis('/tmp/redis.db')
>>> redis_connection.keys()
[]
>>> redis_connection.set('key', 'value')
True
>>> redis_connection.get('key')
'value'
>>> quit()
### Persistence

Persistence
-----------
Now we open the same Redis db and access the key we created during the last run. Redislite will automatically start the
Redis server using the same configuration as last time, so the value that was set in the previous example is still available.

.. code-block:: python
>>> from redislite import Redis
>>> redis_connection = Redis('/tmp/redis.db')
>>> redis_connection.keys()
['key']
>>> redis_connection.get('key')
'value'
>>> quit()
```python
>>> from redislite import Redis
>>> redis_connection = Redis('/tmp/redis.db')
>>> redis_connection.keys()
['key']
>>> redis_connection.get('key')
'value'
```

Compatibility
-------------
## Compatibility

It's possible to MonkeyPatch the normal Redis classes to allow modules
that use Redis to use the redislite classes. Here we patch Redis and use the
redis_collections module.

.. code-block:: python
```python
>>> import redislite.patch
>>> redislite.patch.patch_redis()
>>> import redis_collections
>>> td = redis_collections.Dict()
>>> td['foo']='bar'
>>> td.keys()
['foo']
```

>>> import redislite.patch
>>> redislite.patch.patch_redis()
>>> import redis_collections
>>> td = redis_collections.Dict()
>>> td['foo']='bar'
>>> td.keys()
['foo']
Running and using Multiple servers
----------------------------------
## Running and using Multiple servers

Redislite will start a new server if the redis rdb fileame isn't specified or is new. In this example we start 10 seperate redis servers and set the value of the key 'servernumber' to a different value in each server.

Then we access the value of 'servernumber' and print it.

>>> import redislite
>>> servers = {}
>>> for redis_server_number in range(10):
... servers[redis_server_number] = redislite.Redis()
... servers[redis_server_number].set('servernumber', redis_server_number)
...
True
True
True
True
True
True
True
True
True
True
>>> for redis_server in servers.values():
... redis_server.get('servernumber')
...
b'0'
b'1'
b'2'
b'3'
b'4'
b'5'
b'6'
b'7'
b'8'
b'9'

Multiple Servers with different configurations in the same script
-----------------------------------------------------------------
```python
>>> import redislite
>>> servers = {}
>>> for redis_server_number in range(10):
... servers[redis_server_number] = redislite.Redis()
... servers[redis_server_number].set('servernumber', redis_server_number)
...
True
True
True
True
True
True
True
True
True
True
>>> for redis_server in servers.values():
... redis_server.get('servernumber')
...
b'0'
b'1'
b'2'
b'3'
b'4'
b'5'
b'6'
b'7'
b'8'
b'9'
```

## Multiple Servers with different configurations in the same script

It's possible to spin up multiple instances with different
configuration settings for the Redis server. Here is an example that sets up 2
redis server instances. One instance is configured to listen on port 8002, the
second instance is a read-only slave of the first instance.


.. code-block:: python
>>> import redislite
>>> master=redislite.Redis(serverconfig={'port': '8002'})
>>> slave=redislite.Redis(serverconfig={'slaveof': "127.0.0.1 8002"})
>>> slave.keys()
[]
>>> master.set('key', 'value')
True
>>> master.keys()
['key']
>>> slave.keys()
['key']
>>>
More Information
================
```python
>>> import redislite
>>> master=redislite.Redis(serverconfig={'port': '8002'})
>>> slave=redislite.Redis(serverconfig={'slaveof': "127.0.0.1 8002"})
>>> slave.keys()
[]
>>> master.set('key', 'value')
True
>>> master.keys()
['key']
>>> slave.keys()
['key']
>>>
```

## More Information

There is more detailed information on the redislite documentation page at
http://redislite.readthedocs.org/en/latest/
Expand Down
2 changes: 1 addition & 1 deletion redislite/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
'list-max-ziplist-entries': '512',
'list-max-ziplist-value': '64',
'loglevel': 'notice',
'logfile' : 'redis.log',
'logfile': 'redis.log',
'lua-time-limit': '5000',
'pidfile': '/var/run/redislite/redis.pid',
'port': '0',
Expand Down
30 changes: 30 additions & 0 deletions screwdriver.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version: 4
shared:
environment:
PACKAGE_DIRECTORY: redislite

jobs:
validate_test:
template: python/validate_unittest
steps:
- preend: coveralls
requires: [~commit, ~pr]

validate_lint:
template: python/validate_lint
requires: [~commit, ~pr]

validate_codestyle:
template: python/validate_codestyle
requires: [~commit, ~pr]

generate_version:
template: python/generate_version
requires: [~commit]

publish_test_pypi:
template: python/package_python
environment:
PUBLISH: True
TWINE_REPOSITORY_URL: https://test.pypi.org/legacy/
requires: [validate_test, validate_lint, validate_codestyle, generate_version]

0 comments on commit 1e87d2d

Please sign in to comment.