Skip to content

Instantly share code, notes, and snippets.

@bbertka
Created December 10, 2015 18:29
Show Gist options
  • Save bbertka/b99047d061d14c51401c to your computer and use it in GitHub Desktop.
Save bbertka/b99047d061d14c51401c to your computer and use it in GitHub Desktop.
Python Redis List for Pivotal Cloud Foundry
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