redis支持的关系(如友谊)。
amico的Python项目详细描述
#阿米科
redis支持的关系(如友谊)。这是[amico gem](https://github.com/agoragames/amico)的一个端口。
##安装
pip安装amico
确保你的redis服务器正在运行!redis配置不在本自述文件的范围内,但是 查看[redis文档](http://redis.io/documentation)。
##用法
确保导入amico库:
`python from amico import Amico `
amico配置了许多默认值:
`python >>> Amico.DEFAULTS {'namespace': 'amico', 'pending_follow': False, 'reciprocated_key': 'reciprocated', 'followers_key': 'followers', 'pending_with_key': 'pending_with', 'following_key': 'following', 'page_size': 25, 'pending_key': 'pending', 'blocked_by_key': 'blocked_by', 'default_scope_key': 'default', 'blocked_key': 'blocked'} `
amico的初始值设定项有两个可选参数:
- 选项:更新默认值字典
- redis_连接:到redis的连接
`python >>> amico = Amico(redis_connection = redis) `
`python >>> amico.follow(1, 11) >>> amico.is_following(1, 11) True >>> amico.is_following(11, 1) False >>> amico.follow(11, 1) >>> amico.is_following(11, 1) True >>> amico.following_count(1) 1 >>> amico.followers_count(1) 1 >>> amico.unfollow(11, 1) >>> amico.following_count(11) 0 >>> amico.following_count(1) 1 >>> amico.is_follower(1, 11) False >>> amico.following(1) ['11'] >>> amico.block(1, 11) >>> amico.is_following(11, 1) False >>> amico.is_blocked(1, 11) True >>> amico.is_blocked_by(11, 1) True >>> amico.unblock(1, 11) >>> amico.is_blocked(1, 11) False >>> amico.is_blocked_by(11, 1) False >>> amico.follow(11, 1) >>> amico.follow(1, 11) >>> amico.is_reciprocated(1, 11) True >>> amico.reciprocated(1) ['11'] `
使用AMICO(以下为待定关系):
`python >>> amico = Amico(options = {'pending_follow': True}, redis_connection = redis) >>> amico.follow(1, 11) >>> amico.follow(11, 1) >>> amico.is_pending(1, 11) True >>> amico.is_pending_with(11, 1) True >>> amico.is_pending(11, 1) True >>> amico.is_pending_with(1, 11) True >>> amico.accept(1, 11) >>> amico.is_pending(1, 11) False >>> amico.is_pending_with(11, 1) False >>> amico.is_pending(11, 1) True >>> amico.is_pending_with(1, 11) True >>> amico.is_following(1, 11) True >>> amico.is_following(11, 1) False >>> amico.is_follower(11, 1) True >>> amico.is_follower(1, 11) False >>> amico.accept(11, 1) >>> amico.is_pending(1, 11) False >>> amico.is_pending_with(11, 1) False >>> amico.is_pending(11, 1) False >>> amico.is_pending_with(1, 11) False >>> amico.is_following(1, 11) True >>> amico.is_following(11, 1) True >>> amico.is_follower(11, 1) True >>> amico.is_follower(1, 11) True >>> amico.is_reciprocated(1, 11) True >>> amico.follow(1, 12) >>> amico.is_following(1, 12) False >>> amico.is_pending(1, 12) True >>> amico.deny(1, 12) >>> amico.is_following(1, 12) False >>> amico.is_pending(1, 12) False `
所有调用都支持一个scope参数,允许您对调用进行作用域,以表示不同类型的事物的关系。例如:
`python >>> amico = Amico(options = {'default_scope_key': 'user'}, redis_connection = redis) >>> amico.follow(1, 11) >>> amico.is_following(1, 11) True >>> amico.is_following(1, 11, scope = 'user') True >>> amico.following(1) ['11'] >>> amico.following(1, scope = 'user') ['11'] >>> amico.is_following(1, 11, scope = 'project') False >>> amico.follow(1, 11, scope = 'project') >>> amico.is_following(1, 11, scope = 'project') True >>> amico.following(1, scope = 'project') ['11'] `
您可以使用all(id,type,scope)调用检索所有特定类型的关系。例如:
`python >>> amico.follow(1, 11) >>> amico.follow(1, 12) >>> amico.all(1, 'following') ['12', '11'] `
类型可以是“following”、“followers”、“blocked”、“blocked”或“blocked”。请谨慎使用此命令,因为此调用可能返回大量项。
通过调用clear(id,scope),可以清除为id设置的所有关系。如果允许删除记录,并且希望防止孤立的ID和不准确的跟随者/后续计数,则可能希望执行此操作。注意,这将清除任何方向上的all关系,包括阻塞和挂起。例如:
`python >>> amico.follow(11, 1) >>> amico.block(12, 1) >>> amico.following(11) ['1'] >>> amico.blocked(12) ['1'] >>> amico.clear(1) >>> amico.following(11) [] >>> amico.blocked(12) [] `
##常见问题?
###为什么使用redis排序集而不是redis集?
根据我在开发[排行榜](https://github.com/agoragames/leaderboard)时所做的工作, 在redis支持的排行榜上,我知道我希望能够浏览各种关系。 考虑到redis集的当前命令集,这似乎是不可能的。
另外,通过在redis排序集中使用“score”,它基于 成立后,我们可以得到我们的“新朋友”。评分功能可能是 用户定义在将来允许一些特定的排序。
##对amico的贡献
- 请查看最新的主控形状,以确保功能尚未实现或错误尚未修复
- 查看问题跟踪程序,以确保已经有人没有请求和/或贡献它
- 分叉项目
- 启动功能/错误修复分支
- 承诺并推动,直到您对自己的贡献感到满意
- 确保为它添加测试。这很重要,所以我不会无意中在将来的版本中破坏它。
- 请尽量不要弄乱版本或历史记录。如果你想有自己的版本,或是其他必要的,那是好的,但请隔离到自己的承诺,这样我可以选择它周围。
##版权所有
版权所有(c)2013 David Czarnecki。有关详细信息,请参见license.txt。