Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

connect to redis servers through unix sockets

  • Loading branch information...
commit ed1160da5a711d9995d83607d55eb891c73d2b86 1 parent 74bef1c
@piquadrat piquadrat authored
View
31 src/redisboard/migrations/0003_auto__chg_field_redisserver_port.py
@@ -0,0 +1,31 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+
+ # Changing field 'RedisServer.port'
+ db.alter_column('redisboard_redisserver', 'port', self.gf('django.db.models.fields.IntegerField')(null=True))
+
+
+ def backwards(self, orm):
+
+ # Changing field 'RedisServer.port'
+ db.alter_column('redisboard_redisserver', 'port', self.gf('django.db.models.fields.IntegerField')())
+
+
+ models = {
+ 'redisboard.redisserver': {
+ 'Meta': {'unique_together': "(('hostname', 'port'),)", 'object_name': 'RedisServer'},
+ 'hostname': ('django.db.models.fields.CharField', [], {'max_length': '250'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '250', 'null': 'True', 'blank': 'True'}),
+ 'port': ('django.db.models.fields.IntegerField', [], {'default': '6379', 'null': 'True', 'blank': 'True'})
+ }
+ }
+
+ complete_apps = ['redisboard']
View
24 src/redisboard/models.py
@@ -6,6 +6,7 @@
from django.utils.translation import ugettext_lazy as _
from django.db import models
from django.core.validators import MaxValueValidator, MinValueValidator
+from django.core.exceptions import ValidationError
from django.conf import settings
from .utils import cached_property
@@ -41,20 +42,31 @@ class Meta:
("can_inspect", "Can inspect redis servers"),
)
- hostname = models.CharField(_("Hostname"), max_length=250)
+ hostname = models.CharField(_("Hostname"), max_length=250, help_text=_('this can also be the absolute path to a redis socket'))
port = models.IntegerField(_("Port"), validators=[
MaxValueValidator(65535), MinValueValidator(1)
- ], default=6379)
+ ], default=6379, blank=True, null=True)
password = models.CharField(_("Password"), max_length=250,
null=True, blank=True)
+ def clean(self):
+ if not self.hostname.startswith('/') and not self.port:
+ raise ValidationError(_('Please provide either a hostname AND a port or the path to a redis socket'))
+
@cached_property
def connection(self):
+ if self.hostname.startswith('/'):
+ unix_socket_path = self.hostname
+ hostname = None
+ else:
+ hostname = self.hostname
+ unix_socket_path = None
return redis.Redis(
- host = self.hostname,
+ host = hostname,
port = self.port,
- password = self.password
+ password = self.password,
+ unix_socket_path=unix_socket_path,
)
@connection.deleter
@@ -98,4 +110,6 @@ def stats(self):
def __unicode__(self):
- return "%s:%s" % (self.hostname, self.port)
+ if self.port:
+ return "%s:%s" % (self.hostname, self.port)
+ return self.hostname
Please sign in to comment.
Something went wrong with that request. Please try again.