• Stars
    star
    171
  • Rank 222,266 (Top 5 %)
  • Language
    Python
  • Created over 11 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A redis sharding library/api for your sharding needs.

redis-router

redis_router, a redis sharding library/api for your redis sharding needs.

how it works

wikipedia/consistent_hashing

Consistent hashing is a special kind of hashing. When a hash table is resized and consistent hashing is used, only K/n keys need to be remapped on average, where K is the number of keys, and n is the number of slots. In contrast, in most traditional hash tables, a change in the number of array slots causes nearly all keys to be remapped.

redis_router uses last.fm's libketama in the back.

installation

install libketama/ketama_python first.

After that;

pip install redis-router

or if you like 90s:

easy_install redis-router

or add redis_router directory to the your path.

quick start

servers.txt (server:ip weight)

127.0.0.1:6379 100
127.0.0.1:6380 100

your python code:

router = Router("servers.txt")

router.set("forge", 13)
router.set("spawning_pool", 18)

output with loglevel=DEBUG

DEBUG:key 'forge' hashed as 4113771093 and mapped to 127.0.0.1:6379
DEBUG:key 'spawning_pool' hashed as 1434709819 and mapped to 127.0.0.1:6380
DEBUG:key 'forge' hashed as 4113771093 and mapped to 127.0.0.1:6379
DEBUG:key 'spawning_pool' hashed as 1434709819 and mapped to 127.0.0.1:6380
13 6

redis_router as a server

If you have clients using X programming language other than python, you can use HTTP or TCP interface to connect and send commands to redis_router.

running TCP interface

from redis_router.tcp_interface import RouterServer

r = RouterServer('0.0.0.0', 5000)
r.run()

playing with it

$ telnet localhost 5000
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
set selam timu
True
get selam
timu
dbsize
13

HTTP API

from redis_router.http_interface import start_server

start_server('0.0.0.0', 5000)

example request:

  • initialize a set with two members.
$ curl -X POST --data "command=sadd&arguments=teams,galatasaray,fenerbahce" http://localhost:5000 
{
  "response": 2
}
  • get members
$ curl -X POST --data "command=smembers&arguments=teams" http://localhost:5000
{
  "response": [
    "fenerbahce", 
    "galatasaray"
  ]
}

running tests

$ py.test tests.py 
=============================================== test session starts =========================
platform linux2 -- Python 2.7.3 -- pytest-2.3.4
collected 11 items 

tests.py ...........

============================================ 11 passed in 0.33 seconds ======================

FAQ

Q: What about data invalidation if I move servers, change the config etc.

It's minimum. At least better than:

Node = Hash(key) MOD N

Q: I want to see some stats about sharding efficiency.

Results for 100.000 random keys.

results: {
    redis.client.Redis object at 0x8df75a4: 33558,
    redis.client.Redis object at 0x8df7644: 31207,
    redis.client.Redis object at 0x8df7504: 35235
}

Q: Can I use this with PHP or [INSERT RANDOM LANGUAGE HERE]

Yes.

There are TCP server and HTTP Server options. You can always use libketama's implementations in your language though.

Bitdeli Badge

More Repositories

1

storm

Manage your SSH like a boss.
Python
3,935
star
2

kaptan

configuration manager in your pocket.
Python
308
star
3

django-stackoverflow-trace

Django error page w/ a stackoverflow search link.
Python
235
star
4

macster

You're in a starbucks thinking about to build the next killer-app with node.js and mongodb but you don't have a mac?
Python
127
star
5

unicode_tr

a python module to make unicode strings work as expected for turkish chars. solves the turkish "İ" problem.
Python
84
star
6

relationships

redis backed user relationships on its simplest form.
Python
76
star
7

fb.py

facebook development kit for Django
Python
52
star
8

storm-indicator

SSH shortcut menu for ubuntu. (NO LONGER MAINTAINED.)
Python
52
star
9

PharmacyOnDuty

Pharmacy *on duty* api for Istanbul.
Python
46
star
10

lurker

a tiny wrapper for mySQLDB
Python
39
star
11

lama

a linux/mac app to take screenshots and upload to imgur.
Python
33
star
12

spire

REST interface for mongodb
PHP
32
star
13

storm-gui

cross platform wxpython interface to stormssh.
Python
31
star
14

swarm-host

Realtime redis dashboard for your redis setup.
JavaScript
31
star
15

etym

Online Etymologic Dictionary [in Turkish] Source
CSS
27
star
16

golist

python's list type implementation on go.
Go
26
star
17

lightsteem

A light python client to interact with the STEEM blockchain
Python
24
star
18

dpoll.xyz

Decentralized poll app on the top HIVE blockchain
Python
22
star
19

nutella.py

nutella price ticker on your command line.
Python
21
star
20

btcturk-client

btcturk.com api client
Python
17
star
21

lighthive

A light python client to interact with the HIVEblockchain
Python
17
star
22

conqueue

conqueue is a queue manager library built on the top of redis.
Python
14
star
23

tagbot

A bot rewards specific tags on HiVE blockchain
Python
14
star
24

steemconnect-python-client

Python client of SteemConnect
Python
10
star
25

digitalocean_to_sshconfig

all your droplets belong to your ssh config™
Python
10
star
26

tower

A REST api implementation on the top of Hivemind
Python
9
star
27

steemrocks

Activity feed for steem accounts
Python
8
star
28

curobot

Your personal curation bot on the steem network™
Python
8
star
29

safran

safran.io reader - on your command line.
Python
7
star
30

infestor

Claim and create discounted STEEM accounts on your command line
Python
7
star
31

heisenberg

Python
6
star
32

hived-rpc-scanner

A CLI tool to check the status of RPC nodes
Python
6
star
33

lkd-courses

LKD bunyesinde gerceklestirilen kurslar icin yonetim yazilimi. https://uye.lkd.org.tr/trac/ticket/1830
Python
6
star
34

hotdog

A custom json indexer and api for STEEM blockchain
Python
6
star
35

btcturk-ticker

bitcoin price ticker for your command line.
Python
5
star
36

gora

command line seslisozluk client
5
star
37

imagehoster-python-client

A Python Client of Steemit's image hosting service
Python
5
star
38

magicdice

A Python library and set of tools to play and analyze STEEM based magic dice game.
Python
5
star
39

byteball-rpc-client

A Python JSON-RPC client for the headless wallet
Python
4
star
40

transmitter

Witness updates made easy. ™
Python
4
star
41

mike

Somebody attacks your stash on drugwars? Better call Mike!
Python
4
star
42

steeminator

Personal webapp to manage actions on STEEM blockchain
Python
3
star
43

turbot

Experimental upvote bot for steem blockchain
Python
3
star
44

utopy

Utopian curation bot
Python
3
star
45

dcom

An upvote bot (STEEM) for discord communities
Python
3
star
46

semaphores

Semaphore puzzles and solutions.
Python
3
star
47

randowhale_bot

The bot runs @randowhale on STEEM network
Python
3
star
48

hivedrpcstatus

2
star
49

github-pages-with-jekyll

2
star
50

beem_tutorials

Beem Tutorials
Python
2
star
51

steemprice

Steem price ticker API
Python
2
star
52

zato-connection-registry

Load/Backup/Restore your Zato connections
Python
2
star
53

anonramblings

Say whatever you want, anonymously on the Hive blockchain.
JavaScript
2
star
54

muteproxy

Python
2
star
55

jumphash

Jump Hash consistent hashing library
2
star
56

steem-username-autocomplete-api

A simple HTTP api for steem usernames for auto-complete frontends
Python
2
star
57

example

HTML
1
star
58

usta

personal file server for your sharing needs.
Python
1
star
59

utopian-api-python-client

Python client of public Utopian api
1
star
60

unit-test-workshop

Unit test workshop
Python
1
star
61

deutschbot

Deutschbot
Python
1
star
62

emre.github.io

Personal blog
1
star
63

hived-rpc-status

HTML
1
star
64

thanks

A "thanks" bot for STEEM witnesses to thank their voters after their vote
Python
1
star
65

notes

Personal but public
1
star
66

reward_estimator

Reward estimator for steem posts
Python
1
star
67

rabona-scripts

Various scripts to automate actions on Rabona
Python
1
star
68

communitybot

Steem bot for communities
Python
1
star
69

quaresma

Automate Rabona actions
Python
1
star
70

utopian-post-notifier

A discord bot notifies about Utopian posts.
1
star
71

instasteem

A CLI tool and Python library to sync your instagram posts with your STEEM profile
Python
1
star
72

halisaha_bot

1
star
73

async-lighthive

A light *async* python client to interact with the HIVE blockchain
1
star
74

steem-watchdog

Automates claiming process of author/curation rewards
Python
1
star
75

steemit-view-api

A simple HTTP api responds with Steemit view counts.
Python
1
star
76

hivesigner-python-client

Python client for Hivesigner
Python
1
star
77

hivue

Get your witness vote notifications in your smart lightbulbs!
1
star
78

steem-osx-statusbar

A simple statusbar for STEEM
Python
1
star
79

exchange_rates

Exchange Rate Service
Go
1
star
80

hiveon

https://hiveon.net/ python client
1
star