当前位置:网站首页>One of the first steps to redis
One of the first steps to redis
2022-07-01 14:42:00 【Crystal sugar rain】
Set the background process

Get into redis.conf Medium 136 Change line to yes Set the background process
- modify bind , Change to qianfeng01
- Change password Find No 500 Row or so requorepass Change to 123456
- Login code
see ps -ef | grep redis
①redis-server /usr/local/redis/redis.conf
redis-cli -h qianfeng01 -p 6379 -a password
②redis-cli -h qianfeng01 -p 6379 -a 123456
Common codes entered :
Select indexid 0-15 Switch Library
Flushdb Clean up the current library
Flushall Clean up all libraries
1. # Query relevant information according to matching pattern key
keys * # Query all key
keys ?O* # The second character of the query is O Of key
2. dbsize # View all under the current library key The number of
3. exists key # Judge a certain key Whether there is , 0 Does not exist ,1 Indicates presence
4. type key # see key The type of
5. del key # Delete a key 1 Indicates that the deletion was successful 0 Indicates that deletion failed
6. unlink key # Delete a key( Non blocking delete )
# Only will key from keyspace Delete from metadata , The real deletion will be deleted asynchronously in the follow-up ( The meaning of playing first and then cutting )
7. expire key seconds # Set up key Life time of
8. persist key # eliminate key Life time of , There's no point in clearing that's expired
9. ttl key # see key Life time of -2 Indicates expiration -1 Never expire
set The syntax format of the instruction :set key value [EX seconds] [PX milliseconds] [NX|XX]
EX: KV Life time of , The unit is seconds
PX: KV Life time of , In milliseconds
NX: K When there is no , Will be set successfully
XX: K Preexisting time , Will be covered
get The syntax format of the instruction :
get key
append city shanghai <== stay key Corresponding to the original value Add character string
About operation
set num 1
decr num <== Decline 1 requirement value The type of is plastic
decrb num 5 <== Decline 5 Specify the step size
incr num <== Self increasing +1
incrby num 2 <== Specifies the self increasing step size
About strings
get city "beijingshanghai"
getrange city 0 2 Before and after the bag Intercepting string
getsetcity shenyang <== Override value , And return the original value
Set up multiple pairs
mset username zhangsan age 23 gender f isMarry false <== Set up multiple pairs KV
mget username age gender isMarry num <== Get multiple Key Of value value
api Realization
package com.qf;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.params.SetParams;
import java.util.ArrayList;
import java.util.List;
public class RedisDemo03_String {
public static void main(String[] args) {
setOfString();
getOfString();
}
//set Test of command
public static void setOfString(){
Jedis jedis = new Jedis("qianfeng01",6379);
jedis.auth("123456");
jedis.set("classno","sz2103");
SetParams setParams = new SetParams(); // Parameterless constructors
setParams.ex(100); // Survival time
//setParams.px(5000);
jedis.set("teahcer","cidy",setParams);
jedis.setnx("teaher1","anjing");
jedis.append("city","is good"); // Add to the existing
jedis.incr("num");
jedis.incrBy("num",3);
jedis.mset("k1","100","k2","200");
jedis.close();
}
//get Test of command
public static void getOfString(){
Jedis jedis = new Jedis("qianfeng01",6379);
jedis.auth("123456");
String classno = jedis.get("classno"); //get(key)
System.out.println("classno:"+classno);
String teacher = jedis.get("teacher");
System.out.println("teahcer"+teacher);
Long teacherTTL = jedis.ttl("teacher"); // Survival time
System.out.println("teacherTTL:"+teacherTTL);
String teaher1 = jedis.get("teacher1");
System.out.println("teacher1:"+teaher1);
String city = jedis.get("city");
System.out.println("city"+city);
String num = jedis.get("num");
System.out.println(num);
List<String> list = jedis.mget("k1", "k2"); // For many ky The traversal Print the value
for (String s : list){
System.out.println(s);
}
jedis.close();
}
}
hashes type
# hset The syntax of the command :
hset key field value
hmset key field value [field value ...]
# hget The syntax of the command :
hget key field
hmget key field [field ...]
qianfeng01:6379> hset people username lucy <== Set up people The value of the name field
(integer) 1
qianfeng01:6379> hmset people age 24 gender m isMarry true <== Set up people The values of the other fields of the
OK
qianfeng01:6379> hget people username <== obtain people The value of the name field
"lucy"
qianfeng01:6379> hmget people username age gender isMarry <== obtain people The values of multiple fields of
1) "lucy"
2) "24"
3) "m"
4) "true"
qianfeng01:6379> hdel people username isMarry <== Delete people Multiple fields for
(integer) 2
qianfeng01:6379> hgetall people <== obtain people All fields and values of
1) "age"
2) "24"
3) "gender"
4) "m"
qianfeng01:6379> HEXISTS people gender <== Judge gender Whether the field exists , 1 Indicates presence , 0 Does not exist
(integer) 1
qianfeng01:6379> HEXISTS people isMarry
(integer) 0
qianfeng01:6379> HINCRBY people age 4 <== For integer types field Add Numbers
(integer) 28
qianfeng01:6379> hkeys people <== obtain hash All types of fields
1) "age"
2) "gender"
qianfeng01:6379> HLEN people <== obtain hash Type of fields The number of
(integer) 2
qianfeng01:6379> hsetnx people isMarry false <== Set the value of the field , If it doesn't exist , Just succeed , If there is , Just report a mistake
(integer) 1
qianfeng01:6379> hsetnx people isMarry true <== 0 I'm not successful ,1 It means success
(integer) 0
qianfeng01:6379> hget people isMarry
"false"
qianfeng01:6379> HSTRLEN people isMarry <== Get the specified field Of value String length of
(integer) 5
qianfeng01:6379> hvals people <== obtain hash All types of value
1) "28"
2) "m"
3) "false"
Api
package com.qf; import redis.clients.jedis.Jedis; import java.util.HashMap; import java.util.Map; import java.util.Set; public class RedisDemo04 { public static void main(String[] args) { hsetOfHash(); hgetOfHash(); } public static void hsetOfHash(){ Jedis jedis = new Jedis("qianfeng01",6379); jedis.auth("123456"); Map<String,String> map = new HashMap<>(); map.put("product_id","1091"); map.put("product_name","thinkpadt760"); map.put("product_desc"," Good series "); map.put("product_warehouse","901"); map.put("product_evaluation"," very nice "); jedis.hmset("product_clothing_1001",map); jedis.close(); } public static void hgetOfHash(){ Jedis jedis = new Jedis("qianfeng01",6379); jedis.auth("123456"); if(jedis.exists("product_clothing_1001")){ Map<String,String> map = jedis.hgetAll("product_clothing_1001"); Set<Map.Entry<String,String>> entries = map.entrySet(); for(Map.Entry<String,String> entry :entries ){ System.out.println(entry.getKey()+"\t"+entry.getValue()); } } jedis.close(); } }
边栏推荐
- Phpcms realizes the direct Alipay payment function of orders
- What value can NPDP bring to product managers? Do you know everything?
- Blog recommendation | in depth study of message segmentation in pulsar
- 博文推荐 | 深入研究 Pulsar 中的消息分块
- Opencv mat class
- One of the data Lake series | you must love to read the history of minimalist data platforms, from data warehouse, data lake to Lake warehouse
- Research Report on the development trend and competitive strategy of the global traditional computer industry
- sqlilabs less-8
- [零基础学IoT Pwn] 复现Netgear WNAP320 RCE
- How can we protect our passwords?
猜你喜欢

Play with grpc - communication between different programming languages

"National defense seven sons" funding soared, with Tsinghua reaching 36.2 billion yuan, ranking second with 10.1 billion yuan. The 2022 budget of national colleges and universities was made public

Using CMD to repair and recover virus infected files

Blog recommendation | in depth study of message segmentation in pulsar

Phpcms realizes the direct Alipay payment function of orders
![[zero basic IOT pwn] reproduce Netgear wnap320 rce](/img/f7/d683df1d4b1b032164a529d3d94615.png)
[zero basic IOT pwn] reproduce Netgear wnap320 rce

What problems should be considered for outdoor LED display?

微服务大行其道的今天,Service Mesh是怎样一种存在?

Tdengine connector goes online Google Data Studio app store

Why did you win the first Taosi culture award of 20000 RMB if you are neither a top R & D expert nor a sales Daniel?
随机推荐
643. Maximum average number of subarrays I
Pat 1065 a+b and C (64bit) (20 points) (16 points)
Research Report on the development trend and competitive strategy of the global electromagnetic flowmeter industry
[commercial terminal simulation solution] Shanghai daoning brings you Georgia introduction, trial and tutorial
问题随记 —— Oracle 11g 卸载
Music player development example (can be set up)
Summary of leetcode's dynamic programming 5
sqlilabs less9
微服务开发步骤(nacos)
Buuctf reinforcement question ezsql
使用net core 6 c# 的 NPOI 包,讀取excel..xlsx單元格內的圖片,並存儲到指定服務器
Research Report on the development trend and competitive strategy of the global chemical glassware industry
About the use of HTTP cache validation last modified and Etag
适合没口才的人做,加入中视频伙伴计划收益是真香,一个视频拿3份收益
[stage life summary] I gave up the postgraduate entrance examination and participated in the work. I have successfully graduated and just received my graduation certificate yesterday
SQLAchemy 常用操作
使用net core 6 c# 的 NPOI 包,读取excel..xlsx单元格内的图片,并存储到指定服务器
Provincial election + noi Part IX game theory
Effet halo - qui dit qu'il y a de la lumière sur la tête est un héros
How can we protect our passwords?