Get the App
SLTechnology News&Howtos  ›  Database  › 

Redis of NoSQL (Jedis connection API)

Shulou Source: shulou.com Published: 2022-06-01 11:40:48 09月20日 Update

Engineering construction:

(1) introduction: redis can be operated not only with commands, but also with client support in basically mainstream languages, such as java, C, C #, C++, php, Node.js, Go and so on.

Jedis is introduced here, address: https://github.com/xetorthio/jedis

(2) dependence:

If it is an ordinary project created: you need to add the jar package of the corresponding jedis.jar to the project.

If you are using maven, import the dependent dependency directly: https://mvnrepository.com/artifact/redis.clients/jedis

Redis.clients

Jedis

3.0.0

2.API

(1) single instance connects to redis

Public class JedisUtils {public void jedisClient () {/ * new Jedis (pars1,pars2); * pars1:hostname:String * port:int * / Jedis jedis=new Jedis ("hadoop03", 6379); / / assign jedis.set ("name", "zs") through redis; / / get the value String name=jedis.get ("name") through redis / / release resource jedis.close ();}}

(2) use jedis connection pool to connect to redis service

Public void jedisPoolClient () {/ * new JedisPool (pars1,pars2); * pars1:String, which can be written to a cluster such as redis01,redis03... * port:int port * / JedisPool pool=new JedisPool ("hadoop03", 6379); / obtain Jedis instance Jedis jedis=pool.getResource (); / / release resource jedis.close (); pool.close ();}

Tags: Instance Engineering Resource General mainstream Command address customer client language Cluster Project Centro support Service Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Xiaomi Shulou Technology Shulou Information Docker