public void Redis_StoreCodeTypes() { List <CodeType> list; list = new List <CodeType>(); this.codeTypeList = new List <CodeType>(); this.List(list); string host = "172.16.0.17"; using (RedisClient redisClient = new RedisClient(host)) { foreach (var codetype in list) { // store code type IRedisTypedClient <CodeType> codetypes = redisClient.As <CodeType>(); redisClient.ChangeDb(0); codetypes.SetEntryIfNotExists(codetype.Code, codetype); CodeValue cv = new CodeValue(); ResponseStatus rs = cv.List(codetype.Code); foreach (var codevalue in cv.codeValueList) { // store values IRedisTypedClient <CodeValue> codevalues = redisClient.As <CodeValue>(); redisClient.ChangeDb(1); codevalues.SetEntryIfNotExists(codevalue.FKCodeType + codevalue.ID, codevalue); } } } }
private void InitialTab() { try { if (serverpara.connectvalid == false) { throw new Exception("服务器参数获取失败,请检查参数设置是否有误!"); } string[] host = { serverpara.RedisPassword + '@' + serverpara.RedisIP + ':' + serverpara.RedisPort }; //从连接池获得只读连接客户端 int initialDB = 0; RedisClient Client = (RedisClient)redismanager.GetReadOnlyClient(ref (initialDB), ref (host)); if (Client == null || !Client.Ping()) { throw new Exception("连接服务器失败,请设置服务器参数!"); } //连接云端服务器成功 myTab.Clear(); foreach (var key in CNCinfo) { Client.ChangeDb(key.MachineDB); byte[] machinealarmbyte = new byte[] { }; byte[] alarmbyte = Encoding.UTF8.GetBytes("ALARMNUM_HISTORY"); machinealarmbyte = Client.HGet("Alarm:AlarmNum", alarmbyte); if (machinealarmbyte == null) { continue; } string machinealarmstr = System.Text.Encoding.Default.GetString(machinealarmbyte); long machinealarm = Convert.ToInt64(machinealarmstr); myTab.Rows.Add(new object[] { null, machinealarm, key.MachineName }); } foreach (var key in Robotinfo) { Client.ChangeDb(key.MachineDB); byte[] machinealarmbyte = new byte[] { }; byte[] alarmbyte = Encoding.UTF8.GetBytes("ALARMNUM_HISTORY"); machinealarmbyte = Client.HGet("Alarm:AlarmNum", alarmbyte); if (machinealarmbyte == null) { continue; } string machinealarmstr = System.Text.Encoding.Default.GetString(machinealarmbyte); long machinealarm = Convert.ToInt64(machinealarmstr); myTab.Rows.Add(new object[] { null, machinealarm, key.MachineName }); } } catch (Exception ex) { MessageBox.Show("ERROR:" + ex.Message, "ERROR"); } }
public static void ChangeDb(long db) { using (RedisClient client = GetClient()) { client.ChangeDb(db); } }
public void LoadPaymentWorkload(string filepath) { Console.WriteLine("Loading PAYMENT workload..."); var csvReader = new System.IO.StreamReader(filepath); string line = null; int lineNum = 0; line = csvReader.ReadLine(); // ignore the first line: header int workloadTotal = workerCount * workloadCountPerWorker; int instanceIndex = 0; for (int i = 0; i < workerCount; i++) { RedisClient redisClient = new RedisClient(Constants.RedisHost, Constants.RedisPort); // for payment to create `c_last` index redisClient.ChangeDb(Constants.RedisIndexDbN); Queue <TransactionRequest> reqQueue = new Queue <TransactionRequest>(); for (int k = 0; k < workloadCountPerWorker; k++) { line = csvReader.ReadLine(); lineNum++; if (line == null) { throw new Exception("there is no enough workload"); } string[] columns = line.Split(new string[] { Constants.WorkloadDelimiter }, StringSplitOptions.None); for (int j = 0; j < columns.Length; j++) { columns[j] = columns[j].Substring(1); } columns[columns.Length - 1] = columns[columns.Length - 1].Substring(0, columns[columns.Length - 1].Length - 1); // remove `"` var pm = new PaymentInParameters { timestamp = columns[0], C_ID = (columns[1] == "" ? 0 : Convert.ToUInt32(columns[1])), C_LAST = columns[2], // may be "" H_DATE = columns[3], C_D_ID = Convert.ToUInt32(columns[4]), D_ID = Convert.ToUInt32(columns[5]), W_ID = Convert.ToUInt32(columns[6]), C_W_ID = Convert.ToUInt32(columns[7]), H_AMOUNT = Convert.ToDouble(columns[8]) }; TPCCPaymentStoredProcedure pmsp = new TPCCPaymentStoredProcedure(lineNum.ToString(), pm, redisClient); // TODO: should adopt to the lastest storedprocedure rule // TransactionRequest req = new TransactionRequest(lineNum.ToString(), pmsp); TransactionRequest req = null; reqQueue.Enqueue(req); } List <Tuple <string, int> > executorInstances = instanceIndex >= this.partitionedInstances.Count ? null : this.partitionedInstances[instanceIndex++]; this.executorList.Add(new TransactionExecutor(this.redisVersionDb, null, reqQueue, i, i)); } }
private RedisClient InitClient(RedisClient client) { if (this.ConnectTimeout != null) { client.ConnectTimeout = this.ConnectTimeout.Value; } if (this.SocketSendTimeout.HasValue) { client.SendTimeout = this.SocketSendTimeout.Value; } if (this.SocketReceiveTimeout.HasValue) { client.ReceiveTimeout = this.SocketReceiveTimeout.Value; } if (this.IdleTimeoutSecs.HasValue) { client.IdleTimeoutSecs = this.IdleTimeoutSecs.Value; } if (this.NamespacePrefix != null) { client.NamespacePrefix = this.NamespacePrefix; } if (this.Db != null && client.Db != this.Db) // Reset database to default if changed { client.ChangeDb(this.Db.Value); } return(client); }
public void Can_change_db_at_runtime() { using (var redis = new RedisClient(Config.Localhost, Config.LocalhostPort, Config.LocalhostPassword, 1)) { var val = Environment.TickCount; var key = "test" + val; try { redis.Set(key, val); redis.ChangeDb(2); Assert.That(redis.Get <int>(key), Is.EqualTo(0)); redis.ChangeDb(1); Assert.That(redis.Get <int>(key), Is.EqualTo(val)); redis.Dispose(); } finally { redis.ChangeDb(1); redis.Del(key); } } }
public void Can_change_db_at_runtime() { var redis = new RedisClient(TestConfig.SingleHost, TestConfig.RedisPort, db: 1); var val = Environment.TickCount; var key = "test" + val; try { redis.Set(key, val); redis.ChangeDb(2); Assert.That(redis.Get <int>(key), Is.EqualTo(0)); redis.ChangeDb(1); Assert.That(redis.Get <int>(key), Is.EqualTo(val)); redis.Dispose(); } finally { redis.ChangeDb(1); redis.Del(key); } }
/// <summary> /// 得到一个RedisClient /// </summary> /// <returns></returns> private void GetClient() { try { ICacheFactory cacheFactory = FactoryProducer.GetFactory("Redis"); RedisClient redisClients = ((RedisManage)cacheFactory.GetRedisInstance()).GetRedisClient(); redisClients.ChangeDb(Convert.ToInt64(4)); redisClient = redisClients; } catch (Exception) { throw; } }
/// <summary> /// 客户端缓存操作对象 /// </summary> public RedisClient GetClient(DBEnum _db) { if (_prcm == null) { CreateManager(writeServer, readServer); } RedisClient redisclient = _prcm.GetClient() as RedisClient; if (redisclient.Db != (int)_db) { redisclient.ChangeDb((int)_db); } return(redisclient); }
public void ChangeDb(int db) { try { using (IRedisClient Redis = _prcm.GetClient()) { RedisClient redisClient = (RedisClient)Redis; redisClient.ChangeDb(db); } } catch (Exception e) { throw e; } }
/// <summary> /// 获取一个可用的RedisClient /// </summary> /// <returns>RedisClient</returns> public static RedisClient GetClient(long db = 0) { RedisClient client = null; try { client = MainRedisClientManager.GetClient() as RedisClient; if (db != 0) { client.ChangeDb(db); } } catch (Exception exc) { Logger.Error("获取Redis连接池连接失败", exc); } return(client); }
private RedisClient InitNewClient(RedisClient client) { client.Id = Interlocked.Increment(ref this.RedisClientCounter); client.ConnectionFilter = this.ConnectionFilter; if (this.ConnectTimeout != null) { client.ConnectTimeout = this.ConnectTimeout.Value; } if (this.SocketSendTimeout.HasValue) { client.SendTimeout = this.SocketSendTimeout.Value; } if (this.SocketReceiveTimeout.HasValue) { client.ReceiveTimeout = this.SocketReceiveTimeout.Value; } if (this.IdleTimeoutSecs.HasValue) { client.IdleTimeoutSecs = this.IdleTimeoutSecs.Value; } if (this.NamespacePrefix != null) { client.NamespacePrefix = this.NamespacePrefix; } if (this.Db != null && client.Db != this.Db) { // Reset database to default if changed client.ChangeDb(this.Db.Value); } return(client); }
public void Can_change_db_at_runtime() { using (var redis = new RedisClient(TestConfig.SingleHost, TestConfig.RedisPort, db: 1)) { var val = Environment.TickCount; var key = "test" + val; try { redis.Set(key, val); redis.ChangeDb(2); Assert.That(redis.Get<int>(key), Is.EqualTo(0)); redis.ChangeDb(1); Assert.That(redis.Get<int>(key), Is.EqualTo(val)); redis.Dispose(); } finally { redis.ChangeDb(1); redis.Del(key); } } }
public void ChangeDb(long db) { redisClient.ChangeDb(db); }