本文整理汇总了C#中ServiceStack.Redis.RedisClient.GetTypedClient方法的典型用法代码示例。如果您正苦于以下问题:C# RedisClient.GetTypedClient方法的具体用法?C# RedisClient.GetTypedClient怎么用?C# RedisClient.GetTypedClient使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ServiceStack.Redis.RedisClient
的用法示例。
在下文中一共展示了RedisClient.GetTypedClient方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
try
{
redisHost = ConfigurationManager.AppSettings["redisHost"];
redisPort = int.Parse(ConfigurationManager.AppSettings["redisPort"]);
redisPassword = ConfigurationManager.AppSettings["redisPassword"];
if (!IsPostBack)
{
RedisClient redisClient = new RedisClient(redisHost, redisPort) { Password = redisPassword };
using (var redisGuids = redisClient.GetTypedClient<Guids>())
{
redisGuids.Store(new Guids { Date = DateTime.Now, Value = Guid.NewGuid() });
var allValues = redisGuids.GetAll();
GridView1.DataSource = allValues;
GridView1.DataBind();
}
}
}
catch (Exception ex)
{
throw new WebException(ex.ToString(), WebExceptionStatus.ConnectFailure);
}
}
示例2: RedisQueueClient
/// <summary>
/// Ctor. Obtains and stores a reference to a typed Redis client.
/// </summary>
public RedisQueueClient()
{
_client = new RedisClient(Settings.Default.RedisHost, Settings.Default.RedisPort);
_taskMessageClient = _client.GetTypedClient<TaskMessage>();
_log.Info("Connected to Redis.");
_log.DebugFormat("Connection Properties: {0}:{1}",
Settings.Default.RedisHost, Settings.Default.RedisPort);
}
示例3: GetChangesFor
private List<PlayEvent<StubModel>> GetChangesFor(string modelId)
{
using (var redisClient = new RedisClient())
{
var redis = redisClient.GetTypedClient<PlayEvent<StubModel>>();
return redis.Lists["urn:changes:" + modelId].GetAll();
}
}
示例4: StoreInHash
public static void StoreInHash(string key, string value)
{
using (IRedisClient client = new RedisClient())
{
var objClient = client.GetTypedClient<string>();
var hash = objClient.GetHash<string>(keyPredicate + key.ToString());
hash.Add(key, value);
}
}
示例5: ClearAllChanges
public JsonResult ClearAllChanges()
{
using (var redisClient = new RedisClient())
{
var redis = redisClient.GetTypedClient<StubAddedEvent>();
redis.SetSequence(0);
redis.FlushAll();
}
return this.Json("Changes cleared");
}
示例6: RedisQueueService
public RedisQueueService(Uri baseUri, bool resume)
{
using (RedisClient redisClient = new RedisClient())
{
_redis = redisClient.GetTypedClient<Entry>();
_queue = _redis.Lists[string.Format("barcodes:{0}:queue", baseUri)];
if (!resume)
{
_queue.Clear();
}
}
}
示例7: RedisHistoryService
public RedisHistoryService(Uri baseUri, bool resume)
{
using (RedisClient redisClient = new RedisClient())
{
_redis = redisClient.GetTypedClient<string>();
_history = _redis.Sets[string.Format("barcodes:{0}:history", baseUri)];
if (!resume)
{
_history.Clear();
}
}
}
示例8: GetValue
public static string GetValue(string key)
{
string returnedValue;
using (IRedisClient client = new RedisClient())
{
var objClient = client.GetTypedClient<string>();
var hash = objClient.GetHash<string>(keyPredicate + key);
returnedValue = hash[key];
}
return returnedValue;
}
示例9: Index
public ViewResult Index()
{
var redis = new RedisClient();
using (var redisStatus = redis.GetTypedClient<UserStatus>())
{
var allstatus = redisStatus.GetAll();
var query = (from items in allstatus
select items).ToList();
return View(query);
}
}
示例10: Button2_Click
protected void Button2_Click(object sender, EventArgs e)
{
string redisHost = ConfigurationManager.AppSettings["redisHost"];
int redisPort = int.Parse(ConfigurationManager.AppSettings["redisPort"]);
string redisPassword = ConfigurationManager.AppSettings["redisPassword"];
RedisClient redisClient = new RedisClient(redisHost, redisPort) { Password = redisPassword };
using (var redisGuids = redisClient.GetTypedClient<Guids>())
{
redisGuids.DeleteAll();
var allValues = redisGuids.GetAll();
GridView1.DataSource = allValues;
GridView1.DataBind();
}
}
示例11: Edit
public ActionResult Edit(int id)
{
var redis = new RedisClient();
using (var redisstatus = redis.GetTypedClient<UserStatus>())
{
// Call all items then , select item using id of item
// we don't know id of item stored
// in redis , so search is required.
var item = redisstatus.GetAll().Where(i => i.id.Equals(id));
return View(item.First());
}
}
示例12: QueueClient
public QueueClient(string host, int port, bool enableCaching)
{
RedisHost = host;
RedisPort = port;
GenericClient = new RedisClient(RedisHost, RedisPort);
TypedClient = GenericClient.GetTypedClient<TaskMessage>();
Log.Info("Connected to Redis.");
Log.DebugFormat("Connection Properties: {0}:{1}", Settings.Default.RedisHost, Settings.Default.RedisPort);
LocalCachingEnabled = enableCaching;
if (LocalCachingEnabled)
{
Log.Info("Caching 's enabled. Cache location: " + Settings.Default.LocalCache);
CheckCacheAndRetrieveState();
}
}
示例13: Create
public ActionResult Create(UserStatus status)
{
if (ModelState.IsValid)
{
var redis = new RedisClient();
using (var redisStatus = redis.GetTypedClient<UserStatus>())
{
redisStatus.Store(new UserStatus { id = (int) redisStatus.GetNextSequence(), name = status.name, description = status.description });
}
return RedirectToAction("Index");
}
else
{
ViewBag.status = "Invalid";
return View();
}
}
示例14: GetKeysAndValues
public static List<KeyValuePair<string, string>> GetKeysAndValues()
{
List<KeyValuePair<string, string>> result = new List<KeyValuePair<string, string>>();
using (IRedisClient client = new RedisClient())
{
var objClient = client.GetTypedClient<string>();
var keys = objClient.GetAllKeys().Where(x => x.StartsWith(keyPredicate));
foreach (var key in keys)
{
var hash = objClient.GetHash<string>(key);
var word = key.Substring(keyPredicate.Length);
var val = hash[word];
result.Add(new KeyValuePair<string, string>(word, val));
}
}
return result;
}
示例15: Main
static void Main(string[] args)
{
/*** String ***/
using (IRedisNativeClient client = new RedisClient())
{
client.Set("urn:messages:1", Encoding.UTF8.GetBytes("Hello C# World!"));
}
using (IRedisNativeClient client = new RedisClient())
{
var result = Encoding.UTF8.GetString(client.Get("urn:messages:1"));
Console.WriteLine("Message: {0}", result);
}
/*** Lists ***/
using (IRedisClient client = new RedisClient())
{
var customerNames = client.Lists["urn:customernames"];
customerNames.Clear();
customerNames.Add("Joe");
customerNames.Add("Mary");
customerNames.Add("Bob");
}
using (IRedisClient client = new RedisClient())
{
var customerNames = client.Lists["urn:customernames"];
foreach (var customerName in customerNames)
{
Console.WriteLine("Customer {0}", customerName);
}
}
/*** Object ***/
long lastId = 0;
using (IRedisClient client = new RedisClient())
{
var customerClient = client.GetTypedClient<Customer>();
var customer = new Customer()
{
Id = customerClient.GetNextSequence(),
Address = "123 Main St",
Name = "Bob Green",
Orders = new List<Order>
{
new Order { OrderNumber = "AB123"},
new Order { OrderNumber = "AB124"}
}
};
var storedCustomer = customerClient.Store(customer);
lastId = storedCustomer.Id;
}
using (IRedisClient client = new RedisClient())
{
var customerClient = client.GetTypedClient<Customer>();
var customer = customerClient.GetById(lastId);
Console.WriteLine("Got customer {0}, with name {1}", customer.Id, customer.Name);
}
/*** Transaction ***/
using (IRedisClient client = new RedisClient())
{
var transaction = client.CreateTransaction();
transaction.QueueCommand(c => c.Set("abc", 1));
transaction.QueueCommand(c => c.Increment("abc", 1));
transaction.Commit();
var result = client.Get<int>("abc");
Console.WriteLine(result);
}
/*** Publishing & Subscribing ***/
using (IRedisClient client = new RedisClient())
{
client.PublishMessage("debug", "Hello C#!");
var sub = client.CreateSubscription();
sub.OnMessage = (c, m) => Console.WriteLine("Got message {0}, from channel {1}", m, c);
sub.SubscribeToChannels("news");
}
Console.ReadLine();
}