Search in sources :

Example 6 with RedisClient

use of io.lettuce.core.RedisClient in project yyl_example by Relucent.

the class LettuceExample method main.

public static void main(String[] args) {
    RedisClient client = RedisClient.create(RedisURI.create("redis://localhost/"));
    try (StatefulRedisConnection<String, String> conn = client.connect()) {
        RedisCommands<String, String> command = conn.sync();
        command.set("hello", "hello lettuce");
        String value = command.get("hello");
        System.out.println(value);
    }
}
Also used : RedisClient(io.lettuce.core.RedisClient)

Example 7 with RedisClient

use of io.lettuce.core.RedisClient in project verify-hub by alphagov.

the class PolicyModule method getRedisSessionStore.

private RedisSessionStore getRedisSessionStore(RedisConfiguration config) {
    RedisClient redisClient = RedisClient.create();
    redisClient.setDefaultTimeout(config.getTimeout());
    StatefulRedisMasterSlaveConnection<SessionId, State> redisConnection = MasterSlave.connect(redisClient, new SessionStoreRedisCodec(getRedisObjectMapper()), singletonList(config.getUri()));
    RedisCommands<SessionId, State> redisCommands = redisConnection.sync();
    return new RedisSessionStore(redisCommands, config.getRecordTTL());
}
Also used : RedisClient(io.lettuce.core.RedisClient) State(uk.gov.ida.hub.policy.domain.State) SessionStoreRedisCodec(uk.gov.ida.hub.policy.redis.SessionStoreRedisCodec) SessionId(uk.gov.ida.hub.policy.domain.SessionId) RedisSessionStore(uk.gov.ida.hub.policy.session.RedisSessionStore)

Example 8 with RedisClient

use of io.lettuce.core.RedisClient in project verify-hub by alphagov.

the class SamlEngineModule method getIdExpirationCache.

private <T> IdExpirationCache<T> getIdExpirationCache(RedisConfiguration config, RedisCodec<T, DateTime> codec, int dbIndex) {
    RedisClient redisClient = RedisClient.create();
    redisClient.setDefaultTimeout(config.getTimeout());
    RedisURI uri = config.getUri();
    uri.setDatabase(dbIndex);
    StatefulRedisMasterSlaveConnection<T, DateTime> redisConnection = MasterSlave.connect(redisClient, codec, singletonList(uri));
    RedisCommands<T, DateTime> redisCommands = redisConnection.sync();
    return new RedisIdExpirationCache<>(redisCommands, config.getRecordTTL());
}
Also used : RedisClient(io.lettuce.core.RedisClient) RedisURI(io.lettuce.core.RedisURI) RedisIdExpirationCache(uk.gov.ida.hub.samlengine.security.RedisIdExpirationCache) DateTime(org.joda.time.DateTime)

Example 9 with RedisClient

use of io.lettuce.core.RedisClient in project jetcache by alibaba.

the class MultiLevelCacheMixTest method testWithLettuce.

@Test
public void testWithLettuce() {
    l1Cache = CaffeineCacheBuilder.createCaffeineCacheBuilder().limit(10).expireAfterWrite(1000, TimeUnit.MILLISECONDS).keyConvertor(FastjsonKeyConvertor.INSTANCE).buildCache();
    RedisClient client = RedisClient.create("redis://127.0.0.1");
    l2Cache = RedisLettuceCacheBuilder.createRedisLettuceCacheBuilder().redisClient(client).keyConvertor(FastjsonKeyConvertor.INSTANCE).valueEncoder(JavaValueEncoder.INSTANCE).valueDecoder(JavaValueDecoder.INSTANCE).keyPrefix(new Random().nextInt() + "").expireAfterWrite(1000, TimeUnit.MILLISECONDS).buildCache();
    cache = MultiLevelCacheBuilder.createMultiLevelCacheBuilder().addCache(l1Cache, l2Cache).buildCache();
    testImpl();
}
Also used : RedisClient(io.lettuce.core.RedisClient) Random(java.util.Random) Test(org.junit.jupiter.api.Test)

Example 10 with RedisClient

use of io.lettuce.core.RedisClient in project jetcache by alibaba.

the class RedisLettuceCacheTest method testSimple.

@Test
public void testSimple() throws Exception {
    RedisClient client = RedisClient.create("redis://127.0.0.1");
    test(client, null);
}
Also used : RedisClient(io.lettuce.core.RedisClient) AbstractRedisClient(io.lettuce.core.AbstractRedisClient) LoadingCacheTest(com.alicp.jetcache.LoadingCacheTest) AbstractExternalCacheTest(com.alicp.jetcache.test.external.AbstractExternalCacheTest) Test(org.junit.Test)

Aggregations

RedisClient (io.lettuce.core.RedisClient)11 Test (org.junit.Test)6 LoadingCacheTest (com.alicp.jetcache.LoadingCacheTest)4 AbstractExternalCacheTest (com.alicp.jetcache.test.external.AbstractExternalCacheTest)4 AbstractRedisClient (io.lettuce.core.AbstractRedisClient)4 RedisURI (io.lettuce.core.RedisURI)3 Random (java.util.Random)3 StatefulRedisConnection (io.lettuce.core.api.StatefulRedisConnection)2 RedisAsyncCommands (io.lettuce.core.api.async.RedisAsyncCommands)2 Cache (com.alicp.jetcache.Cache)1 RedisLettuceCacheTest (com.alicp.jetcache.redis.lettuce.RedisLettuceCacheTest)1 SpringTest (com.alicp.jetcache.test.spring.SpringTest)1 RedisReactiveCommands (io.lettuce.core.api.reactive.RedisReactiveCommands)1 RedisCommands (io.lettuce.core.api.sync.RedisCommands)1 RedisClusterClient (io.lettuce.core.cluster.RedisClusterClient)1 RedisClusterAsyncCommands (io.lettuce.core.cluster.api.async.RedisClusterAsyncCommands)1 RedisClusterReactiveCommands (io.lettuce.core.cluster.api.reactive.RedisClusterReactiveCommands)1 RedisClusterCommands (io.lettuce.core.cluster.api.sync.RedisClusterCommands)1 StatefulRedisMasterSlaveConnection (io.lettuce.core.masterslave.StatefulRedisMasterSlaveConnection)1 DateTime (org.joda.time.DateTime)1