Пример #1
0
        public InstanceInfo CreateInstance(string instanceId)
        {
            // Look for existing instance
            InstanceInfo info;
            if (this._database.TryGetValue(instanceId, out info))
            {
                return info;
            }

            // Create a new instance
            info = new InstanceInfo();
            info.instanceId = instanceId;

            // Get unique port
            info.port = (ushort)Interlocked.Increment(ref _lastPort);

            // Create a unique password
            info.password = "******";

            // Create process
            var details = new RedisStartDetails
            {
                Port = info.port,
            };
            info.processId = this._processManager.Spawn(details).ProcessId;

            // Create connectionString
            info.connectionString = string.Format("redis://{0}:{1}@{2}:{3}/", info.instanceId, info.password, "hashtagredis.cloudapp.net", info.port);

            // Return instance
            this._database.TryAdd(instanceId, info); // false means it already existed; should be impossible
            return info;
        }
        public RedisProcessInfo Spawn(RedisStartDetails details)
        {
            StringBuilder arguments = new StringBuilder();
            arguments.Append(String.IsNullOrWhiteSpace(details.ConfigurationFilePath) ? String.Empty : details.ConfigurationFilePath);
            if (details.Port > 0)
            {
                arguments.AppendFormat(" --port {0}", details.Port);
            }

            arguments.AppendFormat(" --requirepass {0}", "redpolo");

            Process process = new Process();
            process.StartInfo = new ProcessStartInfo(ExecutablePath, arguments.ToString());

            process.Start();
            return new RedisProcessInfo()
            {
                ProcessId = process.Id,
            };
        }