赞
踩
using StackExchange.Redis; using CoreRedis.Models; using Microsoft.Extensions.Options; using CoreRedis.Config; namespace CoreRedis.RedisDataType { public class RedisList { private static readonly object Locker = new object(); private ConnectionMultiplexer connectionMultiplexer; IDatabase db = null; public RedisList(IOptionsMonitor<RedisConfig> optionsMonitor) { connectionMultiplexer = ConnectionMultiplexer.Connect(optionsMonitor.CurrentValue.Value); db = connectionMultiplexer.GetDatabase(); } //lpush 左侧插入元素 public async Task<Task<long>> LPUSH(string key,string value) { return db.ListLeftPushAsync(key, value,When.NotExists); } //右侧插入元素 public async Task<Task<long>> RPUSH(string key,string value) { return db.ListRightPushAsync(key, value,When.NotExists); } //从左侧弹出元素 public async Task<Task<RedisValue>> LPOP(string key) { return db.ListLeftPopAsync(key); } //从左侧弹出多个元素 public async Task<Task<RedisValue[]>> LPOPMUL(string key,long count) { return db.ListLeftPopAsync(key,count); } //len 获取列表长度 public async Task<Task<long>> LLen(string key) { return db.ListLengthAsync(key); } //lindex 获取指定索引上的数据 public async Task<Task<RedisValue>> LIndex(string key,long index) { return db.ListGetByIndexAsync(key,index); } //lrange 获取一个索引范围的数据 public async Task<Task<RedisValue[]>> LRange(string key,long start,long end) { return db.ListRangeAsync(key,start,end); } //lset 为指定索引设置新值 public async Task LSet(string key,string value,long index) { await db.ListSetByIndexAsync(key,index,value); } //ltrim 裁剪 public async Task<Task> LTrim(string key,long start,long stop) { return db.ListTrimAsync(key, start, stop); } //lrem 删除元素,0表示全部删除,-1 表示从左侧开始删除等于value的count个,1表示右侧 public async Task<Task<long>> LRem(string key,long count,string value) { return db.ListRemoveAsync(key,value,count); } } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。