StackExchange.Redis

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using StackExchange.Redis;

namespace StackExchangeRedisDemo
{
class Program
{
static void Main(string[] args)
{
ConnectionMultiplexer connection = ConnectionMultiplexer.Connect(“10.10.10.201”);
var db = connection.GetDatabase(0);
db.StringSet(“100101:stringKey”, “stringValue”, TimeSpan.FromMilliseconds(10));
db.StringGet(“100101:stringKey”);
db.StringIncrement(“100101:stringInt”);

        db.ListLeftPush("100101:listTest", "abc");
        db.ListLeftPush("100101:listTest", new[] {"bcd", "abc", "acd", "bca"}.Select(i => (RedisValue) i).ToArray());
        db.ListRange("100101:listTest");

        db.HashSet("100101:hashTest", new[] {new HashEntry("field0", "value0"), new HashEntry("field1", 1)});
        db.HashGetAll("100101:hashTest");
        db.HashIncrement("100101:hashTest", "field1");

        db.SetAdd("100101:setTest", 1);
        db.SetAdd("100101:setTest", new[] {1, 2, 5, 6, 9}.Select(i => (RedisValue) i).ToArray());
        db.SetMembers("100101:setTest");

        var batch = db.CreateBatch();
        batch.StringSetAsync("100101:stringKey1", "test");
        batch.SetAddAsync("100101:setTest1", "123");
        var taskBatch = batch.HashGetAllAsync("100101:hashTest");
        batch.Execute();
        var entries = taskBatch.Result;
        Console.WriteLine(entries.Length);

        var transaction = db.CreateTransaction();
        transaction.HashIncrementAsync("100101:hashTest", "field1");
        transaction.ListLeftPushAsync("100101:listTest", "bcde");
        transaction.Execute();
    }
}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值