from glim.core import Facade
from glim.component import Extension
from glim.facades import Log

import redis

class GredisExtension(Extension):

	def __init__(self, config):
		self.config = config
		self.active = 'default'
		self.connections = {}

		for k, config in self.config.items():
			self.connections[k] = self.connect(config)

	def __getattr__(self, attr):
		try:
			return getattr(self.connections[self.active], attr)
		except redis.RedisError, e:
			Log.error(e)
			return None

	def connection(self, key = None):
		if key:
			self.active = key
		else:
			self.active = 'default'
		return self

	def connect(self, config):
		try:
			connection = redis.StrictRedis(
				host = config['host'],
				port = config['port'],
				db = config['db'])

			connection.ping()
			return connection

		except redis.RedisError, e:
			Log.error(e)
			return None

class Redis(Facade):
	accessor = GredisExtension
@@ -36,16 +36,10 @@
 lim.
-componen
+ex
 t im
@@ -66,16 +66,8 @@
 glim
-.facades
  imp
@@ -869,24 +869,25 @@
 cessor = GredisExtension
+%0A

add changes for newest releases of glim