Example #1
0
        public static void AskReplyError()
        {
            lock (sync)
            {
                shutdownAll();
                Assert.True(Systems.Count == 0);

                // Let Language Ext know that Redis exists
                RedisCluster.register();

                // Connect to the Redis cluster
                ProcessConfig.initialise("sys", "global", "redis-ask-reply-test", "localhost", "0");

                var world = spawn <ProcessId, string>("world",
                                                      () => spawn <string>("hello", msg => failwith <Unit>("Failed!"), ProcessFlags.PersistInbox),
                                                      (pid, msg) =>
                {
                    Assert.Throws <ProcessException>(() =>
                    {
                        ask <string>(pid, msg);
                    });
                    return(pid);
                },
                                                      ProcessFlags.PersistInbox
                                                      );

                tell(world, "error throwing test");

                Thread.Sleep(100);
            }
        }
Example #2
0
        public static void AskReplyError()
        {
            shutdownAll();

            // Let Language Ext know that Redis exists
            RedisCluster.register();

            // Connect to the Redis cluster
            Cluster.connect("redis", "redis-test", "localhost", "0");

            var world = spawn <ProcessId, string>("world",
                                                  () => spawn <string>("hello", msg => failwith <Unit>("Failed!"), ProcessFlags.PersistInbox),
                                                  (pid, msg) =>
            {
                Assert.Throws <ProcessException>(() =>
                {
                    ask <string>(pid, msg);
                });
                return(pid);
            },
                                                  ProcessFlags.PersistInbox
                                                  );

            tell(world, "error throwing test");
        }
Example #3
0
        internal RedisManager(RedisCluster cluster)
        {
            if (cluster.Configs != null && cluster.Configs.Any())
            {
                var configs = cluster.Configs;
                foreach (var config in configs)
                {
                    if (_dict.ContainsKey(config.Name) || string.IsNullOrEmpty(config.Name))
                    {
                        continue;
                    }
                    switch (config.Mode)
                    {
                    case RedisMode.Common:
                    case RedisMode.Cluster:
                    {
                        var client = new CSRedisClient(config.ConnectionStr);
                        _dict.Add(config.Name, client);
                        Default ??= client;
                    }
                    break;

                    case RedisMode.Guard:
                    {
                        var client = new CSRedisClient(null, config.Sentinels.ToArray());
                        _dict.Add(config.Name, client);
                        Default ??= client;
                    }
                    break;
                    }
                }
            }
        }
Example #4
0
        //
        //  Launch a process that adds the int sent in a message to its state
        //  Then calls itself after a second to do the same again.  The state value gradually
        //  increases.
        //
        //  If you stop the sample and restart you'll notice the state has been persisted
        //
        static void Main(string[] args)
        {
            // Log what's going on
            ProcessSystemLog.Subscribe(Console.WriteLine);

            // Let Language Ext know that Redis exists
            RedisCluster.register();

            // Connect to the Redis cluster
            ProcessConfig.initialise("sys", "global", "redis-test", "localhost", "0");

            // Spawn the process
            var pid = spawn <string>("redis-inbox-sample", Inbox, ProcessFlags.PersistInbox);

            Console.WriteLine("Press a key to add 100 messages to the process queue");
            Console.WriteLine(" - The process queue has a Thread.Sleep(200) in it");
            Console.WriteLine(" - So it takes 20 seconds to get through all of the messages");
            Console.WriteLine(" - If you quit the sample and restart, you should see the ");
            Console.WriteLine(" - inbox has persisted.");
            Console.WriteLine("");
            Console.WriteLine("Press a key");
            Console.ReadKey();

            var rnd = new Random();

            for (var i = 0; i < 100; i++)
            {
                tell(pid, "Message sent: " + DateTime.Now + " " + DateTime.Now.Ticks + " " + rnd.Next());
            }

            Console.ReadKey();
        }
Example #5
0
        static void Main(string[] args)
        {
            var ping = ProcessId.Top["redis-watcher-a"]["user"]["ping"];

            // Let Language Ext know that Redis exists
            RedisCluster.register();

            // Connect to the Redis cluster
            Cluster.connect("redis", "redis-watcher-b", "localhost", "0", "global");

            var pong = spawn <string>(
                Name: "pong",
                Inbox: msg =>
            {
                Console.WriteLine(msg);
                tell(ping, "ping", 1000 * ms);
            },
                Terminated: pid => Console.WriteLine(pid + " is pushing up the daisies"),
                Flags: ProcessFlags.PersistInbox
                );

            watch(pong, ping);

            Console.ReadKey();
        }
Example #6
0
        public static void AskReplyError()
        {
            shutdownAll();

            // Let Language Ext know that Redis exists
            RedisCluster.register();

            // Connect to the Redis cluster
            ProcessConfig.initialise("sys", "global", "redis-test", "localhost", "0");

            try
            {
                var world = spawn <ProcessId, string>("world",
                                                      () => spawn <string>("hello", msg => failwith <Unit>("Failed!"), ProcessFlags.PersistInbox),
                                                      (pid, msg) =>
                {
                    ask <string>(pid, msg);
                    return(pid);
                },
                                                      ProcessFlags.PersistInbox
                                                      );
                tell(world, "error throwing test");
            }
            catch (Exception e)
            {
                Debug.Assert(e.Message == "Process issue: Failed!");
            }

            Thread.Sleep(1000);
        }
Example #7
0
        static void Main(string[] args)
        {
            RedisCluster.register();
            initialise("app", "session-id-role", "session-id-node-1", "localhost", "0");

            var app = spawn <Unit, string>(
                Name: "application",
                Setup: () => ignore(spawn <string>("child", msg => Console.WriteLine($"{msg} : {sessionId()}"), ProcessFlags.PersistInbox)),
                Inbox: (_, msg) => fwdChild("child"),
                Flags: ProcessFlags.PersistInbox);

            while (true)
            {
                var sid = SessionId.Generate();

                withSession(sid, () =>
                {
                    sessionId();
                    tell(app, "Hello");
                });

                if (Console.ReadKey().Key == ConsoleKey.Escape)
                {
                    break;
                }
            }
        }
Example #8
0
        static void Main(string[] args)
        {
            RedisCluster.register();
            initialise("app", "schedule-test", "schedule-test1", "localhost", "0");

            //RunInbox();
            RunInboxAppendNum();
            //RunInboxAppend();
        }
Example #9
0
        internal static RedisCluster GetCluster(TextWriter log = null)
        {
            string clusterConfiguration =
                RemoteHost + ":" + clusterPort0 + "," +
                RemoteHost + ":" + clusterPort1 + "," +
                RemoteHost + ":" + clusterPort2;

            return(RedisCluster.Connect(clusterConfiguration, log));
        }
Example #10
0
        static void Main(string[] args)
        {
            // Remove this to get on-screen logging
            ProcessSystemLog.Subscribe(Console.WriteLine);

            // Let Language Ext know that Redis exists
            RedisCluster.register();

            // Connect to the Redis cluster
            ProcessConfig.initialiseFileSystem("session-test-1");

            var ping = ProcessId.None;
            var pong = ProcessId.None;

            // Start a process which simply writes the messages it receives to std-out
            var logger = spawn <string>("logger", x => Console.WriteLine(x));

            sessionStart("xyz", 20 * seconds, "live");

            // Ping process
            ping = spawn <string>("ping", msg =>
            {
                tell(logger, msg);

                var txt = hasSession()
                    ? sessionId().ToString()
                    : "expired";

                var val = sessionGetData <int>("test");
                sessionSetData("test", val.FirstOrDefault() + 1);

                tell(pong, $"ping-{txt}-{val.FirstOrDefault()}", TimeSpan.FromMilliseconds(1000));
            });

            // Pong process
            pong = spawn <string>("pong", msg =>
            {
                tell(logger, msg);

                var txt = hasSession()
                    ? sessionId().ToString()
                    : "expired";

                var val = sessionGetData <int>("test");
                sessionSetData("test", val.FirstOrDefault() + 1);

                tell(ping, $"pong-{txt}-{val.FirstOrDefault()}", TimeSpan.FromMilliseconds(1000));
            });

            // Trigger
            tell(pong, "start");

            Console.ReadKey();
        }
Example #11
0
        public static void Main(string[] args)
        {
            // Remove this to get on-screen logging
            ProcessSystemLog.Subscribe(Console.WriteLine);

            RedisCluster.register();
            ProcessConfig.initialiseFileSystem("ping-pong-1");

            var ping = ProcessId.None;
            var pong = ProcessId.None;

            Process.PreShutdown.Subscribe(_ =>
            {
                kill(ping);
                kill(pong);
            });

            // Start a process which simply writes the messages it receives to std-out
            var logger = spawn <string>("logger", x => Console.WriteLine(x));

            // Ping process
            ping = spawn <string>("ping", msg =>
            {
                tell(logger, msg);

                var res  = readList <int>("arr");
                var name = read("name", "");
                var ind  = read("count", 0);
                write("count", ind + 1);

                tell(pong, $"ping {name}-{ind}", TimeSpan.FromMilliseconds(100));
            });

            // Pong process
            pong = spawn <string>("pong", msg =>
            {
                tell(logger, msg);

                var map  = readMap <string>("map");
                var name = read("name", "");
                var ind  = read("count", 0);
                write("count", ind + 1);

                tell(ping, $"pong {name}-{ind}", TimeSpan.FromMilliseconds(100));
            });

            // Trigger
            tell(ping, "start");

            Console.ReadKey();

            Process.shutdownAll();
        }
Example #12
0
        public QueryPage(string key)
        {
            InitializeComponent();

            var cluster = ConnectionManager.Connections[key];

            if (cluster != null)
            {
                _cluster = cluster;
                _key     = key;
            }
        }
Example #13
0
        public void RedisRegisterTest()
        {
            lock (sync)
            {
                shutdownAll();
                Assert.True(Systems.Count == 0);

                // Let Language Ext know that Redis exists
                RedisCluster.register();

                // Connect to the Redis cluster
                ProcessConfig.initialise("sys", "global", "redis-test", "localhost", "0");

                string value = null;
                var    pid   = spawn <string>("reg-proc", msg => value = msg);

                var regid = register("woooo amazing", pid);

                Assert.True(regid == "/disp/reg/global-woooo amazing");

                Thread.Sleep(200);

                tell(regid, "hello");

                Thread.Sleep(200);

                Assert.True(value == "hello");

                tell(find("woooo amazing"), "world");

                Thread.Sleep(200);

                Assert.True(value == "world");

                deregisterById(pid);

                Thread.Sleep(200);

                try
                {
                    tell(find("woooo amazing"), "noooo");
                }
                catch (Exception e)
                {
                    Assert.True(e.Message.Contains("No processes in group"));
                }

                Thread.Sleep(200);

                Assert.True(value != "noooo");
            }
        }
Example #14
0
        public static void RegisterTest()
        {
            try
            {
                shutdownAll();

                // Let Language Ext know that Redis exists
                RedisCluster.register();

                // Connect to the Redis cluster
                Cluster.connect("redis", "redis-test", "localhost", "0", "global");

                string value = null;
                var    pid   = spawn <string>("reg-proc", msg => value = msg);

                var regid = register <string>("woooo amazing", pid);

                Thread.Sleep(10);

                var kids = children(Registered);

                Debug.Assert(kids.Count() == 1);
                Debug.Assert(kids["woooo amazing"].Path == "/registered/woooo amazing");

                tell(regid, "hello");

                Thread.Sleep(10);

                Debug.Assert(value == "hello");

                tell(find("woooo amazing"), "world");

                Thread.Sleep(10);

                Debug.Assert(value == "world");

                Thread.Sleep(10);

                deregister("woooo amazing");

                Thread.Sleep(10);

                kids = children(Registered);
                Debug.Assert(kids.Count() == 0);
            }
            finally
            {
                Cluster.disconnect();
            }
        }
Example #15
0
        public void TimeSlotHashing_Cluster()
        {
            int total = 0;
            var watch = Stopwatch.StartNew();

            unchecked
            {
                for (int i = 0; i < LOOP; i++)
                {
                    total += RedisCluster.HashSlot("GetSetValues" + i);
                }
            }
            watch.Stop();
            Console.WriteLine("Time to hash {0}: {1}ms ({2})", LOOP, watch.ElapsedMilliseconds, total);
        }
Example #16
0
        static void Main(string[] args)
        {
            // Remove this to get on-screen logging
            ProcessSystemLog.Subscribe(Console.WriteLine);

            // Let Language Ext know that Redis exists
            RedisCluster.register();

            // Connect to the Redis cluster
            Cluster.connect("redis", "redis-session-test", "localhost:6379", "0", "global");

            var ping = ProcessId.None;
            var pong = ProcessId.None;

            // Start a process which simply writes the messages it receives to std-out
            var logger = spawn <string>("logger", Console.WriteLine);

            sessionStart("xyz", 20 * seconds);

            // Ping process
            ping = spawn <string>("ping", msg =>
            {
                tell(logger, msg);

                var txt = hasSession()
                    ? sessionId().ToString()
                    : "expired";

                tell(pong, "ping-" + txt, TimeSpan.FromMilliseconds(1000));
            });

            // Pong process
            pong = spawn <string>("pong", msg =>
            {
                tell(logger, msg);

                var txt = hasSession()
                    ? sessionId().ToString()
                    : "expired";

                tell(ping, "pong-" + txt, TimeSpan.FromMilliseconds(1000));
            });

            // Trigger
            tell(pong, "start");

            Console.ReadKey();
        }
Example #17
0
        static void Test6()
        {
            var str = @"1d30dccb6ef7daedd79884d4c4fd93cfaf848c17 172.16.10.32:6379@16379 myself,master - 0 1551270675000 1 connected 0-4095 [12222-<-0655825d6cb9148d5bfb9f68bdfb4e1651fac62e] [14960-<-eb2da2a40037265b9f21022d2c6e2ba00e91b67c]
2c24ef8cbe72ac2f987fb15a08d017c6aefe9fab 172.16.10.34:7000@17000 slave 9412d9fba8f7cb5c99f3a29f2abdda44dce8b506 0 1551270679509 8 connected
eb2da2a40037265b9f21022d2c6e2ba00e91b67c 172.16.10.32:7000@17000 master - 0 1551270680511 2 connected 12288-16383
0655825d6cb9148d5bfb9f68bdfb4e1651fac62e 172.16.10.34:6379@16379 master - 0 1551270678000 7 connected 8192-12287
88d1256ee4142e220516508b29b8ebdee80521a0 172.16.10.34:7001@17001 slave 1d30dccb6ef7daedd79884d4c4fd93cfaf848c17 0 1551270677504 9 connected
9412d9fba8f7cb5c99f3a29f2abdda44dce8b506 172.16.10.33:6379@16379 master - 0 1551270677000 4 connected 4096-8191
71cd78e1f4aeee042ea99925c72f0a943a061ed4 172.16.10.32:7001@17001 slave 0655825d6cb9148d5bfb9f68bdfb4e1651fac62e 0 1551270676000 7 connected
8b5e17020b0fcc742341c583518c2ab247b34afa 172.16.10.33:7001@17001 slave eb2da2a40037265b9f21022d2c6e2ba00e91b67c 0 1551270680000 6 connected
220fd8bd50d5329c5ac5b867991df12237f102ed 172.16.10.33:7000@17000 slave 1d30dccb6ef7daedd79884d4c4fd93cfaf848c17 0 1551270676000 5 connected
";

            var cluster = new RedisCluster(null);

            cluster.ParseNodes(str);
        }
Example #18
0
        static void Main(string[] args)
        {
            // Log what's going on
            // ProcessLog.Subscribe(Console.WriteLine);

            // Let Language Ext know that Redis exists
            RedisCluster.register();

            // Connect to the Redis cluster
            ProcessConfig.initialise("sys", "global", "redis-subscribe-test", "localhost", "0");

            var pid = ProcessId.Top["redis-publish-test"]["user"]["redis-pubsub-random-test"];

            // Listen to the published results coming back from the Redis channel
            subscribe <int>(pid, Console.WriteLine);

            Console.ReadKey();
        }
Example #19
0
        void ExecuteCluster(RedisCluster redisCluster)
        {
            char[] chars = new[] {
                '1', '2', '3', '4', '5', '6', '7', '8', '9',
                'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
                'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
            };
            var      rd            = new Random();
            DateTime lastWriteTime = new DateTime(1970, 01, 01);

            while (true)
            {
                try
                {
                    // 保持 0.5s 写一次 REDIS
                    if ((DateTime.Now - lastWriteTime).TotalSeconds < 0.5)
                    {
                        continue;
                    }

                    char[] keyChars = new char[10];
                    keyChars[0] = 'B';
                    keyChars[1] = '0';
                    keyChars[2] = '7';
                    for (int index = 3; index < 10; index++)
                    {
                        var r = rd.Next(0, chars.Length - 1);
                        keyChars[index] = chars[r];
                    }

                    string key = new string(keyChars);
                    redisCluster.Set(key, key);
                    string value = redisCluster.Get <string>(key);
                    //redisCluster.Del(key);

                    this.AppendTextAsync("{0} {1}", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), value);
                    lastWriteTime = DateTime.Now;
                }
                catch (Exception ex)
                {
                    this.AppendTextAsync2("{0} {1}", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), ex.Message);
                }
            }
        }
Example #20
0
        static void Test1()
        {
            ProcessId pong = ProcessId.None;
            ProcessId ping = ProcessId.None;

            // Let Language Ext know that Redis exists
            RedisCluster.register();

            // Connect to the Redis cluster
            ProcessConfig.initialise("sys", "global", "redis-test", "localhost", "0");

            ping = spawn <string>(
                Name:      "ping",
                Inbox:     msg =>
            {
                Console.WriteLine(msg);
                tell(pong, "pong", 100 * ms);
            },
                Terminated: pid => Console.WriteLine(pid + " is pushing up the daisies"),
                Flags: ProcessFlags.PersistInbox
                );

            pong = spawn <string>(
                Name:     "pong",
                Inbox:     msg =>
            {
                Console.WriteLine(msg);
                tell(ping, "ping", 100 * ms);
            },
                Terminated: pid => Console.WriteLine(pid + " is pushing up the daisies"),
                Flags: ProcessFlags.PersistInbox
                );

            watch(ping, pong);
            watch(pong, ping);

            tell(pong, "Running");

            Console.WriteLine("Press key to kill ping");
            Console.ReadKey();
            kill(ping);
            Console.WriteLine("Press key to exit");
            Console.ReadKey();
        }
Example #21
0
        //public static void RegisteredAskReply()
        //{
        //    shutdownAll();
        //    ProcessConfig.initialise();

        //    var helloServer = spawn<string>("hello-server", msg =>
        //    {
        //        reply("Hello, " + msg);
        //    });

        //    var hi = register<string>("hi", helloServer);

        //    var response = ask<string>(find("hi"), "Paul");

        //    Debug.Assert(response == "Hello, Paul");
        //}

        public static void AskReply()
        {
            shutdownAll();

            // Let Language Ext know that Redis exists
            RedisCluster.register();

            // Connect to the Redis cluster
            ProcessConfig.initialise("sys", "global", "redis-test", "localhost", "0");

            var helloServer = spawn <string>("hello-server", msg =>
            {
                reply("Hello, " + msg);
            },
                                             ProcessFlags.PersistInbox);

            var response = ask <string>(helloServer, "Paul");

            Debug.Assert(response == "Hello, Paul");
        }
Example #22
0
        private static object _connect(object[] args)
        {
            string name       = args[0] as string;
            string str        = args[1] as string;
            var    connection = DbUtil.Open(str);

            if (connection != null)
            {
                var cluster = new RedisCluster();
                cluster.Connected  = true;
                cluster.Connection = connection;
                cluster.Name       = name + DateTime.Now.ToString("[HHmmfff]");

                return(cluster);
            }
            else
            {
                return(null);
            }
        }
Example #23
0
        public void RedisRegisterTest()
        {
            shutdownAll();

            // Let Language Ext know that Redis exists
            RedisCluster.register();

            // Connect to the Redis cluster
            Cluster.connect("redis", "redis-test", "localhost", "0", "global");

            string value = null;
            var    pid   = spawn <string>("reg-proc", msg => value = msg);

            var regid = register("woooo amazing", pid);

            Assert.True(regid == "/disp/reg/global-woooo amazing");

            Thread.Sleep(100);

            tell(regid, "hello");

            Thread.Sleep(100);

            Assert.True(value == "hello");

            tell(find("woooo amazing"), "world");

            Thread.Sleep(100);

            Assert.True(value == "world");

            deregisterById(pid);

            Thread.Sleep(100);

            tell(find("woooo amazing"), "noooo");

            Thread.Sleep(100);

            Assert.True(value != "noooo");
        }
Example #24
0
        //
        //  Launch a process that adds the int sent in a message to its state
        //  Then calls itself after a second to do the same again.  The state value gradually
        //  increases.
        //
        //  If you stop the sample and restart you'll notice the state has been persisted
        //
        static void Main(string[] args)
        {
            // Log what's going on
            // ProcessLog.Subscribe(Console.WriteLine);

            // Let Language Ext know that Redis exists
            RedisCluster.register();

            // Connect to the Redis cluster
            Cluster.connect("redis", "redis-test", "localhost", "0");

            // Spawn the process
            var pid = spawn <int, int>("redis-state-sample", Setup, Inbox, ProcessFlags.PersistState);

            // Subscribe locally to the state changes
            observeState <int>(pid).Subscribe(Console.WriteLine);

            // Start it off by sending the first message
            tell(pid, 1);

            Console.ReadKey();
        }
Example #25
0
        //
        //  This sample sends messages published by a Language Ext process (by calling 'publish')
        //  to a Redis channel.  We then subscribe to the messages coming back where we push them
        //  out to the console.
        //
        static void Main(string[] args)
        {
            // Log what's going on
            // ProcessLog.Subscribe(Console.WriteLine);

            // Let Language Ext know that Redis exists
            RedisCluster.register();

            // Connect to the Redis cluster
            Cluster.connect("redis", "redis-test", "localhost:6379", "0");

            // Launch a process that publishes a random number as fast as possible
            var pid = spawn <Random, int>("redis-pubsub-random-test", Setup, Inbox, ProcessFlags.RemotePublish);

            // Listen to the published results coming back from the Redis channel
            subscribe <int>(pid, Console.WriteLine);

            // Start it off by sending the first message
            tell(pid, 0);

            Console.ReadKey();
        }
Example #26
0
 public void HashingAlgo()
 {  // this example taken from Appendix A of the specification
     Assert.AreEqual(0x31C3, RedisCluster.HashSlot(Encoding.UTF8.GetBytes("123456789")));
 }