Redis的相关概念不做介绍了,大家也可以先了解下Memcached,然后比较下二者的区别,就会有个整体的印象。 服务器端通常选择Linux , Redis对于linux是官方支持的,使用资料很多,需要下载相关服务器端程序 ,然后解压安装。因为能力和条件有限,我只简单介绍下
Redis的相关概念不做介绍了,大家也可以先了解下Memcached,然后比较下二者的区别,就会有个整体的印象。
服务器端通常选择Linux , Redis对于linux是官方支持的,使用资料很多,需要下载相关服务器端程序 ,然后解压安装。因为能力和条件有限,我只简单介绍下windows上如何安装和使用,有兴趣的可以娱乐一下。
服务器端程序下载地址:https://github.com/ServiceStack/redis-windows.git
如果不好操作的话到这来:http://download.csdn.net/detail/u013283727/8212831下载完后使用cmd进入下载文件的目录中,尝试以下操作:
Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\>cd redis64-latest C:\redis64-latest>redis-server redis.windows.conf --maxmemory 200m _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 2.8.17 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in stand alone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 4552 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' [4552] 01 Dec 13:38:53.147 # Server started, Redis version 2.8.17 [4552] 01 Dec 13:38:53.147 * DB loaded from disk: 0.000 seconds [4552] 01 Dec 13:38:53.147 * The server is now ready to accept connections on po rt 6379
客户端使用java程序来连接,在这里介绍两种常用的方法
(Jar包直接找maven要:http://www.mvnrepository.com 一搜就出来了)1.Redisson
/** * @author fcs * Redisson Example */ public class RedissonTest { public static void main(String[] args) { //1.初始化 Config config = new Config(); config.setConnectionPoolSize(10); config.addAddress("127.0.0.1:6379"); Redisson redisson = Redisson.create(config); System.out.println("redis连接接成功。。。。。"); //2.测试concurrentMap,put时候就会同步到redis中 ConcurrentMap<String, String> map = redisson.getMap("firstMap"); map.put("changshengfeng", "男"); map.put("yongtaoliu", "男"); map.put("qiaozhu", "女"); ConcurrentMap resultMap = redisson.getMap("firstMap"); System.out.println("resultMap == "+resultMap.keySet()); //关闭连接 redisson.shutdown(); } }
2.Jedis
/** * @author fcs * test about jedis * Dec 1, 2014 */ public class JedisTest { private static Jedis jedis; @Before public void setup(){ jedis = new Jedis("127.0.0.1", 6379); System.out.println("Redis服务器已连接...."); // jedis.auth("admin"); //权限验证 } /** * redis 存储字符串 */ @Test public void testString(){ //添加数据 jedis.set("name", "fcs"); System.out.println(jedis.get("name"));//获取结果 jedis.append("name", "is handsome");//拼接 jedis.del("name");//删除某个键 System.out.println(jedis.get("name")); jedis.mset("name","changsheng","age","22","qq","646653132");//设置多个键值对 jedis.incr("age");//加1操作 在投票中可能用的上 System.out.println(jedis.get("name")+"--"+jedis.get("age")+"--"+jedis.get("qq")); } /** * 操作List */ @Test public void testList(){ jedis.del("java framework"); System.out.println(jedis.lrange("java framework", 0, -1)); //先向key java framework存放三条数据 jedis.lpush("java framework", "spring"); jedis.lpush("java framework", "struts"); jedis.lpush("java framework", "hibernate"); //再取出所有数据jedis.lrange是按范围取出 第一个是key 第二个是其实位置 第三个是结束位置 System.out.println(jedis.lrange("java framework", 0, -1)); jedis.del("java framework"); jedis.rpush("java framework", "spring"); jedis.rpush("java framework", "struts"); jedis.rpush("java framework", "hibernate"); //再取出所有数据jedis.lrange是按范围取出 第一个是key 第二个是其实位置 第三个是结束位置 System.out.println(jedis.lrange("java framework", 0, -1)); } /** * 操作Set */ @Test public void testSet(){ jedis.sadd("haha", "why"); jedis.sadd("haha", "you"); jedis.sadd("haha", "so"); jedis.sadd("haha", "diao"); jedis.sadd("haha", "?"); //移除 jedis.srem("haha", "?"); System.out.println("判断?是不是haha集合的元素:"+jedis.sismember("haha", "?")); System.out.println("获取所有加入的value:"+jedis.smembers("haha")); System.out.println("返回给定集合名的一个随机的value:"+jedis.srandmember("haha")); System.out.println("返回集合的元素个数:"+jedis.scard("haha")); } /** * redis 操作map */ @Test public void testmap(){ Map<String,String> map = new HashMap<String, String>(); map.put("name", "小露"); map.put("sex", "男"); map.put("email", "haha@fcs.com"); jedis.hmset("user", map);//相当于给map再取一个名字 List<String> rsmap = jedis.hmget("user", "name","sex");//后面是一个可变参数列表 去某个map中的一些key代表的值 System.out.println(rsmap); //删除map中的某个键值 jedis.hdel("user", "email"); System.out.println("删除后----email"+jedis.hmget("user", "email")); System.out.println("是否存在key为user的记录:"+jedis.exists("user")); System.out.println("key为user的map中存放的值的个数:"+jedis.hlen("user")); System.out.println("返回map对象中所有的key:"+jedis.hkeys("user")); System.out.println("返回map对象中所有的value:"+jedis.hvals("user")); //使用迭代器 Iterator<String> iter = jedis.hkeys("user").iterator(); System.out.println("***************使用迭代器***************"); while(iter.hasNext()){ String key = iter.next();//每次向后越过一个对象 System.out.println(key+":"+jedis.hmget("user", key));//迭代key 根据key再取值value } } /** * 这里在前面执行完之后直接再去拿值 试试这些进驻内存的数据是否还在 * 可以把服务器端关掉再重启 再直接运行这个方法看看 * 如果还有数据就说明该数据库自动完成了持久化 它有默认的持久化机制 */ @Test public void testNoSet(){ Iterator<String> iter = jedis.hkeys("user").iterator(); System.out.println("***************使用迭代器***************"); while(iter.hasNext()){ String key = iter.next();//每次向后越过一个对象 System.out.println(key+":"+jedis.hmget("user", key));//迭代key 根据key再取值value } } // @AfterClass 测试整个类时可以用 会关闭服务器端程序 // public static void close(){ // jedis.shutdown();//不能用@After 不然每次执行完一个方法都会关闭服务器 // System.out.println("连接已关闭....."); // } }
这时候可以看到cmd中有一些日志记录:(这就是它默认的持久化机制,可以在redis.windows.conf配置文件中查看)
[3972] 01 Dec 13:59:04.073 * 1 changes in 900 seconds. Saving... [3972] 01 Dec 13:59:04.229 # fork operation complete [3972] 01 Dec 13:59:04.229 * Background saving terminated with success [3972] 01 Dec 14:20:05.127 * 1 changes in 900 seconds. Saving... [3972] 01 Dec 14:20:05.267 # fork operation complete [3972] 01 Dec 14:20:05.267 * Background saving terminated with success [3972] 01 Dec 14:35:06.074 * 1 changes in 900 seconds. Saving... [3972] 01 Dec 14:35:06.204 # fork operation complete [3972] 01 Dec 14:35:06.224 * Background saving terminated with success哎,先到这吧。。。。

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.