• jedis操作


    package com.taotao.jedis;

    public interface JedisClient {

    String set(String key, String value);
    String get(String key);
    Boolean exists(String key);
    Long expire(String key, int seconds);
    Long ttl(String key);
    Long incr(String key);
    Long hset(String key, String field, String value);
    String hget(String key, String field);
    Long hdel(String key, String... field);
    }


    package com.taotao.jedis;

    import org.springframework.beans.factory.annotation.Autowired;

    import redis.clients.jedis.JedisCluster;

    public class JedisClientCluster implements JedisClient {

    @Autowired
    private JedisCluster jedisCluster;

    @Override
    public String set(String key, String value) {
    return jedisCluster.set(key, value);
    }

    @Override
    public String get(String key) {
    return jedisCluster.get(key);
    }

    @Override
    public Boolean exists(String key) {
    return jedisCluster.exists(key);
    }

    @Override
    public Long expire(String key, int seconds) {
    return jedisCluster.expire(key, seconds);
    }

    @Override
    public Long ttl(String key) {
    return jedisCluster.ttl(key);
    }

    @Override
    public Long incr(String key) {
    return jedisCluster.incr(key);
    }

    @Override
    public Long hset(String key, String field, String value) {
    return jedisCluster.hset(key, field, value);
    }

    @Override
    public String hget(String key, String field) {
    return jedisCluster.hget(key, field);
    }

    @Override
    public Long hdel(String key, String... field) {
    return jedisCluster.hdel(key, field);
    }

    }


    package com.taotao.jedis;


    import org.springframework.beans.factory.annotation.Autowired;


    import redis.clients.jedis.Jedis;
    import redis.clients.jedis.JedisPool;


    public class JedisClientPool implements JedisClient {

    @Autowired
    private JedisPool jedisPool;


    @Override
    public String set(String key, String value) {
    Jedis jedis = jedisPool.getResource();
    String result = jedis.set(key, value);
    jedis.close();
    return result;
    }


    @Override
    public String get(String key) {
    Jedis jedis = jedisPool.getResource();
    String result = jedis.get(key);
    jedis.close();
    return result;
    }


    @Override
    public Boolean exists(String key) {
    Jedis jedis = jedisPool.getResource();
    Boolean result = jedis.exists(key);
    jedis.close();
    return result;
    }


    @Override
    public Long expire(String key, int seconds) {
    Jedis jedis = jedisPool.getResource();
    Long result = jedis.expire(key, seconds);
    jedis.close();
    return result;
    }


    @Override
    public Long ttl(String key) {
    Jedis jedis = jedisPool.getResource();
    Long result = jedis.ttl(key);
    jedis.close();
    return result;
    }


    @Override
    public Long incr(String key) {
    Jedis jedis = jedisPool.getResource();
    Long result = jedis.incr(key);
    jedis.close();
    return result;
    }


    @Override
    public Long hset(String key, String field, String value) {
    Jedis jedis = jedisPool.getResource();
    Long result = jedis.hset(key, field, value);
    jedis.close();
    return result;
    }


    @Override
    public String hget(String key, String field) {
    Jedis jedis = jedisPool.getResource();
    String result = jedis.hget(key, field);
    jedis.close();
    return result;
    }


    @Override
    public Long hdel(String key, String... field) {
    Jedis jedis = jedisPool.getResource();
    Long result = jedis.hdel(key, field);
    jedis.close();
    return result;
    }


    }

  • 相关阅读:
    ERP SYSTEM 开发指南(一)简单模块开发
    机器学习--决策树
    机器学习---线性模型
    机器学习
    《IDA Pro 权威指南》学习
    内核漏洞利用技术
    word2vec、seq2seq
    Ring0级的探索
    ActiveX 控件的漏洞挖掘
    FTP的漏洞挖掘
  • 原文地址:https://www.cnblogs.com/chinaifae/p/10254369.html
Copyright © 2020-2023  润新知