예제 #1
0
        private static string ProcessUserInput(RedisClient redisClient, string username, string otherUsername)
        {
            string input = Console.ReadLine();
            if (otherUsername == null)
            {
                if (redisClient.SIsMember("usernames", input.ToAsciiCharArray()) != 0)
                {
                    otherUsername = input;

                    return otherUsername;
                }
                else
                {
                    Console.WriteLine("Wrong username, try again!");
                    return null;
                }
            }
            else
            {
                if (input.ToLower() != "/exit")
                {
                    string chatName = username.CompareTo(otherUsername) < 0 ? username + "-" + otherUsername : otherUsername + "-" + username;
                    redisClient.RPush("chat:" + chatName, (username + ": " + input).ToAsciiCharArray());
                }
                else
                {
                    otherUsername = null;
                }

                return otherUsername;
            }
        }