Skip to content

Instantly share code, notes, and snippets.

@jonaslindmark
Last active December 15, 2015 18:09
Show Gist options
  • Save jonaslindmark/5301814 to your computer and use it in GitHub Desktop.
Save jonaslindmark/5301814 to your computer and use it in GitHub Desktop.
from time import time
from twisted.web import client, error as web_error
from twisted.python import failure
from cStringIO import StringIO
import gzip
port = 8098
def uncompress(compressed_data):
sio = StringIO(compressed_data)
with gzip.GzipFile(fileobj=sio, mode='rb') as zf:
data = zf.read()
return data
def get(host, bucket, key, timeout=0.5):
start = time()
def handle_result(result):
end = time()
print "Riak result in: %s ms", (end-start)
return uncompress(result)
def build_url(host):
return str(url)
def on_404(failure):
if failure.check(web_error.Error) and failure.value.status == 404:
return None
return failure
url = 'http://%s:%s/riak/%s/%s' % (host, port, bucket, key)
d = client.getPage(url , timeout=timeout)
d.addCallbacks(handle_result, on_404)
return d
if __name__ == "__main__":
from twisted.internet import reactor
host = 'riak-02.production.wrops.net'
def got_result(r):
print "got result", r[:20]
reactor.stop()
d = get(host, 'friendships','7587')
d.addCallback(got_result)
reactor.run()
@eskilandreen
Copy link

build_url doesn't seem to be used

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment