Skip to content

Instantly share code, notes, and snippets.

@braoru
Created April 6, 2016 12:21
Show Gist options
  • Save braoru/82099448b1ca2cc348fe2aea6a47a8f9 to your computer and use it in GitHub Desktop.
Save braoru/82099448b1ca2cc348fe2aea6a47a8f9 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2016:
# Sébastien Pasche, sebastien.pasche@leshop.ch
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
author = "Sebastien Pasche"
maintainer = "Sebastien Pasche"
version = "0.0.1"
from riak import RiakClient, RiakObject, BucketType, RiakBucket, datatypes, RiakNode
from pprint import pprint
import json
if __name__ == '__main__':
riak_nodes = [
'mtariaa01.leshop.local',
'mtariaa02.leshop.local',
'mtariaa03.leshop.local',
'mtariaa04.leshop.local',
'mtariaa05.leshop.local'
]
nodes = [
{'host': node} for node in riak_nodes
]
revers_index_name = 'keys'
riak_client = RiakClient(
nodes=nodes,
multiget_pool_size=(len(riak_nodes) + 1)
)
bucket_name='stock-monitoring'
bucket = riak_client.bucket(bucket_name)
sets_buckets = riak_client.bucket_type("sets")
identifier_set = sets_buckets.bucket(bucket_name).get(revers_index_name)
data = [
bucket.get(element).data for element in identifier_set
]
pprint("Data")
pprint("----")
print(
json.dumps(
data,
sort_keys=True,
indent=4,
separators=(',', ': ')
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment