site.dunhanson.redis:easy-redis

easy redis

License

License

Categories

Categories

Redis Data Databases
GroupId

GroupId

site.dunhanson.redis
ArtifactId

ArtifactId

easy-redis
Last Version

Last Version

1.0.2-alpha-2
Release Date

Release Date

Type

Type

jar
Description

Description

site.dunhanson.redis:easy-redis
easy redis
Project URL

Project URL

https://github.com/dunhanson/easy-redis
Source Code Management

Source Code Management

https://github.com/dunhanson/easy-redis

Download easy-redis

How to add to project

<!-- https://jarcasting.com/artifacts/site.dunhanson.redis/easy-redis/ -->
<dependency>
    <groupId>site.dunhanson.redis</groupId>
    <artifactId>easy-redis</artifactId>
    <version>1.0.2-alpha-2</version>
</dependency>
// https://jarcasting.com/artifacts/site.dunhanson.redis/easy-redis/
implementation 'site.dunhanson.redis:easy-redis:1.0.2-alpha-2'
// https://jarcasting.com/artifacts/site.dunhanson.redis/easy-redis/
implementation ("site.dunhanson.redis:easy-redis:1.0.2-alpha-2")
'site.dunhanson.redis:easy-redis:jar:1.0.2-alpha-2'
<dependency org="site.dunhanson.redis" name="easy-redis" rev="1.0.2-alpha-2">
  <artifact name="easy-redis" type="jar" />
</dependency>
@Grapes(
@Grab(group='site.dunhanson.redis', module='easy-redis', version='1.0.2-alpha-2')
)
libraryDependencies += "site.dunhanson.redis" % "easy-redis" % "1.0.2-alpha-2"
[site.dunhanson.redis/easy-redis "1.0.2-alpha-2"]

Dependencies

compile (6)

Group / Artifact Type Version
redis.clients : jedis jar 3.2.0
org.slf4j : slf4j-api jar 1.7.30
org.apache.commons : commons-lang3 jar 3.9
site.dunhanson.utils : basic-utils jar 1.0.1
commons-beanutils : commons-beanutils jar 1.9.4
cn.hutool : hutool-all jar 5.3.8

provided (1)

Group / Artifact Type Version
org.projectlombok : lombok jar 1.18.12

test (2)

Group / Artifact Type Version
junit : junit jar 4.13
org.slf4j : slf4j-log4j12 jar 1.7.30

Project Modules

There are no modules declared in this project.

Easy Redis

simplify redis operations

Maven

<dependency>
  <groupId>site.dunhanson.redis</groupId>
  <artifactId>easy-redis</artifactId>
  <version>1.0.1</version>
</dependency>

Config

redis.yaml

redis:
  type: single
  single:
    host: localhost
    port: 6379
    password:
  cluster:
    type: sentinel
    sentinel:
      masterName: mymaster
      password: bxkc2016
      hostAndPort:
        - 192.168.2.170:26377
        - 192.168.2.170:26378
        - 192.168.2.170:26379

Start

public class JedisTest {
    @Test
    public void start() {
        try (Jedis jedis = JedisUtils.get()){
            jedis.set("test", "hello world");
            System.out.println(jedis.get("test"));
        }
    }

    @Test
    public void byteSetTest() {
        try (Jedis jedis = JedisUtils.get()){
            // value
            Map<String, Object> map = new HashMap<>();
            map.put("a", "aaa");
            map.put("b", "bbb");
            map.put("c", "ccc");
            // set
            byte[] key = "test".getBytes();
            byte[] value = ObjectUtils.toByteArray(map);
            String result = jedis.set(key, value);
            System.out.println(result);
        }
    }

    @Test
    public void byteSetExTest() {
        try (Jedis jedis = JedisUtils.get()){
            // value
            Map<String, Object> map = new HashMap<>();
            map.put("1", "aaa");
            map.put("2", "bbb");
            map.put("3", "ccc");
            // set
            byte[] key = "test".getBytes();
            byte[] value = ObjectUtils.toByteArray(map);
            int time = 10;
            String result = jedis.setex(key, time, value);
            System.out.println(result);
        }
    }

    @Test
    public void byteSetNxTest() {
        try (Jedis jedis = JedisUtils.get()){
            // value
            Map<String, Object> map = new HashMap<>();
            map.put("1", "aaa");
            map.put("2", "bbb");
            map.put("3", "ccc");
            // set
            byte[] key = "test".getBytes();
            byte[] value = ObjectUtils.toByteArray(map);
            // nx
            Long result = jedis.setnx(key, value);
            System.out.println(result);
        }
    }

    @Test
    public void byteGetTest() {
        try (Jedis jedis = JedisUtils.get()){
            byte[] key = "test".getBytes();
            byte[] value = jedis.get(key);
            // get
            Map<String, Object> map = ObjectUtils.toEntity(value);
            System.out.println(map);
        }
    }
}

Plan

  • Single-node schema add database pool

References

https://github.com/xetorthio/jedis

Versions

Version
1.0.2-alpha-2
1.0.2-alpha-1
1.0.2-alpha
1.0.1
1.0.0