Created
December 10, 2015 18:29
-
-
Save bbertka/b99047d061d14c51401c to your computer and use it in GitHub Desktop.
Python Redis List for Pivotal Cloud Foundry
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json, os | |
import redis | |
from redis_collections import List | |
MAX = 50 | |
# Authenticate and create redis object (assuming PCF service) | |
creds = json.loads(os.environ['VCAP_SERVICES'])['p-redis'][0]['credentials'] | |
r = redis.StrictRedis(host=creds['host'], port=creds['port'], password=creds['password'], db=0) | |
# Instantiate a List object with key name 'mydata' | |
l = List(redis=r, key='mydata') | |
# Ensure only 20 latest of MAX items exist | |
for x in range(0, MAX): | |
l.append( str(x) ) | |
if len(l) > 20: | |
l.pop(0) | |
# Read 20 item stack-list into array | |
results = [item for item in l] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment