Giter Club home page Giter Club logo

redislite's Introduction

redislite

https://travis-ci.org/yahoo/redislite.svg?branch=master Documentation Status

Description

Self contained Python interface to the Redis key-value store.

It makes it possible to use redis without the need to install and configure a redis server.

Installation

To install redislite, simply:

$ pip install redislite

or using easy_install:

$ easy_install redislite

or from source:

$ python setup.py install

Getting Started

>>> import redislite
>>> r = redis.StrictRedis()
>>> r.set('foo', 'bar')
True
>>> r.get('foo')
'bar'

Usage

redislite provides enhanced versions of the redis.Redis() and redis.StrictRedis() classes that take the same arguments as the corresponding redis classes and take one additional optional argument. Which is the name of the redis rdb file to use. If the argument is not provided it will create a new one.

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.

Example

Here we open a Python shell and set a key in our embedded redis db

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

Here we open the same redis db and access the key we created during the last run

>>> from redislite import Redis
>>> redis_connection = Redis('/tmp/redis.db')
>>> redis_connection.keys()
['key']
>>> redis_connection.get('key')
'value'

It's also 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.

>>> import redislite.patch
>>> redislite.patch.patch_redis()
>>> import redis_collections
>>> td = redis_collections.Dict()
>>> td['foo']='bar'
>>> td.keys()
['foo']

Or the Walrus module

>>> from redislite.patch import patch_redis
>>> patch_redis('/tmp/walrus.db')
>>> from walrus import *
>>> db = Database()
>>> huey = db.Hash('huey')
>>> huey.update(color='white', temperament='ornery', type='kitty')
<Hash "huey": {'color': 'white', 'type': 'kitty', 'temperament': 'ornery'}>
>>> huey.keys()
['color', 'type', 'temperament']
>>> 'color' in huey
True
>>> huey['color']
'white'

More Information

There is more detailed information on the redislite documentation page at http://redislite.readthedocs.org/en/latest/

redislite's People

Contributors

dwighthubbard avatar geonu avatar yashbathia avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.