Redis
 sql >> डेटाबेस >  >> NoSQL >> Redis

रेडिस टाइप किया गया क्लाइंट

सर्विस स्टैक के C# Redis क्लाइंट पर एक 'दृढ़ता से टाइप किया हुआ' API उपलब्ध है, जो सभी Redis Value संचालनों को किसी भी c# प्रकार के विरुद्ध लागू करने के लिए करता है

जोर से टाइप किया गया जेनेरिक क्लाइंट एपीआई #

नीचे दृढ़ता से टाइप किया गया एपीआई है जिस तक आपके पास IRedisClient.As<T>() पर कॉल करने के बाद पहुंच है उदा.:

using (var redisClient = new RedisClient())
{
    var redis = redisClient.As<MyPocoType>();
}

रेडिस वेरिएबल में अब एक जोरदार टाइप किया गया जेनेरिक क्लाइंट है जो रेडिस वैल्यू ऑपरेशंस को MyPocoType के खिलाफ लागू करने की अनुमति देता है। . नीचे दिया गया इंटरफ़ेस सभी उपलब्ध कार्यों को सूचीबद्ध करता है:

public interface IRedisTypedClient<T>
    : IBasicPersistenceProvider<T>
{
    IHasNamed<IRedisList<T>> Lists { get; set; }
    IHasNamed<IRedisSet<T>> Sets { get; set; }
    IHasNamed<IRedisSortedSet<T>> SortedSets { get; set; }
    IRedisHash<TKey, T> GetHash<TKey>(string hashId);

    IRedisTypedTransaction<T> CreateTransaction();

    IDisposable AcquireLock();
    IDisposable AcquireLock(TimeSpan timeOut);

    int Db { get; set; }
    List<string> GetAllKeys();

    T this[string key] { get; set; }

    string SequenceKey { get; set; }
    void SetSequence(int value);
    int GetNextSequence();
    RedisKeyType GetEntryType(string key);
    string GetRandomKey();

    void SetEntry(string key, T value);
    void SetEntry(string key, T value, TimeSpan expireIn);
    bool SetEntryIfNotExists(string key, T value);
    T GetValue(string key);
    T GetAndSetValue(string key, T value);
    bool ContainsKey(string key);
    bool RemoveEntry(string key);
    bool RemoveEntry(params string[] args);
    bool RemoveEntry(params IHasStringId[] entities);
    int IncrementValue(string key);
    int IncrementValueBy(string key, int count);
    int DecrementValue(string key);
    int DecrementValueBy(string key, int count);
    bool ExpireEntryIn(string key, TimeSpan expiresAt);
    bool ExpireEntryAt(string key, DateTime dateTime);
    TimeSpan GetTimeToLive(string key);
    void Save();
    void SaveAsync();
    void FlushDb();
    void FlushAll();
    T[] SearchKeys(string pattern);
    List<T> GetValues(List<string> keys);
    List<T> GetSortedEntryValues(IRedisSet<T> fromSet, int startingFrom, int endingAt);

    HashSet<T> GetAllItemsFromSet(IRedisSet<T> fromSet);
    void AddItemToSet(IRedisSet<T> toSet, T item);
    void RemoveItemFromSet(IRedisSet<T> fromSet, T item);
    T PopItemFromSet(IRedisSet<T> fromSet);
    void MoveBetweenSets(IRedisSet<T> fromSet, IRedisSet<T> toSet, T item);
    int GetSetCount(IRedisSet<T> set);
    bool SetContainsItem(IRedisSet<T> set, T item);
    HashSet<T> GetIntersectFromSets(params IRedisSet<T>[] sets);
    void StoreIntersectFromSets(IRedisSet<T> intoSet, params IRedisSet<T>[] sets);
    HashSet<T> GetUnionFromSets(params IRedisSet<T>[] sets);
    void StoreUnionFromSets(IRedisSet<T> intoSet, params IRedisSet<T>[] sets);
    HashSet<T> GetDifferencesFromSet(IRedisSet<T> fromSet, params IRedisSet<T>[] withSets);
    void StoreDifferencesFromSet(IRedisSet<T> intoSet, IRedisSet<T> fromSet, params IRedisSet<T>[] withSets);
    T GetRandomItemFromSet(IRedisSet<T> fromSet);

    List<T> GetAllItemsFromList(IRedisList<T> fromList);
    List<T> GetRangeFromList(IRedisList<T> fromList, int startingFrom, int endingAt);
    List<T> SortList(IRedisList<T> fromList, int startingFrom, int endingAt);
    void AddItemToList(IRedisList<T> fromList, T value);
    void PrependItemToList(IRedisList<T> fromList, T value);
    T RemoveStartFromList(IRedisList<T> fromList);
    T BlockingRemoveStartFromList(IRedisList<T> fromList, TimeSpan? timeOut);
    T RemoveEndFromList(IRedisList<T> fromList);
    void RemoveAllFromList(IRedisList<T> fromList);
    void TrimList(IRedisList<T> fromList, int keepStartingFrom, int keepEndingAt);
    int RemoveItemFromList(IRedisList<T> fromList, T value);
    int RemoveItemFromList(IRedisList<T> fromList, T value, int noOfMatches);
    int GetListCount(IRedisList<T> fromList);
    T GetItemFromList(IRedisList<T> fromList, int listIndex);
    void SetItemInList(IRedisList<T> toList, int listIndex, T value);

    //Queue operations
    void EnqueueItemOnList(IRedisList<T> fromList, T item);
    T DequeueItemFromList(IRedisList<T> fromList);
    T BlockingDequeueItemFromList(IRedisList<T> fromList, TimeSpan? timeOut);

    //Stack operations
    void PushItemToList(IRedisList<T> fromList, T item);
    T PopItemFromList(IRedisList<T> fromList);
    T BlockingPopItemFromList(IRedisList<T> fromList, TimeSpan? timeOut);
    T PopAndPushItemBetweenLists(IRedisList<T> fromList, IRedisList<T> toList);

    void AddItemToSortedSet(IRedisSortedSet<T> toSet, T value);
    void AddItemToSortedSet(IRedisSortedSet<T> toSet, T value, double score);
    bool RemoveItemFromSortedSet(IRedisSortedSet<T> fromSet, T value);
    T PopItemWithLowestScoreFromSortedSet(IRedisSortedSet<T> fromSet);
    T PopItemWithHighestScoreFromSortedSet(IRedisSortedSet<T> fromSet);
    bool SortedSetContainsItem(IRedisSortedSet<T> set, T value);
    double IncrementItemInSortedSet(IRedisSortedSet<T> set, T value, double incrementBy);
    int GetItemIndexInSortedSet(IRedisSortedSet<T> set, T value);
    int GetItemIndexInSortedSetDesc(IRedisSortedSet<T> set, T value);
    List<T> GetAllItemsFromSortedSet(IRedisSortedSet<T> set);
    List<T> GetAllItemsFromSortedSetDesc(IRedisSortedSet<T> set);
    List<T> GetRangeFromSortedSet(IRedisSortedSet<T> set, int fromRank, int toRank);
    List<T> GetRangeFromSortedSetDesc(IRedisSortedSet<T> set, int fromRank, int toRank);
    IDictionary<T, double> GetAllWithScoresFromSortedSet(IRedisSortedSet<T> set);
    IDictionary<T, double> GetRangeWithScoresFromSortedSet(IRedisSortedSet<T> set, int fromRank, int toRank);
    IDictionary<T, double> GetRangeWithScoresFromSortedSetDesc(IRedisSortedSet<T> set, int fromRank, int toRank);
    List<T> GetRangeFromSortedSetByLowestScore(IRedisSortedSet<T> set, string fromStringScore, string toStringScore);
    List<T> GetRangeFromSortedSetByLowestScore(IRedisSortedSet<T> set, string fromStringScore, string toStringScore, int? skip, int? take);
    List<T> GetRangeFromSortedSetByLowestScore(IRedisSortedSet<T> set, double fromScore, double toScore);
    List<T> GetRangeFromSortedSetByLowestScore(IRedisSortedSet<T> set, double fromScore, double toScore, int? skip, int? take);
    IDictionary<T, double> GetRangeWithScoresFromSortedSetByLowestScore(IRedisSortedSet<T> set, string fromStringScore, string toStringScore);
    IDictionary<T, double> GetRangeWithScoresFromSortedSetByLowestScore(IRedisSortedSet<T> set, string fromStringScore, string toStringScore, int? skip, int? take);
    IDictionary<T, double> GetRangeWithScoresFromSortedSetByLowestScore(IRedisSortedSet<T> set, double fromScore, double toScore);
    IDictionary<T, double> GetRangeWithScoresFromSortedSetByLowestScore(IRedisSortedSet<T> set, double fromScore, double toScore, int? skip, int? take);
    List<T> GetRangeFromSortedSetByHighestScore(IRedisSortedSet<T> set, string fromStringScore, string toStringScore);
    List<T> GetRangeFromSortedSetByHighestScore(IRedisSortedSet<T> set, string fromStringScore, string toStringScore, int? skip, int? take);
    List<T> GetRangeFromSortedSetByHighestScore(IRedisSortedSet<T> set, double fromScore, double toScore);
    List<T> GetRangeFromSortedSetByHighestScore(IRedisSortedSet<T> set, double fromScore, double toScore, int? skip, int? take);
    IDictionary<T, double> GetRangeWithScoresFromSortedSetByHighestScore(IRedisSortedSet<T> set, string fromStringScore, string toStringScore);
    IDictionary<T, double> GetRangeWithScoresFromSortedSetByHighestScore(IRedisSortedSet<T> set, string fromStringScore, string toStringScore, int? skip, int? take);
    IDictionary<T, double> GetRangeWithScoresFromSortedSetByHighestScore(IRedisSortedSet<T> set, double fromScore, double toScore);
    IDictionary<T, double> GetRangeWithScoresFromSortedSetByHighestScore(IRedisSortedSet<T> set, double fromScore, double toScore, int? skip, int? take);
    int RemoveRangeFromSortedSet(IRedisSortedSet<T> set, int minRank, int maxRank);
    int RemoveRangeFromSortedSetByScore(IRedisSortedSet<T> set, double fromScore, double toScore);
    int GetSortedSetCount(IRedisSortedSet<T> set);
    double GetItemScoreInSortedSet(IRedisSortedSet<T> set, T value);
    int StoreIntersectFromSortedSets(IRedisSortedSet<T> intoSetId, params IRedisSortedSet<T>[] setIds);
    int StoreUnionFromSortedSets(IRedisSortedSet<T> intoSetId, params IRedisSortedSet<T>[] setIds);

    bool HashContainsEntry<TKey>(IRedisHash<TKey, T> hash, TKey key);
    bool SetEntryInHash<TKey>(IRedisHash<TKey, T> hash, TKey key, T value);
    bool SetEntryInHashIfNotExists<TKey>(IRedisHash<TKey, T> hash, TKey key, T value);
    void SetRangeInHash<TKey>(IRedisHash<TKey, T> hash, IEnumerable<KeyValuePair<TKey, T>> keyValuePairs);
    T GetValueFromHash<TKey>(IRedisHash<TKey, T> hash, TKey key);
    bool RemoveEntryFromHash<TKey>(IRedisHash<TKey, T> hash, TKey key);
    int GetHashCount<TKey>(IRedisHash<TKey, T> hash);
    List<TKey> GetHashKeys<TKey>(IRedisHash<TKey, T> hash);
    List<T> GetHashValues<TKey>(IRedisHash<TKey, T> hash);
    Dictionary<TKey, T> GetAllEntriesFromHash<TKey>(IRedisHash<TKey, T> hash);
}

सामान्य डेटा एक्सेस इंटरफ़ेस #

उपरोक्त विधियों को शामिल करते हुए, जेनेरिक क्लाइंट Redis गैर-विशिष्ट सामान्य डेटा एक्सेस संचालन को भी लागू करता है जिसे अन्य डेटा दृढ़ता प्रदाताओं द्वारा आसानी से कार्यान्वित किया जा सकता है यदि आप भविष्य में प्रदाताओं को स्वैप करना चाहते हैं।

public interface IBasicPersistenceProvider<T>
    : IDisposable
{
    T GetById(string id);

    IList<T> GetByIds(ICollection<string> ids);

    IList<T> GetAll();

    T Store(T entity);

    void StoreAll(IEnumerable<T> entities);

    void Delete(T entity);

    void DeleteById(string id);

    void DeleteByIds(ICollection<string> ids);

    void DeleteAll();
}

आम तौर पर, यदि आपके पास केवल बुनियादी दृढ़ता की जरूरत है, तो मैं उपरोक्त सामान्य डेटा एक्सेस एपीआई के खिलाफ विकसित करने की सलाह दूंगा क्योंकि अन्य दृढ़ता प्रदाताओं के लिए इसे लागू करना आसान है और संभावित हुड को बढ़ाता है कि आपकी लाइब्रेरी का पुन:उपयोग किया जा सकता है-जैसा कि अन्य डेटा स्टोर के खिलाफ जारी रहना है यानी OrmLite, आदि के साथ RDBMS के खिलाफ।


  1. Redis
  2.   
  3. MongoDB
  4.   
  5. Memcached
  6.   
  7. HBase
  8.   
  9. CouchDB
  1. Laravel 5.5 रेडिस कतार बहुत धीमी है

  2. रीयल-टाइम स्टॉक एप्लिकेशन के लिए रेडिस कुंजी डिज़ाइन

  3. AWS वर्चुअल प्राइवेट क्लाउड (VPC) में Redis™ के लिए स्केलग्रिड DBaaS परिनियोजित करें

  4. डेटा प्रकार के चयन के लिए रेडिस सुझाव

  5. स्प्रिंग रेडिस एरर हैंडल