import pickle data1 = {'firstname': [1, 2.0, 3, 4], 'lastname': ('maiden', u'Smith'), 'account': None} pickle.dump(data1, open('data.pkl', 'wb')) data2 = pickle.load(open('data.pkl', 'rb')) data1 == data2 class PicklePerson(object): def __init__(self, name, age, location): self.name = name self.age = age self.location = location def __repr__(self): return "name: " + self.name + "\n" + "age: " + self.age + \ "\n" + "location: " + self.location john = PicklePerson("John", "60", "Smith") print john pickle.dump(john, open("pickle_john", "wb")) zombie_john = pickle.load(open("pickle_john","r")) zombie_john import cPickle, os %timeit pickle.dump([data1 for x in xrange(1000)], open("pickle_john", "wb")) %timeit cPickle.dump([data1 for x in xrange(1000)], open("pickle_john", "wb")) os.path.getsize('/Users/antigen/Downloads/Pickle-and-Redis/pickle_john') import redis r = redis.StrictRedis(host='localhost', port=6379, db=0) r.set('foo', 'bar') r.get('foo') %timeit r.set('foo', 'bar') %timeit r.get('foo') import string text = """Pipelines are a subclass of the base Redis class that provide support for buffering multiple commands to the server in a single request. They can be used to dramatically increase the performance of groups of commands by reducing the number of back-and-forth TCP packets between the client and server.""" for word in text.split(): r.sadd("persistent", word) print [r.srandmember('persistent') for i in xrange(10)] print [r.srandmember('persistent') for i in xrange(10)] for word in text.split(): r.incr(word) for word in set(text.split()): if int(r.get(word)) > 2: print word print "\t\t", r.get(word) bob = pickle.dumps(PicklePerson("bob","50","smith")) print bob r.set("bob", bob) pickle.loads(r.get("bob")) import redisco from redisco import connection_setup, models redisco.connection_setup(host='localhost', port=6379, db=0) class Person(models.Model): name = models.Attribute(required=True) age = models.Attribute(required=False) location = models.Attribute(required=False) for x in Person.objects.filter(name="Tim"): x.delete() tim_smith = Person(name="Tim",age="40",location="Vancouver") tim_smiths = Person(name="Tim",age="70",location="Burnaby") tim_smiths.save() tim_smith.save() Person.objects.filter(name="Tim") Person.objects.filter(name="Tim", age="40")[0] == tim_smith