PHP Classes

File: test/python/nosql/redis.py

Recommend this page to a friend!
  Classes of Nikos M.   Dialect PHP ORM and ODM Library   test/python/nosql/redis.py   Download  
File: test/python/nosql/redis.py
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: Dialect PHP ORM and ODM Library
Store and retrieve objects in database using ORM
Author: By
Last change:
Date: 3 years ago
Size: 1,533 bytes
 

Contents

Class file image Download
def getStorage(DialectNoSql): import json import redis class RedisStorage(DialectNoSql.INoSql): def __init__(self, opts=dict()): options = { 'host': '127.0.0.1', 'port': 6379, 'namespace': '' } options.update(opts) self.client = redis.Redis(host=options['host'], port=options['port']) self.keyPrefix = str(options['namespace']) def vendor(self): return 'redis' def supportsPartialUpdates(self): return False def supportsConditionalQueries(self): return False def insert(self, collection, key, data): self.client.set(self.getKeyName(collection, key), json.dumps(data)) return 1 def update(self, collection, key, data): return self.insert(collection, key, data) def delete(self, collection, key): self.client.unlink(self.getKeyName(collection, key)) return 1 def find(self, collection, key): data = self.client.get(self.getKeyName(collection, key)) return None if not data else json.loads(data.decode('utf-8')) def findAll(self, collection, conditions): return None def getKeyName(self, collection, key = None): return self.keyPrefix + str(collection) + ':' + ('' if not key else (':'.join(map(str, key.values())) if isinstance(key, dict) else str(key))) return RedisStorage