def save(self): data = {'uuid': self.uuid} for attr_name in self.stored_attrs: data[attr_name] = self.value_of(attr_name) ActiveRedis.connexion().hmset(self.redis_namespace_with_uuid(data['uuid']), data) return data['uuid']
def all_redis_keys(cls): return ActiveRedis.connexion().keys('{}:*'.format(cls.redis_namespace()))
def delete_all(cls): for key in cls.all_redis_keys(): ActiveRedis.connexion().delete(key) return True
def delete(self): return ActiveRedis.connexion().delete( self.redis_namespace_with_uuid(self.uuid))
def update_attr(self, attr_name, value): return ActiveRedis.connexion().hset( self.redis_namespace_with_uuid(self.uuid), attr_name, value)
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) # This is a basic data type example. from active_redis import DataType, registry @registry.datatype class Queue(DataType): # The type string is used to allow the data type to be constructed # directly from the ActiveRedis class and helps unserialize the # data type when stored in Redis. type = 'queue' def push(self, item): """Push an item onto the queue.""" self.client.rpush(self.key, item) def delete(self): """Delete the queue.""" self.client.delete(self.key) def __repr__(self): pass # Now we can use our data type. from active_redis import ActiveRedis redis = ActiveRedis() myqueue = redis.queue() myqueue.push('foo') myqueue.push('bar')
def find_by_redis_key(cls, redis_key): return cls(**ActiveRedis.connexion().hgetall(redis_key))
# Copyright (c) 2013 Jordan Halterman <*****@*****.**> # See LICENSE for details. import sys, os sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) from active_redis import ActiveRedis redis = ActiveRedis() # Create an unnamed dictionary. mydict = redis.dict() # Add items to the dictionary. mydict['foo'] = '1' mydict['bar'] = '2' # Note that when adding a complex data structure the structure # will be serialized to JSON when written to Redis. However, the # structure will still be monitored for changes, so even once a # list is serialized it can still be mutated, and Active Redis # will capture changes and re-serialize the dictionary. mydict['baz'] = ['foo', 'bar'] mydict['baz'].append('baz') mydict.delete() # We can also create a named dict by passing a key to the constructor. mydict = redis.dict('mydict') mydict['foo'] = 'bar' del mydict mydict = redis.dict('mydict') print mydict # {'foo': u'bar'}
# Copyright (c) 2013 Jordan Halterman <*****@*****.**> # See LICENSE for details. import sys, os sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) from active_redis import ActiveRedis redis = ActiveRedis() # Create an unnamed set. myset = redis.set() # Add items to the set. myset.add('foo') myset.add('bar') # We can also create a named set by passing a key to the constructor. myset = redis.set('myset') myset.add('foo') del myset myset = redis.set('myset') print myset # set([u'foo']) myset.delete() print myset # set()
# Copyright (c) 2013 Jordan Halterman <*****@*****.**> # See LICENSE for details. import sys, os sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) from active_redis import ActiveRedis redis = ActiveRedis() # Create an unnamed list. mylist = redis.list() # Append items to the list. mylist.append('foo') mylist.append('bar') # Note that when appending a complex data structure the structure # will be serialized to JSON when written to Redis. However, the # structure will still be monitored for changes, so even once a # list is serialized it can still be mutated, and Active Redis # will capture changes and re-serialize the list. mylist.append(['foo', 'bar']) mylist[2].append('baz') mylist.delete() # We can also create a named list by passing a key to the constructor. mylist = redis.list('mylist') mylist.append('foo') del mylist mylist = redis.list('mylist') print mylist # [u'foo']
# Copyright (c) 2013 Jordan Halterman <*****@*****.**> # See LICENSE for details. import sys, os sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) from active_redis import ActiveRedis redis = ActiveRedis() # Create an unnamed set. myset = redis.set() # Add items to the set. myset.add("foo") myset.add("bar") # We can also create a named set by passing a key to the constructor. myset = redis.set("myset") myset.add("foo") del myset myset = redis.set("myset") print myset # set([u'foo']) myset.delete() print myset # set()