Esempio n. 1
0
        public void SetItems(IEnumerable <object> keys, object sameValue, bool overrides)
        {
            Dictionary <string, Message> list = new Dictionary <string, Message>();

            foreach (var key in keys)
            {
                int    code = key.GetHashCode();
                string host = _nodeLocator.GetNodeForKey(code);
                if (list.ContainsKey(host))
                {
                    list[host].Values.Add(key);
                }
                else
                {
                    Message cacheMsg = new Message(host, Message.CommandType.SetList, key, sameValue, 1, new[] { key },
                                                   overrides);
                    list.Add(host, cacheMsg);
                }
            }

            foreach (var host in list.Keys)
            {
                _client = new Client(host, SettingItem.GetInstance().CacheNodePort);
                Packet packet = new CachePacket(Serializer.SerializeToBytes(list[host]));
                packet.WaiteCallBack = false;
                _client.Send <Message>(packet);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Set the value of the key
        /// </summary>
        public void SetItem(object key, object value, bool overrides)
        {
            int code = key.GetHashCode();
            string host = _nodeLocator.GetNodeForKey(code);
            Message message = new Message(host, Message.CommandType.Set, key, value, 1, null, overrides);
            _client = new Client(host, SettingItem.GetInstance().CacheNodePort);

            Packet packet = new CachePacket(Serializer.SerializeToBytes(message));
            //1207
            packet.WaiteCallBack = false;
            _client.Send<Message>(packet);
        }
Esempio n. 3
0
        /// <summary>
        /// Get the value base on the key
        /// </summary>
        public object GetItem(object key)
        {
            int    code = key.GetHashCode();
            string host = _nodeLocator.GetNodeForKey(code);

            _client = new Client(host, SettingItem.GetInstance().CacheNodePort);
            Message message = new Message(host, Message.CommandType.Get, key, null);
            Packet  packet  = new CachePacket(Serializer.SerializeToBytes(message));

            packet.WaiteCallBack = true;
            message = _client.Send <Message>(packet);
            return(message.Value);
        }
Esempio n. 4
0
        /// <summary>
        /// Set the value of the key
        /// </summary>
        public void SetItem(object key, object value, bool overrides)
        {
            int     code    = key.GetHashCode();
            string  host    = _nodeLocator.GetNodeForKey(code);
            Message message = new Message(host, Message.CommandType.Set, key, value, 1, null, overrides);

            _client = new Client(host, SettingItem.GetInstance().CacheNodePort);

            Packet packet = new CachePacket(Serializer.SerializeToBytes(message));

            //1207
            packet.WaiteCallBack = false;
            _client.Send <Message>(packet);
        }
Esempio n. 5
0
        /// <summary>
        /// Get keys by value
        /// </summary>
        public object[] GetKeyByValue(object value, int topN, object changeValue)
        {
            List <string> hosts = SettingItem.GetInstance().CacherCollections;
            List <object> keys  = new List <object>();

            foreach (var host in hosts)
            {
                _client = new Client(host, SettingItem.GetInstance().CacheNodePort);
                Message message = new Message(host, Message.CommandType.GetList, changeValue, value, topN);
                Packet  packet  = new CachePacket(Serializer.SerializeToBytes(message));
                packet.WaiteCallBack = true;
                message = _client.Send <Message>(packet);
                keys.AddRange(message.Values);
            }
            return(keys.ToArray());
        }
Esempio n. 6
0
        public void SetItems(IEnumerable<object> keys, object sameValue, bool overrides)
        {
            Dictionary<string, Message> list = new Dictionary<string, Message>();
            foreach (var key in keys)
            {
                int code = key.GetHashCode();
                string host = _nodeLocator.GetNodeForKey(code);
                if (list.ContainsKey(host))
                {
                    list[host].Values.Add(key);
                }
                else
                {
                    Message cacheMsg = new Message(host, Message.CommandType.SetList, key, sameValue, 1, new[] { key },
                                                             overrides);
                    list.Add(host, cacheMsg);
                }
            }

            foreach (var host in list.Keys)
            {
                _client = new Client(host, SettingItem.GetInstance().CacheNodePort);
                Packet packet = new CachePacket(Serializer.SerializeToBytes(list[host]));
                packet.WaiteCallBack = false;
                _client.Send<Message>(packet);
            }
        }
Esempio n. 7
0
 /// <summary>
 /// Get keys by value
 /// </summary>
 public object[] GetKeyByValue(object value, int topN, object changeValue)
 {
     List<string> hosts = SettingItem.GetInstance().CacherCollections;
     List<object> keys = new List<object>();
     foreach (var host in hosts)
     {
         _client = new Client(host, SettingItem.GetInstance().CacheNodePort);
         Message message = new Message(host, Message.CommandType.GetList, changeValue, value, topN);
         Packet packet = new CachePacket(Serializer.SerializeToBytes(message));
         packet.WaiteCallBack = true;
         message = _client.Send<Message>(packet);
         keys.AddRange(message.Values);
     }
     return keys.ToArray();
 }
Esempio n. 8
0
 /// <summary>
 /// Get the value base on the key
 /// </summary>
 public object GetItem(object key)
 {
     int code = key.GetHashCode();
     string host = _nodeLocator.GetNodeForKey(code);
     _client = new Client(host, SettingItem.GetInstance().CacheNodePort);
     Message message = new Message(host, Message.CommandType.Get, key, null);
     Packet packet = new CachePacket(Serializer.SerializeToBytes(message));
     packet.WaiteCallBack = true;
     message = _client.Send<Message>(packet);
     return message.Value;
 }