Giter Site home page Giter Site logo

java-redis's Introduction

redis

install

code ~/.bash_profile

alias "redis_start= ~/redis/src/redis-server"
alias "redis= ~/redis/src/redis-cli"

source ~/.bash_profile

documentação

acessar client

redis
// 127.0.0.1:6379>

adicionar no cache via client

FLUSHALL # limpa todo cache


set key value # adiciona no cache 
get key # busca do cache 
set "nome" "danilo" EX 10 # com tempo de expiração em segundos

lpush "fila" "item1" # adiciona na fila
rpop "fila" # busca da fila na fila


# adiciona no array
sadd "membros" "danilo"
sadd "membros" "lana"
sadd "membros" "sheila"
# busca o array
smembers "membros"
# valida no array o array
sismember "membros" "sheila"


# adiciona no hash
hset "usuario" "nome" "Danilo"
hset "usuario" "cpf" "339839389383"
hset "usuario" "telefone" "(11)99999-9999"
# busca do hash        
hget "usuario" "nome"
# busca hash todo     
hgetAll "usuario"

criando projeto

mvn archetype:generate -DgroupId=br.com.redis -DartifactId=redis -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false

doc mvn

https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html

gerar com manifest

https://www.sohamkamani.com/java/cli-app-with-maven/

como rodar

./buld.sh
./start.sh

dependencias

<dependency>
    <groupId>redis.clients</groupId>
    <artifactId>jedis</artifactId>
    <version>4.2.2</version>
</dependency>

criando instancia

Jedis jedis = new Jedis("http://localhost:6379");

utilizando redis para gravar e ler strings

jedis.set("chave", "um valor");
String cachedResponse = jedis.get("chave");

Push/Pop

jedis.lpush("fila", "item1");
jedis.lpush("fila", "item2");

String pop1 = jedis.rpop("fila");
String pop2 = jedis.rpop("fila");

Sets(Array)

jedis.sadd("membros", "danilo");
jedis.sadd("membros", "lana");
jedis.sadd("membros", "sheila");

Set<String> membros = jedis.smembers("membros");
boolean isMember = jedis.sismember("membros", "sheila");

Hashes

jedis.hset("usuario", "nome", "Danilo");
jedis.hset("usuario", "cpf", "339839389383");
jedis.hset("usuario", "telefone", "(11)99999-9999");
        
String nome = jedis.hget("usuario", "nome");
        
Map<String, String> fields = jedis.hgetAll("usuario");
String cpf = fields.get("cpf");

mais infos

java-redis's People

Contributors

didox avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.