html tool

显示标签为“redis”的博文。显示所有博文
显示标签为“redis”的博文。显示所有博文

2022年4月2日星期六

转:redis key的有效期查看

 https://blog.csdn.net/weixin_39530269/article/details/111837932



redis 查看keys 的有效期:


127.0.0.1:6379> ttl "shiro_redis_session:b4f107c6-e96c-4a1e-8402-a3be9a619847"


(integer) 1194


Redis TTL命令用于获取键到期的剩余时间(秒)。


返回值


以毫秒为单位的整数值TTL或负值


TTL以毫秒为单位。


-1, 如果key没有到期超时。


-2, 如果键不存在。


现在设置键到期,之后只需查看到期的剩余时间。


127.0.0.1:6379> set tutorialname 987789


OK


127.0.0.1:6379> get tutorialname


"987789"


127.0.0.1:6379> EXPIRE tutorialname 60


(integer) 1


127.0.0.1:6379> TTL tutorialname


(integer) 31


127.0.0.1:6379> TTL tutorialname


(integer) 30


2022年4月1日星期五

redis : info keyspaces

 https://www.cnblogs.com/hwpaas/p/9442410.html

keyspace 栏显示的每行信息格式如下所示: dbX: keys=X,expires=X,avg_ttl=X

其中,第一个 X 表示数据库的编号,第二个 X 表示键的数量,第三个 X 表示具有过期时间的键的数量,第四个 X 表示键的平均生存时间。举个例子:

db0:keys=6,expires=0,avg_ttl=0:这就表示当前数据库 0 的 key 总数有 6 个,带有过期时间的 key 总数 0 个,平均存活时间为 0。

2019年12月4日星期三

shell脚本获得redis中全部的值


  1 #!/usr/bin/env bash
  2 connect_redis="redis-cli -h 1.1.1.1 -p 6379 -a 123456 -n 0"
  3 #redis-cli -h 1.1.1.1 -p 6379 -a 123456 -n 0 keys  '*' | 
  4 ${connect_redis} keys  'api_privilege_*' |
  5 while read key
  6 do       
  7     key_type=`${connect_redis} type ${key}`
  8     if [[ "${key_type}"=="hash" ]] 
  9     then 
 10         key_val=`${connect_redis} hgetall    ${key}`
 11         #echo "${connect_redis} hgetall    ${key}"
 12     else 
 13         key_val=`${connect_redis} get   ${key}`
 14          
 15     fi   
 16     echo ${key},${key_val}
 17 done     



参考:https://blog.csdn.net/chinabestchina/article/details/79113177
其中:
-h 代表redis安装地址
-p 代表redis端口
-a 代表redis访问密码
-n 代表redis数据库的db index
PS:查看redis中使用的db index的方式
你可以使用以下命令来了解数据库的数量:
CONFIG GET databases
1) "databases"
2) "16"
也可以使用以下命令列出定义了某些键的数据库:
INFO keyspace
# Keyspace
db0:keys=10,expires=0
db1:keys=1,expires=0
db3:keys=1,expires=0

2017年11月2日星期四

转:java redis Demo

https://www.tutorialspoint.com/redis/redis_java.htm

import redis.clients.jedis.Jedis; 

public class RedisJava { 
   public static void main(String[] args) { 
      //Connecting to Redis server on localhost 
      Jedis jedis = new Jedis("localhost"); 
      System.out.println("Connection to server sucessfully"); 
      //check whether server is running or not 
      System.out.println("Server is running: "+jedis.ping()); 
   } 
} 

[popexizhi:
mvn pom.xml 依赖如下:
	
		redis.clients
		jedis
		2.8.1
	
可用版本参考:https://mvnrepository.com/artifact/redis.clients/jedis
]

________________________________________________________________________________________


-----------------------------------------------------
[popexizhi:1. redis 本地配置文件使用支持0.0.0.0的监听,默认启动使用的是127.0.0.12. redis-cli查看命令中 list 类型支持python的-1索引方式eg:LRANGE hi 0 -1
]
-----------------------------------------------------
其他类型数据参见: http://www.baeldung.com/jedis-java-redis-client-library
5.1. Strings
Strings are the most basic kind of Redis value, useful for when you need to persist simple key-value data types:
1
2
jedis.set("events/city/rome", "32,15,223,828");
String cachedResponse = jedis.get("events/city/rome");
The variable cachedResponse will hold the value 32,15,223,828. Coupled with expiration support, discussed later, it can work as a lightning fast and simple to use cache layer for HTTP requests received at your web application and other caching requirements.

5.2. Lists

Redis Lists are simply lists of strings, sorted by insertion order and make it an ideal tool to implement, for instance, message queues:
1
2
3
4
jedis.lpush("queue#tasks", "firstTask");
jedis.lpush("queue#tasks", "secondTask");
 
String task = jedis.rpop("queue#tasks");
The variable task will hold the value firstTask. Remember that you can serialize any object and persist it as a string, so messages in the queue can carry more complex data when required.

5.3. Sets

Redis Sets are an unordered collection of Strings that come in handy when you want to exclude repeated members:
1
2
3
4
5
6
jedis.sadd("nicknames", "nickname#1");
jedis.sadd("nicknames", "nickname#2");
jedis.sadd("nicknames", "nickname#1");
 
Set nicknames = jedis.smembers("nicknames");
boolean exists = jedis.sismember("nicknames", "nickname#1");
The Java Set nicknames will have a size of 2, the second addition of nickname#1 was ignored. Also, the existsvariable will have a value of true, the method sismember enables you to quickly check for the existence of a particular member.

5.4. Hashes

Redis Hashes are mapping between String fields and String values:
1
2
3
4
5
6
7
jedis.hset("user#1", "name", "Peter");
jedis.hset("user#1", "job", "politician");
         
String name = jedis.hget("user#1", "name");
         
Map fields = jedis.hgetAll("user#1");
String job = fields.get("job");
As you can see, hashes are a very convenient data type when you want to access object’s properties individually since you do not need to retrieve the whole object.