Redis 常用操作
import org.junit.Before;
import org.junit.Test;
import redis.clients.jedis.Jedis; import java.util.Set;
public class RedisUtilTest { private Jedis jedis; @Before
public void setup(){
//连接redis服务器,localhost:6379
jedis = new Jedis("localhost", );
//权限认证
jedis.auth("");
} /**
* 通过手机号删除缓存
*/
@Test
public void testDelByPhoneNum(){
Set<String> set = jedis.keys("*15555555555*");
System.out.println(set);
for(String key: set){
jedis.del(key);
System.out.println("【"+key+"】have deleted!");
}
}
}
keys public Set<String> keys(String pattern)
Returns all the keys matching the glob-style pattern as space separated strings. For example if you have in the database the keys "foo" and "foobar" the command "KEYS foo*" will return "foo foobar".
Note that while the time complexity for this operation is O(n) the constant times are pretty low. For example Redis running on an entry level laptop can scan a million keys database in milliseconds. Still it's better to consider this one of the slow commands that may ruin the DB performance if not used with care. In other words this command is intended only for debugging and special operations like creating a script to change the DB schema. Don't use it in your normal code. Use Redis Sets in order to group together a subset of objects. Glob style patterns examples: h?llo will match hello hallo hhllo
h*llo will match hllo heeeello
h[ae]llo will match hello and hallo, but not hillo
Use \ to escape special chars if you want to match them verbatim.
Redis 常用操作的更多相关文章
- 【Redis使用系列】Redis常用操作
一.string类型的常用命令 set key value #一个key对应一个value.多次赋值,会覆盖前面. setnx key value #如果key存在则创建key1,并返回1,如果 ...
- Python Redis常用操作(持续更新)
目录 1.Redis简介 2.Redis部署 3.Redis API应用 4.String操作 1.Redis简介 redis是业界主流的key-value,nosql数据库之一.和Memcached ...
- redis常用操作总结
在项目中时常会用到redis,redis看起来好像很难的样子,而且我也确认反复学习了很久,但是,总结下来,自己使用到的东西并不太多,如下作一些总结工作. 1.安装(单机) 1.1 windows, 直 ...
- Redis常用操作
一.string类型的常用命令 set key1 com #一个key对应一个value,多次复制,会覆盖前面的value setnx key1 zhangsan #如果key1不存在则创建key1, ...
- Python Redis 常用操作
delete(*names) # 根据删除redis中的任意数据类型 exists(name) # 检测redis的name是否存在 keys(pattern='*') # 根据模型获取redis的n ...
- Redis常用操作--------SortedSet(有序集合)
1.ZADD key score member [[score member] [score member] ...] 将一个或多个 member 元素及其 score 值加入到有序集 key 当中. ...
- Redis常用操作-------Set(集合)
1.SADD key member [member ...] 将一个或多个 member 元素加入到集合 key 当中,已经存在于集合的 member 元素将被忽略. 假如 key 不存在,则创建一个 ...
- Redis常用操作-------List(列表)
1.BLPOP key [key ...] timeout BLPOP 是列表的阻塞式(blocking)弹出原语. 它是 LPOP 命令的阻塞版本,当给定列表内没有任何元素可供弹出的时候,连接将被 ...
- Redis常用操作-------Hash(哈希表)
1.HDEL key field [field ...] 删除哈希表 key 中的一个或多个指定域,不存在的域将被忽略. 在Redis2.4以下的版本里, HDEL 每次只能删除单个域,如果你需要在一 ...
- Redis常用操作-------Key(键)
1.DEL key [key ...] 删除给定的一个或多个 key . 不存在的 key 会被忽略. 可用版本: >= 1.0.0 时间复杂度: O(N), N 为被删除的 key 的数量. ...
随机推荐
- 【MVVM Light】Messager的使用
一.前言 在MVVM编程的模式中,有时候我们会遇到一个很尴尬的情况: 若干个xaml.cs都复用一个ViewModel,当ViewModel想传递一个特定的消息给某一个xaml.cs的时候 ...
- 02 button的练习
private void button1_Click(object sender, EventArgs e) { MessageBox.Show("我也喜欢你!"); //if ( ...
- win2008R2 下解决关于mysql odbc无法正常工作问题
1.安装 mysql-connector-odbc-5.1.1-win32 下载 2.确保IIS中“启用32位应用程序”为True 3.连接字符串: mysql_connstr="Drive ...
- [C#项目开源] MongoDB 可视化管理工具 (2011年10月-至今)
正文 该项目从2011年10月开始开发,知道现在已经有整整5年了.MongoDB也从一开始的大红大紫到现在趋于平淡. MongoCola这个工具在一开始定位的时候只是一个Windows版本的工具,期间 ...
- bzoj3388(神奇的解法)
题目大意: 约翰的表哥罗恩生活在科罗拉多州.他近来打算教他的奶牛们滑雪,但是奶牛们非常害羞,不敢在游人如织的度假胜地滑雪.没办法,他只好自己建滑雪场了.罗恩的雪场可以划分为W列L行(1≤W≤500;1 ...
- flask+sqlite3+echarts2+ajax数据可视化
前提: 准备Python + Flask+Sqlite3的平台环境(windows系统) 前面一节介绍flask怎么安装了,剩下sqlite3下载后解压,然后环境变量添加解压路径就行了 附加下载地址: ...
- Android 的进程和线程
进程和线程 如果某个应用程序组件是第一次被启动,且这时应用程序也没有其他组件在运行,则android系统会为应用程序创建一个包含单个线程的linux进程.默认情况下,同一个应用程序的所有组件都运行在同 ...
- 如何在Windows Server 2008 R2 SP1安装Redis-x64-3.2.100,并且自动注册服务
1.官网:http://redis.io/ 2.下载地址:https://github.com/MSOpenTech/redis/releases 3.最新的安装包: 4.点击msi文件开始安装. 5 ...
- angular $http请求
angular使用post.get向后台传参的问题 一.问题的来源 我们都知道向后台传参可以使用get.put,其形式就类似于name=jyy&id=001.但是在ng中我却发现使用$http ...
- <![CDATA[的web使用简单说明
html.javascript会涉及到三个解析器,html解析器.xml解析器.javascript解析器.那么好了,问题来了,以上代码经常混编在一起,各自有各自的规则,终究会有冲突的,如下就是冲突. ...