the redis running status.
[6246]05 Aug 19:24:33- 0 clients connected (0 slaves),539544 bytes in use[6246] 05 Aug 19:24:37- Accepted 127.0.0.1:51381[6246] 05 Aug 19:24:38- 1 clients connected (0 slaves),547372 bytes in use
The above steps are OK !! Such a simple redis database can run smoothly.
Step 7: Stop a redis instance
The simplest way is to stop an instanc
Java Operations Redis is a must-learn content, then I directly on a super simple case for you to refer to the next!First, create the Redistest class, the code is as follows!Import Redis.clients.jedis.jedis;public class Redistest {public static void main (string[] args) {//TODO auto-Generated method stub//Connect Redis service Jedis Jedis = new Jedis ("127.0.0.1",
delete the Lock_key to implement the release lock, the other not acquire the lock, then try to retry until you get the lock.
The above logic is ok under normal circumstances, but once the client that gets the lock is dead, and the above release lock is not performed, the other client cannot acquire the lock.
implementation of four Redis distributed lock
A distributed lock that is implemented in a simple way cannot release resources when the client i
Java Operations Redis Simple example
Beginner Redis, in the Java language and environment to complete the Redis learning. First, the official website downloads the source code, compiles, installs, modifies the configuration file
Dis jedis.set ("foo", "Bar" = Jedis.get ("foo" ); Jedis.zadd ( "Sose", 0, "car"); Jedis.zadd ("Sose", 0, "bike" ); finally { // // When the program closes, you need to call the Close method Pool.destroy ();Set master/Slave distributionEnable synchronous replicationRedis is primarily built for master/slave distribution. This means that the "write" request must point to "master", and "master" will replicate the changed content to "slave" synchronously. The "read" request can (not be
As a result of a systematic study of Redis, Redis is used as the data cache in multiple projects in the company, so take advantage of these days to write a demo of the time, here for your own later study notes, if there is wrong place, please tap bricks.
The Redis website recommended to Java use a lot of clients: Jedis
filed1 ..... fieldn//Get all specified hash filed04hmset key filed1 value1 ... filedn valuen//Set hash multiple Field05hincrby key field integer/ /Add the specified hash filed to the given Value 06hexists key field//test Specifies whether field exists 07hdel key field//delete specified hasH Field08hlen key//Returns field number of the specified hash 09hkeys key//return hash of all field10hvals key Return hash of all value11hgetall//return hash of all filed and value3.
《Integration of Spring 4 (including MVC, Context, ORM) + MyBatis 3 ExampleArticle briefly introduces the latest version of the Spring MVC, IOC, MyBatis ORM integration and declarative transaction processing. Now we need to integrate the cache, and we're using Redis, and this article will cover the integration of Redis cache + Spring on the basis of this example.
cache of the Provincecities method has been cleaned out and the cache of the Insertcity method works.Then verify the cache configuration of the Renamecity method, JMeter calls the/bdp/city/rename.json interface:Then look at Redis storage:The cache of the Searchcity method has also been cleaned up, and the caching of the Renamecity method has worked.7. Precautions
The Java object to be cached must
storage:
The cache of the searchCity method has been cleared, and the cache of the renameCity method also works.
7. note: The Java object to be cached must implement the Serializable interface, because Spring will serialize the object before saving it to Redis, such as com. defonds. bdp. city. bean. city class. If Serializable is not implemented, the following error occurs: nested exception is
One. Add dependencyTwo. Example:1. Create Jedis Object Operations RedisConstructing Jedis objectsJedis Jedis = new Jedis ("127.0.0.1", 6379);Adding data to RedisJedis.set ("MyTest", "123bin");Reading data from RedisString value = Jedis.get ("mytest"); System.out.println (value);Close connectionJedis.close (); 2. Build connection pool configuration information by connecting pooling//Jedispoolconfig jedispoolconfig = new Jedispoolconfig ();Set maximum n
= Female, age = 55]}
After deleting a user whose ID is 2, all remaining users: {3 = Person [id = 3, name = TheOne, gender = Male, age = 25], 1 = Person [id = 1, name = Oracle, gender = Female, age = 55]}
You can also open redis-cli and manually enter the key to view the current Redis storage result:
The remaining two users are: {3 = Person [id = 3, name = TheOne, gender = Male, age = 25], 1 = Person [id =
method, JMeter calls the/bdp/city/rename.json interface:Then look at Redis storage:The cache of the Searchcity method has also been cleaned up, and the caching of the Renamecity method has worked. 7. Precautions
The Java object to be cached must implement the Serializable interface , because Spring will serialize the object first into Redis, such as the Com.
Redis Study Notes (7)-cluster client (jedis) code example, redisjedis
In the previous section, I learned how to build a cluster and operate on the redis-cli terminal. However, a more common scenario is to read and write the cluster in the program code, this requires redis-client Support for the cluster mode. Currently,
session to view or analyze the health of Redis.[6246]05 19:24:33-0 clients connected (0 slaves), 539544 bytes in use[6246] 19:24:37-accepted 127.0.0 .1:51381[6246] 19:24:38-1 clients connected (0 slaves), 547372 bytes in useA few more steps will be OK!! Such a simple Redis database can run smoothly.Step Seven: Stop the Redis instanceThe simplest approach is to u
the same time, they get the updated value (the latest value ).
MultiUtility tool: Redis is a versatile utility that can be used in many applications, such as cache and message passing queues (Redis native supports publishing/subscription). For example: web application sessions, website page clicks, and other transient data;
To install
divided into two commands to execute, the code is as follows:
Public static void wrongReleaseLock2(Jedis jedis, String lockKey, String requestId) {
/ / Determine whether the lock and unlock are the same client
If (requestId.equals(jedis.get(lockKey))) {
// If at this time, the lock is suddenly not the client, it will be unlocked by mistake.
Jedis.del(lockKey);
}
}
As a code comment, the problem is that if the Jedis.del () method is called, the lock will be unlocked when it is no
Redis Series Learning (iii) Java API access and transactions
Introduction Two first simple example three business
first, the introduction
To access the Redis database to Java, the first officially recommended Jedis framework, which contains
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.