Skip to content

DarkIdiot/RedisCache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

92 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Redis Cache

Tips:

 required: JDK1.5+

Overview

RedisCache是基于Jedis的SDK。

  • ①强大的泛型支持,实现了任意java对象简单存\取
  • ②增强缓存接口:支持防穿透设计,以及本地缓存同步更新
  • ③提供多种分布式锁分布式队列支持
  • ④个性化的redis源配置支持

Usage:

RedisCache

Normal Style

    IRedisMap<Integer, User> cache = Redis.use("redisSourceName");
    User user = new User();
    cache.put(1001,user);
    User redisUser = cache.get(1001);

Fluent Style

    IRedisMap<Integer, User> cache = Redis.create().setServiceName("redisSourceName").build();
    User user = new User();
    cache.put(1001,user);
    User redisUser = cache.get(1001);

RedisLock

Normal Style

    Lock lock = RedisLock.useSimpleRedisLock("simpleLock", "redisSourceName");
    try {
        lock.lock();
        lock.isLocking();
    } finally {
        lock.unlock();
    }

Fluent Style

    Lock lock = RedisLock.create().setService("redisSourceName").setLockName("simpleLock").useSimpleRedisLock();
    try {
        lock.lock();
        lock.isLocking();
    } finally {
        lock.unlock();
    }

RedisQueue

Normal Style

    Queue<Task> queue = RedisQueue.useSimpleFifoQueue("simpleQueue","redisSourceName");
    queue.enqueue(task1,task2,task3);
    Task task = queue.dequeue();

Fluent Style

    Queue<Task> queue = RedisQueue.create().setService("redisSourceName").setQueueName("simpleQueue").useSimpleFifoQueue();
    queue.enqueue(task1,task2,task3);
    Task task = queue.dequeue();

Configuration

pattern I @for connection@

service.names=redisSourceName,redisSourceName1,...

Stand-Alone

redisSourceName.ip = 127.0.0.1
redisSourceName.port = 6379
redisSourceName.password=password

Simplified Way

redisSourceName.ip-port-password = 127.0.0.1:6379?password

Sentinel

redisSourceName1.is.cluster = true
redisSourceName1.sentinel.master.name = masterName
redisSourceName1.sentinel.hosts = 127.0.0.1:6379;127.0.0.1:6389;127.0.0.1:6379;127.0.0.1:6399
redisSourceName1.password = password

pattern II @for basic@

redisSourceName.open.local.cache = true
redisSourceName[.read].timeoutInMillis = 10000
redisSourceName[.write].timeoutInMillis = 10000
redisSourceName[.read].maxTotal = 8
redisSourceName[.write].maxTotal = 8
redisSourceName[.read].maxIdle = 20
redisSourceName[.write].maxIdle = 20
redisSourceName[.read].maxWait = 2000
redisSourceName[.write].maxWait = 2000
redisSourceName[.read].testOnBorrow = true
redisSourceName[.write].testOnBorrow = true
redisSourceName[.read].testOnReturn = false
redisSourceName[.write].testOnReturn = false

Dependencies:

<dependencies>
    <dependency>
        <groupId>redis.clients</groupId>
        <artifactId>jedis</artifactId>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
    </dependency>
    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
    </dependency>
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
    </dependency>
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
    </dependency>
</dependencies>

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages