com.ibm.storage.clientlibrary

Class RedisCache<K,V>

    • Constructor Summary

      Constructors 
      Constructor and Description
      RedisCache(redis.clients.jedis.Jedis jedisCache, long defaultLifespan)
      Constructor in which already-created Jedis instance is passed in to be used as underlying cache.
      RedisCache(String host, int port, int timeout, long defaultLifespan)
      Constructor creating Jedis instance
      RedisCache(String host, int port, long defaultLifespan)
      Constructor creating Jedis instance
      RedisCache(String host, long defaultLifespan)
      Constructor creating Jedis instance
    • Constructor Detail

      • RedisCache

        public RedisCache(String host,
                          long defaultLifespan)
        Constructor creating Jedis instance
        Parameters:
        host - host where Redis is running
        defaultLifespan - Default life time in milliseconds for cached objects
      • RedisCache

        public RedisCache(String host,
                          int port,
                          long defaultLifespan)
        Constructor creating Jedis instance
        Parameters:
        host - host where Redis is running
        port - port number
        defaultLifespan - Default life time in milliseconds for cached objects
      • RedisCache

        public RedisCache(String host,
                          int port,
                          int timeout,
                          long defaultLifespan)
        Constructor creating Jedis instance
        Parameters:
        host - host where Redis is running
        port - port number
        timeout - number of seconds before Jedis closes an idle connection
        defaultLifespan - Default life time in milliseconds for cached objects
      • RedisCache

        public RedisCache(redis.clients.jedis.Jedis jedisCache,
                          long defaultLifespan)
        Constructor in which already-created Jedis instance is passed in to be used as underlying cache. This constructor is for situations in which application wants access to Jedis instance so that it can directly make Jedis method calls on the Jedis instance.
        Parameters:
        jedisCache - Existing Jedis instance to be used as underlying cache
        defaultLifespan - Default life time in milliseconds for cached objects
    • Method Detail

      • clear

        public void clear()
        delete all key-value pairs from the current database
        Specified by:
        clear in interface Cache<K,V>
      • close

        public void close()
        Close a Redis connection
      • delete

        public void delete(K key)
        delete a key-value pair from the cache
        Specified by:
        delete in interface Cache<K,V>
        Parameters:
        key - key corresponding to value
      • deleteAll

        public void deleteAll(List<K> keys)
        delete one or more key-value pairs from the cache
        Specified by:
        deleteAll in interface Cache<K,V>
        Parameters:
        keys - iterable data structure containing the keys to delete
      • flushAll

        public String flushAll()
        delete all key-value pairs from all databases
        Returns:
        status code reply
      • get

        public V get(K key)
        look up a value in the cache
        Specified by:
        get in interface Cache<K,V>
        Parameters:
        key - key corresponding to value
        Returns:
        value corresponding to key, null if key is not in cache or if value is expired
      • getAll

        public Map<K,V> getAll(List<K> keys)
        look up one or more values in the cache. Don't return expired values.
        Specified by:
        getAll in interface Cache<K,V>
        Parameters:
        keys - iterable data structure containing the keys to look up
        Returns:
        map containing key-value pairs corresponding to unexpired data in the cache
      • getCacheEntry

        public CacheEntry<V> getCacheEntry(K key)
        look up a CacheEntry in the cache. The CacheEntry may correspond to expired data. This method can be used to revalidate cached objects whose expiration times have passed
        Specified by:
        getCacheEntry in interface Cache<K,V>
        Parameters:
        key - key corresponding to value
        Returns:
        value corresponding to key (may be expired), null if key is not in cache
      • getStatistics

        public RedisCacheStats getStatistics()
        get cache statistics. For Redis, cache statistics are contained in a string. The string is returned by RedisCacheStats.getStats()
        Specified by:
        getStatistics in interface Cache<K,V>
        Returns:
        data structure containing statistics
      • printCacheEntry

        public String printCacheEntry(K key)
        Return string representing a cache entry corresponding to a key (or indicate if the key is not in the cache).
        Parameters:
        key - key corresponding to value
        Returns:
        string containing output
      • put

        public void put(K key,
                        V value)
        cache a key-value pair
        Specified by:
        put in interface Cache<K,V>
        Parameters:
        key - key associated with value
        value - value associated with key
      • put

        public void put(K key,
                        V value,
                        long lifetime)
        cache a key-value pair
        Specified by:
        put in interface CacheWithLifetimes<K,V>
        Parameters:
        key - key associated with value
        value - value associated with key
        lifetime - lifetime in milliseconds associated with data
      • putAll

        public void putAll(Map<K,V> map)
        cache one or more key-value pairs
        Specified by:
        putAll in interface Cache<K,V>
        Parameters:
        map - map containing key-value pairs to cache
      • putAll

        public void putAll(Map<K,V> map,
                           long lifetime)
        cache one or more key-value pairs
        Specified by:
        putAll in interface CacheWithLifetimes<K,V>
        Parameters:
        map - map containing key-value pairs to cache
        lifetime - lifetime in milliseconds associated with each key-value pair
      • size

        public long size()
        Return number of objects in cache
        Specified by:
        size in interface Cache<K,V>
        Returns:
        number of objects in cache
      • toString

        public String toString(String charset)
        Output contents of current database to a string.
        Parameters:
        charset - Character set representing keys, if not default
        Returns:
        string containing output
      • toString

        public String toString()
        Output contents of current database to a string.
        Overrides:
        toString in class Object
        Returns:
        string containing output

Copyright © 2015. All rights reserved.