Esempio n. 1
0
 public void TestAuth()
 {
     using (var redis = new RedisClient(Host, Port, 0))
     {
         Assert.AreEqual("OK", redis.Auth(Password));
     }
 }
Esempio n. 2
0
        private void Initialize()
        {
            try
            {
                // create the connection
                Client = new RedisClient(_config.Host, _config.Port)
                {
                    ReconnectAttempts = 3,
                    ReconnectTimeout = 200
                };

                // select the database
                Client.Select(_config.DatabaseId);

                // authenticate if needed.
                if (!string.IsNullOrEmpty(_config.Password))
                    Client.Auth(_config.Password);

                // check the version
                var version = GetVersion();
                if (version < _requiredMinimumVersion)
                    throw new Exception(string.Format("You are using redis version {0}, minimum required version is 2.6", version));

                _logger.Information("Redis storage initialized: {0:l}:{1}, v{2:l}.", _config.Host, _config.Port, version);
            }
            catch (Exception e)
            {
                _logger.Error("Redis storage initialization failed: {0:l}:{1} - {2:l}", _config.Host, _config.Port, e.Message);
            }
        }
 public void TestAuth()
 {
     using (var redis = new RedisClient(Host, Port, 0))
     {
         Assert.AreEqual("OK", redis.Auth(Password));
     }
 }
Esempio n. 4
0
        static void KeysTest(RedisClient redisClient)
        {
            var a = redisClient.Auth("yswenli");

            var info = redisClient.Info();

            var serverInfo = redisClient.ServerInfo;

            redisClient.Select(1);

            var dbsize = redisClient.DBSize();

            redisClient.SlaveOf();

            var pong = redisClient.Ping();

            var clist = redisClient.ClientList();

            var ck = "slowlog-max-len";

            var cr1 = redisClient.SetConfig(ck, 1000);

            var cr2 = redisClient.GetConfig(ck);

            var isCluster = redisClient.IsCluster;
        }
Esempio n. 5
0
        private void Initialize()
        {
            try
            {
                // create the connection
                _client = new RedisClient(_redisConfig.Host, _redisConfig.Port)
                {
                    ReconnectAttempts = 3,
                    ReconnectTimeout  = 200
                };

                // select the database
                _client.Select(_redisConfig.DatabaseId);

                // authenticate if needed.
                if (!string.IsNullOrEmpty(_redisConfig.Password))
                {
                    _client.Auth(_redisConfig.Password);
                }

                // check the version
                var version = GetVersion();
                if (version < _requiredMinimumVersion)
                {
                    throw new Exception(string.Format("You are using redis version {0}, minimum required version is 2.6", version));
                }

                _logger.Information("Storage initialized: {0:l}:{1}, v{2:l}.", _redisConfig.Host, _redisConfig.Port, version);
            }
            catch (Exception e)
            {
                _logger.Error("Storage initialization failed: {0:l}:{1} - {2:l}", _redisConfig.Host, _redisConfig.Port, e.Message);
            }
        }
Esempio n. 6
0
        static void KeysTest(RedisClient redisClient)
        {
            var a = redisClient.Auth("yswenli");

            var info = redisClient.Info();

            var serverInfo = redisClient.ServerInfo;

            redisClient.Select(1);

            var dbsize = redisClient.DBSize();

            redisClient.SlaveOf();

            var pong = redisClient.Ping();

            var clist = redisClient.ClientList();

            var ck = "slowlog-max-len";

            var cr1 = redisClient.SetConfig(ck, 1000);

            var cr2 = redisClient.GetConfig(ck);

            var t1 = redisClient.GetDataBase().Ttl("zaaa");
            var t2 = redisClient.GetDataBase().Ttl("haa22");
            var t3 = redisClient.GetDataBase().Pttl("key0");
            var t4 = redisClient.GetDataBase().Pttl("akey0");

            var isCluster = redisClient.IsCluster;
        }
Esempio n. 7
0
 public T Get <T>(string key)
 {
     using (var redis = new RedisClient(redisHost, redisPort))
     {
         redis.Connected += (s, e) => redis.Auth(redisPassword); // set AUTH, CLIENT NAME, etc
         return(redis.Get(key).StringToObj <T>());
     }
 }
Esempio n. 8
0
 public bool Exist(string key)
 {
     using (var redis = new RedisClient(redisHost, redisPort))
     {
         redis.Connected += (s, e) => redis.Auth(redisPassword); // set AUTH, CLIENT NAME, etc
         return(redis.Exists(key));
     }
 }
Esempio n. 9
0
 public void Set(string key, string value)
 {
     using (var redis = new RedisClient(redisHost, redisPort))
     {
         redis.Connected += (s, e) => redis.Auth(redisPassword); // set AUTH, CLIENT NAME, etc
         redis.Set(key, value);
     }
 }
Esempio n. 10
0
 public void Set <T>(string key, T value, TimeSpan span)
 {
     using (var redis = new RedisClient(redisHost, redisPort))
     {
         redis.Connected += (s, e) => redis.Auth(redisPassword); // set AUTH, CLIENT NAME, etc
         redis.Set(key, value.ObjToString(), span);
     }
 }
Esempio n. 11
0
        public DbCon()
        {
            redis = new RedisClient("localhost");
            redis.Auth("password");

            mClient = new MongoClient(MONGO_CONNECT_STRING);
            mServer = mClient.GetServer();
            mDB     = mServer.GetDatabase("db1");
        }
Esempio n. 12
0
        static void Main(string[] args)
        {
            ConsoleHelper.Title = "SAEA.RedisSocketTest";
            ConsoleHelper.WriteLine("输入ip:port连接RedisServer");

            var ipPort = ConsoleHelper.ReadLine();

            if (string.IsNullOrEmpty(ipPort))
            {
                ipPort = "127.0.0.1:6379";
            }
            RedisClient redisClient = new RedisClient(ipPort);

            redisClient.Connect();
            //redisClient.Connect("wenli");


            var info = redisClient.Info();

            if (info.Contains("NOAUTH Authentication required."))
            {
                while (true)
                {
                    ConsoleHelper.WriteLine("请输入redis连接密码");
                    var auth = ConsoleHelper.ReadLine();
                    if (string.IsNullOrEmpty(auth))
                    {
                        auth = "yswenli";
                    }
                    var a = redisClient.Auth(auth);
                    if (a.Contains("OK"))
                    {
                        break;
                    }
                    else
                    {
                        ConsoleHelper.WriteLine(a);
                    }
                }
            }

            //redisConnection.SlaveOf();

            //redisConnection.Ping();

            redisClient.Select(1);

            //ConsoleHelper.WriteLine(redisConnection.Type("key0"));

            ConsoleHelper.WriteLine("dbSize:{0}", redisClient.DBSize().ToString());


            RedisOperationTest(redisClient, true);
            ConsoleHelper.ReadLine();
        }
Esempio n. 13
0
        /// <summary>
        /// Get a synchronous RedisClient for blocking calls (e.g. BLPop, Subscriptions, Transactions, etc)
        /// </summary>
        /// <returns>RedisClient to be used in single thread context</returns>
        public RedisClient Clone()
        {
            ActivityTracer.Verbose("Cloning client");
            RedisClient client = new RedisClient(Host, Port, 0);

            if (_password != null)
            {
                client.Auth(_password);
            }
            return(client);
        }
Esempio n. 14
0
        private void Monitoring()
        {
            string authRtn = _redisClient.Auth(_instance.Password);

            _redisClient.MonitorReceived += _redisClient_MonitorReceived;
            string rtn = _redisClient.Monitor();

            if (rtn.Equals("OK"))
            {
            }
        }
Esempio n. 15
0
        /// <summary>
        /// 基础数据库连接
        /// </summary>
        /// <param name="mdb">mongo数据库</param>
        /// <param name="mcom">mongo连接地址</param>
        /// <param name="rhost">redis连接地址</param>
        /// <param name="rpw">redis连接密码</param>
        public DbConBase(String mdb, String mcom, String rhost, String rpw)
        {
            rcon = new RedisClient(rhost);
            rcon.Auth(rpw);
            var mClient = new MongoClient(mcom);
            var mServer = mClient.GetServer();

            mcon = mServer.GetDatabase(mdb);
            DbBasic.createTestHT(rcon);
            DbBasic.createRwHt(mcon);
        }
Esempio n. 16
0
        public RedisClient GetRedisClient()
        {
            RedisClient redisClient = new RedisClient(this.IPEndPoint);

            if (redisClient.Connect(1000))
            {
                redisClient.Auth(Password);
            }

            return(redisClient);
        }
Esempio n. 17
0
        /// <summary>
        /// 客户端缓存操作对象
        /// </summary>
        public static RedisClient GetClient()
        {
            var p        = "";
            var endPoint = _redisConfig.AnsyzeHost(ref p);
            var client   = new RedisClient(endPoint);

            if (!string.IsNullOrWhiteSpace(p))
            {
                client.Auth(_pwd);
            }
            return(client);
        }
Esempio n. 18
0
        public void AuthTest()
        {
            using (var mock = new MockConnector("MockHost", 9999, "+OK\r\n", "+OK\r\n"))
                using (var redis = new RedisClient(mock))
                {
                    Assert.AreEqual("OK", redis.Auth("my password"));
                    Assert.AreEqual("*2\r\n$4\r\nAUTH\r\n$11\r\nmy password\r\n", mock.GetMessage());

                    Assert.AreEqual("OK", redis.AuthAsync("my password").Result);
                    Assert.AreEqual("*2\r\n$4\r\nAUTH\r\n$11\r\nmy password\r\n", mock.GetMessage());
                }
        }
Esempio n. 19
0
        /// <summary>
        /// 客户端缓存操作对象
        /// </summary>
        public static RedisClient GetClient()
        {
            var p = "";
            // var endPoint = _redisConfig.AnsyzeHost(ref p);
            var client = new RedisClient(_host, _port);

            if (!string.IsNullOrWhiteSpace(_pwd))
            {
                client.Auth(_pwd);
                //client.Select(1);
            }
            return(client);
        }
Esempio n. 20
0
        public void TestPSubscribe()
        {
            int    change_count  = 0;
            int    message_count = 0;
            string last_message  = String.Empty;

            using (var redisConsumer = new RedisClient(Host, Port, 0))
                using (var redisPublisher = new RedisClient(Host, Port, 0))
                {
                    redisConsumer.Auth(Password);
                    redisPublisher.Auth(Password);

                    redisConsumer.SubscriptionReceived += (o, e) =>
                    {
                        message_count++;
                        last_message = e.Message.Body;
                    };
                    redisConsumer.SubscriptionChanged += (o, e) =>
                    {
                        change_count++;
                    };
                    Task consumer_task = Task.Factory.StartNew(() =>
                    {
                        redisConsumer.PSubscribe("t*");
                    });
                    while (change_count != 1) // wait for psubscribe
                    {
                        Thread.Sleep(10);
                    }

                    Assert.AreEqual(1, redisPublisher.Publish("test", "hello world"), "First publish");
                    Assert.AreEqual(0, redisPublisher.Publish("junk", "nothing"), "Junk publish");
                    Assert.AreEqual(1, redisPublisher.Publish("test2", "hello again"), "Second publish");
                    redisConsumer.PSubscribe("c*");
                    while (change_count != 2) // wait for psubscribe
                    {
                        Thread.Sleep(10);
                    }
                    Assert.AreEqual(1, redisPublisher.Publish("channel1", "something new"), "New channel publish");

                    redisConsumer.PUnsubscribe("t*");
                    redisConsumer.PUnsubscribe();
                    consumer_task.Wait();

                    Assert.AreEqual(3, message_count);
                    Assert.AreEqual(4, change_count);
                    Assert.AreEqual("something new", last_message);
                }
        }
Esempio n. 21
0
 public static bool RedisConnect(string ip, int port, string password)
 {
     try
     {
         Redis = new RedisClient(ip, port);
         Redis.Auth(password);
         Connected = Redis.Connect(100);
         return(Connected);
     }
     catch (Exception ex)
     {
         ErrorMessage = ex.Message;
         return(false);
     }
 }
 public void TestUnwatch()
 {
     using (new RedisTestKeys(Redis, "test1"))
     {
         Redis.Watch("test1");
         Assert.AreEqual("OK", Redis.Unwatch());
         Redis.Multi();
         using (var otherClient = new RedisClient(Host, Port, 0))
         {
             otherClient.Auth(Password);
             otherClient.Set("test1", "other");
         }
         Redis.Set("test1", "multi");
         Assert.IsNotNull(Redis.Exec());
     }
 }
Esempio n. 23
0
 public void TestUnwatch()
 {
     using (new RedisTestKeys(Redis, "test1"))
     {
         Redis.Watch("test1");
         Assert.AreEqual("OK", Redis.Unwatch());
         Redis.Multi();
         using (var otherClient = new RedisClient(Host, Port, 0))
         {
             otherClient.Auth(Password);
             otherClient.Set("test1", "other");
         }
         Redis.Set("test1", "multi");
         Assert.IsNotNull(Redis.Exec());
     }
 }
Esempio n. 24
0
        public void TestSubscribe()
        {
            int change_count = 0;
            int message_count = 0;
            string last_message = String.Empty;

            using (var redisConsumer = new RedisClient(Host, Port, 0))
            using (var redisPublisher = new RedisClient(Host, Port, 0))
            {
                redisConsumer.Auth(Password);
                redisPublisher.Auth(Password);

                redisConsumer.SubscriptionReceived += (o, e) =>
                {
                    message_count++;
                    last_message = e.Message.Body;
                };
                redisConsumer.SubscriptionChanged += (o, e) =>
                {
                    change_count++;
                };
                Task consumer_task = Task.Factory.StartNew(() =>
                {
                    redisConsumer.Subscribe("test");
                });
                while (change_count != 1) // wait for subscribe
                    Thread.Sleep(10);

                Assert.AreEqual(1, redisPublisher.Publish("test", "hello world"), "First publish");
                Assert.AreEqual(0, redisPublisher.Publish("junk", "nothing"), "Junk publish");
                Assert.AreEqual(1, redisPublisher.Publish("test", "hello again"), "Second publish");
                redisConsumer.Subscribe("test2");
                while (change_count != 2) // wait for subscribe
                    Thread.Sleep(10);
                Assert.AreEqual(1, redisPublisher.Publish("test2", "a new channel"), "New channel publish");

                redisConsumer.Unsubscribe("test");
                redisConsumer.Unsubscribe();
                consumer_task.Wait();

                Assert.AreEqual(3, message_count);
                Assert.AreEqual(4, change_count);
                Assert.AreEqual("a new channel", last_message);
            }
        }
Esempio n. 25
0
        public void Initialize()
        {
            Host = ConfigurationManager.AppSettings["host"];
            Port = Int32.Parse(ConfigurationManager.AppSettings["port"]);
            Password = ConfigurationManager.AppSettings["password"];

            _redis = new Lazy<RedisClient>(() =>
            {
                RedisClient redis = new RedisClient(Host, Port, 0);
                redis.Auth(Password);
                return redis;
            });

            _async = new Lazy<RedisClientAsync>(() =>
            {
                RedisClientAsync async = new RedisClientAsync(Host, Port, 0);
                async.Auth(Password).Wait();
                return async;
            });
        }
Esempio n. 26
0
        public void Initialize()
        {
            Host     = ConfigurationManager.AppSettings["host"];
            Port     = Int32.Parse(ConfigurationManager.AppSettings["port"]);
            Password = ConfigurationManager.AppSettings["password"];

            _redis = new Lazy <RedisClient>(() =>
            {
                RedisClient redis = new RedisClient(Host, Port, 0);
                redis.Auth(Password);
                return(redis);
            });

            _async = new Lazy <RedisClientAsync>(() =>
            {
                RedisClientAsync async = new RedisClientAsync(Host, Port, 0);
                async.Auth(Password).Wait();
                return(async);
            });
        }
Esempio n. 27
0
 public string Auth(string password)
 {
     return(_client.Auth(password));
 }
Esempio n. 28
0
        void TestRedis()
        {
            var redisOp = RedisOption.BuildRedisOption(ConnectString);

            AppendLine(tb_Output, $"Current RedisOption is {redisOp}");
            var  client = new RedisClient(redisOp);
            bool flag   = client.IsConnected;

            AppendLine(tb_Output, $"Current RedisClient is IsConnected {flag},If False While Try Auth With Password({redisOp.Password})");

            if (!flag && !string.IsNullOrEmpty(redisOp.Password))
            {
                try
                {
                    var authRet = client.Auth(redisOp.Password);
                    AppendLine(tb_Output, $"client.Auth({redisOp.Password})->{authRet} [Success]");
                    flag = true;
                }
                catch (Exception ex)
                {
                    AppendLine(tb_Output, $"client.Auth({redisOp.Password})-> [Failed] Handler Error {ex.Message}\r\n{ex}");
                    flag = false;
                }
            }

            if (!flag)
            {
                return;
            }

            if (redisOp.DefaultDb > 0)
            {
                try
                {
                    var selectRet = client.Select(redisOp.DefaultDb);
                    AppendLine(tb_Output, $"client.Select(db:{redisOp.DefaultDb})->{selectRet} [Success]");
                    flag = true;
                }
                catch (Exception ex)
                {
                    AppendLine(tb_Output, $"client.Select(db:{redisOp.DefaultDb}) [Failed] Handler Error {ex.Message}\r\n{ex}");
                    flag = false;
                }
            }
            if (!flag)
            {
                return;
            }
            try
            {
                var clientListRet = client.ClientList().Replace("\n", "\r\n");
                AppendLine(tb_Output, $"client.ClientList()->\r\n{clientListRet}  ");
            }
            catch (Exception ex)
            {
                AppendLine(tb_Output, $"client.ClientList() [Failed] Handler Error {ex.Message}\r\n{ex}");
            }
            try
            {
                var clientInfoRet = client.Info();
                AppendLine(tb_Output, $"client.Info()->\r\n{clientInfoRet}");
            }
            catch (Exception ex)
            {
                AppendLine(tb_Output, $"client.Info() [Failed] Handler Error {ex.Message}\r\n{ex}");
            }

            try
            {
                var quitRet = client.Quit();
                AppendLine(tb_Output, $"{ConnectString} Close Success ->{quitRet}");
                flag = true;
            }
            catch (Exception ex)
            {
                AppendLine(tb_Output, $"{ConnectString} Close Handler Error {ex.Message}\r\n{ex}");
                flag = false;
            }
        }
Esempio n. 29
0
        static void Main(string[] args)
        {
            ConsoleHelper.Title = "SAEA.RedisSocketTest";
            ConsoleHelper.WriteLine("输入连接字符串连接RedisServer,格式为\r\nserver=127.0.0.1:6379;passwords=yswenli");

            var cnnStr = ConsoleHelper.ReadLine();

            if (string.IsNullOrEmpty(cnnStr))
            {
                //cnnStr = "server=127.0.0.1:6379;passwords=yswenli";
                cnnStr = "server=127.0.0.1:6379;passwords=yswenli";
            }
            RedisClient redisClient = new RedisClient(cnnStr, false);

            redisClient.Connect();

            redisClient.Select(1);

            var list = redisClient.GetDataBase().LRang("list1", 0, 10);

            //redisClient.GetDataBase().HSet("test", "", "2151");


            //var isCluster = redisClient.IsCluster;

            //var list = redisClient.ClusterNodes;

            var keys = redisClient.GetDataBase().Keys();

            var scan  = redisClient.GetDataBase().Scan();
            var hscan = redisClient.GetDataBase().HScan("haa22", 0);
            var sscan = redisClient.GetDataBase().SScan("aaa", 0);

            redisClient.GetDataBase().ZAdd("zaaa", "!#@%$^&*\r\n()^^%%&%@FSDH\r\n某月霜\r\n/.';lakdsfakdsf", 110);
            var zscan = redisClient.GetDataBase().ZScan("zaaa", 0);

            //var r = redisClient.GetDataBase().Rename("aaa", "aaa");

            //var l = redisClient.GetDataBase().LRang("testlist");

            //var z = redisClient.GetDataBase().ZRang("zaaa");

            var h = redisClient.GetDataBase().HGetAll("haa22");

            var t1 = redisClient.GetDataBase().Ttl("zaaa");
            var t2 = redisClient.GetDataBase().Ttl("haa22");
            var t3 = redisClient.GetDataBase().Pttl("key0");
            var t4 = redisClient.GetDataBase().Pttl("akey0");

            //var m = redisClient.ClusterInfo;
            //var n = redisClient.ClusterNodes;
            //var k = redisClient.KeySlot("aaa");
            //var g = redisClient.GetKeysInSlot(0);

            //redisClient.GetDataBase().SRemove("abcd", "12345");

            var info = redisClient.Info();

            var serverInfo = redisClient.ServerInfo;

            var r = redisClient.Console("scan 0");

            if (info.Contains("NOAUTH Authentication required."))
            {
                while (true)
                {
                    ConsoleHelper.WriteLine("请输入redis连接密码");
                    var auth = ConsoleHelper.ReadLine();
                    if (string.IsNullOrEmpty(auth))
                    {
                        auth = "yswenli";
                    }
                    var a = redisClient.Auth(auth);
                    if (a.Contains("OK"))
                    {
                        break;
                    }
                    else
                    {
                        ConsoleHelper.WriteLine(a);
                    }
                }
            }

            //redisClient.SlaveOf();

            var pong = redisClient.Ping();

            //redisClient.Select(1);

            PerformanceTest(redisClient);

            ConsoleHelper.WriteLine(redisClient.Type("key0"));

            ConsoleHelper.WriteLine("dbSize:{0}", redisClient.DBSize().ToString());

            RedisOperationTest(redisClient, true);
            ConsoleHelper.ReadLine();
        }
Esempio n. 30
0
        static void Main(string[] args)
        {
            ConsoleHelper.Title = "SAEA.RedisSocketTest";
            ConsoleHelper.WriteLine("输入连接字符串连接RedisServer,格式为server=127.0.0.1:6379;password=yswenli");

            var cnnStr = ConsoleHelper.ReadLine();

            if (string.IsNullOrEmpty(cnnStr))
            {
                cnnStr = "server=172.31.32.85:6379;password=yswenli";
            }
            RedisClient redisClient = new RedisClient(cnnStr);

            redisClient.Connect();

            //var s= redisClient.Select(159);
            //s= redisClient.Select(160);

            //var z = redisClient.Type("zaaa");

            //var scan = redisClient.GetDataBase().Scan();
            //var hscan = redisClient.GetDataBase().HScan("haa2", 0);
            //var sscan = redisClient.GetDataBase().SScan("aaa", 0);
            //var zscan = redisClient.GetDataBase().ZScan("zaaa", 0);

            var r = redisClient.GetDataBase().Rename("aaa", "aaa");


            var info = redisClient.Info();

            if (info.Contains("NOAUTH Authentication required."))
            {
                while (true)
                {
                    ConsoleHelper.WriteLine("请输入redis连接密码");
                    var auth = ConsoleHelper.ReadLine();
                    if (string.IsNullOrEmpty(auth))
                    {
                        auth = "yswenli";
                    }
                    var a = redisClient.Auth(auth);
                    if (a.Contains("OK"))
                    {
                        break;
                    }
                    else
                    {
                        ConsoleHelper.WriteLine(a);
                    }
                }
            }

            //redisConnection.SlaveOf();

            //redisConnection.Ping();

            redisClient.Select(1);

            //ConsoleHelper.WriteLine(redisConnection.Type("key0"));

            ConsoleHelper.WriteLine("dbSize:{0}", redisClient.DBSize().ToString());


            RedisOperationTest(redisClient, true);
            ConsoleHelper.ReadLine();
        }
Esempio n. 31
0
        static void Main(string[] args)
        {
            if (AppDomain.CurrentDomain.IsDefaultAppDomain())
            {
                // RazorEngine cannot clean up from the default appdomain...
                Console.WriteLine("Switching to secound AppDomain, for RazorEngine...");
                AppDomainSetup adSetup = new AppDomainSetup();
                adSetup.ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
                var current = AppDomain.CurrentDomain;
                // You only need to add strongnames when your appdomain is not a full trust environment.
                var strongNames = new StrongName[0];

                var domain = AppDomain.CreateDomain(
                    "MyMainDomain", null,
                    current.SetupInformation, new PermissionSet(PermissionState.Unrestricted),
                    strongNames);
                var exitCode = domain.ExecuteAssembly(Assembly.GetExecutingAssembly().Location);
                // RazorEngine will cleanup.
                AppDomain.Unload(domain);
                return;
            }

            RedisClient rc = new RedisClient(ConfigurationManager.AppSettings.Get("redishost"));

            rc.Connect(1000);


            if (ConfigurationManager.AppSettings.Get("password") != "")
            {
                rc.Auth(ConfigurationManager.AppSettings.Get("password"));
            }



            //读取出所有信息

            List <Message> unSendMessage = new List <Message>();
            //for (var i = 0; i < unSendCount; i++) {
            //    unSendMessage.Add(rc.LPop(""));
            //}
            string item;

            while ((item = rc.LPop("message")) != null)
            {
                unSendMessage.Add(new Message(item));
            }
            if (unSendMessage.Count == 0)
            {
                Console.WriteLine($"没有待发送消息");
                return;
            }

            Console.WriteLine($"有{unSendMessage.Count}个待发送消息");

            //string[] unSendMessage = rc.LRange("message", 0, unSendCount);
            SendMail("检测报告", unSendMessage);

            //rc.LRem("message", 0, unSendCount);

            //rc.a("message");


            Console.WriteLine($"{unSendMessage.Count}个消息 发送完成");
        }
 private LoginClientMgr_Redis()
 {
     dbcon = new RedisClient(DB_ADDR);
     dbcon.Auth(DB_PASSWORD);
 }
Esempio n. 33
0
        /// <summary>
        /// ID
        /// 想要运行的文件全路径
        /// 想要运行的文件参数
        /// 日志路径
        /// 日志格式
        /// </summary>
        /// <param name="args"></param>
        public static void Main(string[] args)
        {
            rc = new RedisClient(ConfigurationManager.AppSettings.Get("redishost"));

            try
            {
                rc.Connect(1000);

                IsDebug = Boolean.Parse(ConfigurationManager.AppSettings.Get("debug"));

                if (ConfigurationManager.AppSettings.Get("password") != "")
                {
                    rc.Auth(ConfigurationManager.AppSettings.Get("password"));
                }
                if (IsDebug)
                {
                    rc.LPush("debug", args);
                    debugprefix = "debug_";
                }

                runUid   = args[0];
                filepath = args[1];
                runargs  = args[2];
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();

                rc.HSet(debugprefix + "status_" + runUid, "startTime", DateTime.Now);
                rc.HIncrBy(debugprefix + "status_" + runUid, "errorcount", 1);
                rc.HIncrBy(debugprefix + "status_" + runUid, "runcount", 1);

                rc.HSet(debugprefix + "status_" + runUid, "updateTime", DateTime.Now);


                Process proc = new Process();
                proc.StartInfo.FileName               = "cmd.exe";
                proc.StartInfo.WorkingDirectory       = Path.GetDirectoryName(filepath);
                proc.StartInfo.Domain                 = Path.GetDirectoryName(filepath);
                proc.StartInfo.RedirectStandardOutput = true;
                proc.StartInfo.RedirectStandardError  = true;
                proc.StartInfo.RedirectStandardInput  = true;
                proc.StartInfo.UseShellExecute        = false;
                proc.StartInfo.CreateNoWindow         = true;
                proc.OutputDataReceived              += Proc_OutputDataReceived;
                proc.ErrorDataReceived               += Proc_ErrorDataReceived;
                proc.Start();
                proc.BeginErrorReadLine();
                proc.BeginOutputReadLine();


                string appcmd = string.Format(GenerateCmd(filepath), filepath, runargs);
                rc.LPush("debug", appcmd);
                proc.StandardInput.WriteLine(appcmd);
                proc.StandardInput.WriteLine("exit");
                proc.WaitForExit();

                //proc.Close();
                //proc.Dispose();

                stopwatch.Stop();

                rc.HIncrBy(debugprefix + "status_" + runUid, "errorcount", -1);
                sethistory(stopwatch.Elapsed.TotalSeconds);
            }
            catch (Exception ex)
            {
                rc.LPush(debugprefix + "error_" + runUid, ex.ToString());
            }
        }
Esempio n. 34
0
        static void Main(string[] args)
        {
            ConsoleHelper.Title = "SAEA.RedisSocketTest";
            ConsoleHelper.WriteLine("输入连接字符串连接RedisServer,格式为\r\nserver=127.0.0.1:6379;passwords=yswenli");

            var cnnStr = ConsoleHelper.ReadLine();

            if (string.IsNullOrEmpty(cnnStr))
            {
                //cnnStr = "server=127.0.0.1:6380;passwords=yswenli";
                cnnStr = "server=172.31.32.85:6379;passwords=yswenli";
            }
            RedisClient redisClient = new RedisClient(cnnStr);

            redisClient.Connect();

            //var keys = redisClient.GetDataBase().Keys();

            //var scan = redisClient.GetDataBase().Scan();
            //var hscan = redisClient.GetDataBase().HScan("haa22", 0);
            //var sscan = redisClient.GetDataBase().SScan("aaa", 0);
            //var zscan = redisClient.GetDataBase().ZScan("zaaa", 0);

            //var r = redisClient.GetDataBase().Rename("aaa", "aaa");

            //var l = redisClient.GetDataBase().LRang("testlist");

            //var z = redisClient.GetDataBase().ZRang("zaaa");

            //var h = redisClient.GetDataBase().HGetAll("haa22");

            redisClient.Select(0);

            //var m = redisClient.ClusterInfo;
            //var n = redisClient.ClusterNodes;
            //var k = redisClient.KeySlot("aaa");
            //var g = redisClient.GetKeysInSlot(0);

            //redisClient.GetDataBase().SRemove("abcd", "12345");

            var info = redisClient.Info();

            if (info.Contains("NOAUTH Authentication required."))
            {
                while (true)
                {
                    ConsoleHelper.WriteLine("请输入redis连接密码");
                    var auth = ConsoleHelper.ReadLine();
                    if (string.IsNullOrEmpty(auth))
                    {
                        auth = "yswenli";
                    }
                    var a = redisClient.Auth(auth);
                    if (a.Contains("OK"))
                    {
                        break;
                    }
                    else
                    {
                        ConsoleHelper.WriteLine(a);
                    }
                }
            }

            //redisConnection.SlaveOf();

            //redisConnection.Ping();

            //redisClient.Select(1);

            //ConsoleHelper.WriteLine(redisConnection.Type("key0"));

            ConsoleHelper.WriteLine("dbSize:{0}", redisClient.DBSize().ToString());

            RedisOperationTest(redisClient, true);
            ConsoleHelper.ReadLine();
        }
Esempio n. 35
0
        public DockServer()
        {
            _localSource = new DockItem()
            {
                Name = "LocalSource"
            };
            _localSource.Create = new Func <object>(() =>
            {
                var result = new SQLiteConnection(CopyConnectString);
                result.Open();
                return(result);
            });
            _localSource.Shutdown = new Action <object>((i) =>
            {
                var connection = i as SQLiteConnection;
                connection.Close();
            });

            _mysqlSource = new DockItem()
            {
                Name = "MySQLSource"
            };
            _mysqlSource.Create = new Func <object>(() =>
            {
                var result = new MySqlConnection(ConnectString);
                result.Open();
                return(result);
            });
            _mysqlSource.Shutdown = new Action <object>((i) =>
            {
                var connection = i as MySqlConnection;
                connection.Close();
            });

            _mysqlAccount = new DockItem()
            {
                Name = "MySQLAccount"
            };
            _mysqlAccount.Create = new Func <object>(() =>
            {
                var result = new MySqlConnection(AccountConnectString);
                result.Open();
                return(result);
            });
            _mysqlAccount.Shutdown = new Action <object>((i) =>
            {
                var connection = i as MySqlConnection;
                connection.Close();
            });

            _redisSocial = new DockItem()
            {
                Name = "RedisSocial"
            };
            _redisSocial.Create = new Func <object>(() =>
            {
                var result = new RedisClient(RedisSocialHost, RedisSocialPort);
                result.Auth(RedisSocialPasswd);
                result.Select(RedisSocialDb);
                return(result);
            });
            _redisSocial.Shutdown = new Action <object>((i) =>
            {
                var connection = i as RedisClient;
                connection.Dispose();
            });

            _redisCopy = new DockItem()
            {
                Name = "RedisCopy"
            };
            _redisCopy.Create = new Func <object>(() =>
            {
                var result = new RedisClient(RedisCopyHost, RedisCopyPort);
                result.Auth(RedisCopyPasswd);
                result.Select(RedisCopyDb);
                return(result);
            });
            _redisCopy.Shutdown = new Action <object>((i) =>
            {
                var connection = i as RedisClient;
                connection.Dispose();
            });
        }