Giter VIP home page Giter VIP logo

ooredis's Introduction

OOREDIS

OORedis 是一个 Redis 的 Python 库,它基于 redis-py ,具有以下三个主要功能:

  • 以 Key 对象为单位操作 Redis 的数据结构
  • 提供一组 Pythonic 的 API
  • 提供方便的类型转换机制

用例

>>> from ooredis import *
>>> connect()
>>>
>>> project = Dict('project-info')
>>> project['name'] = 'OORedis'
>>> project['description'] = 'A Python-to-Redis mapper'
>>> project['language'] = 'Python'
>>> project.items()
[('name', 'OORedis'),  ('description', 'A Python-to-Redis mapper'), ('language', 'Python')]
>>>
>>> book_list = Deque('my-book-list')
>>> book_list.append('SICP')
>>> book_list.append('The Joy of Clojure')
>>> book_list.append('Real World Haskell')
>>> list(book_list)
['SICP', 'The Joy of Clojure', 'Real World Haskell']
>>> book_list.pop()
'Real World Haskell'
>>>
>>> my_friend = Set('my-friend')
>>> my_friend.add('peter')
>>> my_friend.add('jack')
>>> my_friend.add('mary')
>>> your_friend = set(['peter', 'bob', 'yui'])
>>> my_friend ^ your_friend
set(['yui', 'bob', 'mary', 'jack'])
>>> my_friend & your_friend
set(['peter'])
>>> my_friend
Set Key 'my-friend': set(['peter', 'mary', 'jack'])
>>> my_friend &= your_friend
>>> my_friend
Set Key 'my-friend': set(['peter'])
>>>
>>> price = SortedSet('fruit-price')
>>> price['apple'] = 6.5
>>> price['banana'] = 3.2
>>> price['cherry'] = 4
>>> price
Sortedset Key 'fruit-price': [{'score': 3.2, 'value': 'banana'}, {'score': 4.0, 'value': 'cherry'}, {'score': 6.5, 'value': 'apple'}]
>>> for p in price:
...     print(p)
... 
{'score': 3.2, 'value': 'banana'}
{'score': 4.0, 'value': 'cherry'}
{'score': 6.5, 'value': 'apple'}
>>> for p in reversed(price):
...     print(p)
... 
{'score': 6.5, 'value': 'apple'}
{'score': 4.0, 'value': 'cherry'}
{'score': 3.2, 'value': 'banana'}

文档

更多代码示例和具体用法,请参考在线文档: http://ooredis.readthedocs.org/

测试

注意:测试将清空 Redis 的 0 号数据库,请谨慎操作。

$ git clone git://github.com/huangz1990/ooredis.git
Cloning into ooredis...
remote: Counting objects: 112, done.
remote: Compressing objects: 100% (81/81), done.
remote: Total 112 (delta 38), reused 102 (delta 28)
Receiving objects: 100% (112/112), 68.03 KiB | 44 KiB/s, done.
Resolving deltas: 100% (38/38), done.
$ cd ooredis/
$ nosetests
.................................................................................................................................................................................................................................................................................................................................
----------------------------------------------------------------------
Ran 321 tests in 5.803s

OK

已知问题

因为以下一些已知问题,本软件仍处于试验期当中,请不要在大数据量或者生产环境使用本软件:

  • 带有全局变量
  • 少数几个方法实现带有竞争条件
  • 有一些操作,比如 __iter__ ,需要一次性取出数据库中的所有元素,另外,有部分操作的实现效率并不是最优的。

以上问题将会在以后的版本中逐渐改进。

许可

本软件由 huangz 编写, 你可以在免费且自由的情况下,下载、使用、修改本软件,如果你需要其他许可, 请使用以下方式与我取得联系:

twitter: @huangz1990

gmail: huangz1990

豆瓣: www.douban.com/people/i_m_huangz

ooredis's People

Contributors

huangzworks avatar

Stargazers

kingfly avatar Breeze Chen avatar frankfanslc avatar Keany Vy KHUN avatar James Lau avatar ZX avatar Tomi lla avatar Tang Zheng'en avatar 丁剑 avatar Mithrandir avatar Robigus avatar Aaron avatar  avatar  avatar  avatar  avatar  avatar QuantumGhost avatar  avatar  avatar Million avatar Michael Zhuang avatar xiaochaihu avatar Jeff avatar Micky avatar  avatar  avatar  avatar  avatar  avatar Cai Zhijiang avatar Albert Cai avatar  avatar roger.luo avatar Xiaojie Fan avatar newliver avatar Jindong Zhang avatar Álvaro Justen avatar Chao Wang avatar  avatar  avatar  avatar Wrongway avatar Dee Cheung avatar Earthson Lu avatar error.d avatar ACCOUNT MOVED avatar Max avatar  avatar kun avatar Yang Li avatar tom.wen avatar  avatar Xiao Meng avatar Steve Zhi avatar Xiaoping Tang avatar  avatar Junliang Chen avatar hoterran avatar ben avatar David Gao avatar gradetwo avatar Zoom.Quiet avatar Sean Ren avatar

Watchers

Álvaro Justen avatar tony wang avatar  avatar James Cloos avatar 丁剑 avatar  avatar  avatar

ooredis's Issues

TypeCase处理中文出错

TypeCase类的unicode编码没有处理好,待修复。

>>> greet = SingleValue('greet')
>>> greet.set('你好')
Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "/usr/lib/python2.7/site-packages/ooredis/mix/string.py", line 48, in set
    value = self._type_case.to_redis(value)
    File "/usr/lib/python2.7/site-packages/ooredis/type_case.py", line 14, in to_redis
    value = unicode(value)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 0: ordinal not in range(128)
>>> greet.set(u'你好')
>>> greet.get()
Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "/usr/lib/python2.7/site-packages/ooredis/mix/string.py", line 69, in get
    return self._type_case.to_python(value)
    File "/usr/lib/python2.7/site-packages/ooredis/type_case.py", line 42, in to_python
        raise ValueError
ValueError

关于 OORedis 2.0 版本

随着 Redis 2.4 版本的功能基本稳定,我想现在开始对 OORedis 进行更新是一个不错的时机,因为打算修改的地方比较多,因此我将这个版本命名为 OORedis 2.0 。

OORedis 2.0 要做的事情有如下:

  • 补全 ABC mixin 中各个 special method 的文档,并生成 API 手册。
  • 编写一个 OORedis 的教程(tutorial)。
  • 利用 Redis 2.4 版本几个新命令的新特性(一次操作多个元素),提升诸如 Set 类的 &= 、 |= 、^= 等操作的速度
  • 对现有代码进行 formatting 工作
  • 移除 Server 模块:因为我觉得OORedis 应该专注于对数据结构进行操作上,Server、Connect等命令的实现交给 redis-py 去做
  • List 的实现和 API 都要进行大修改,SortedSet的实现估计也要进行更改
  • 丰富功能:补全之前一些因为比较复杂而没有实现的功能,比如 List 类的 del[start:end] 操作
  • 对测试进行重构,引入 nosetest

嗯,要做的大概就是这些,如果对以上计划有疑问或者对新版本有更好的建议,欢迎留言。

list的__getitem__中的bug

发现一个列表类中的BUG,记录。

>>> books
List Key 'book_list': [u'pro python', u'on lisp', u'design patterns']
>>> books[:]
[u'pro python', u'on lisp']

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.