Redis String类型数据常用的16条命令总结 描述:String 类型是最简单的类型,一个Key对应一个Value,String类型是二进制安全的.Redis的String可以包含任何数据,比如jpg图片或序列化对象. 常用方法: 1, set方法: set <key> <value> 设置key的值为value (1)对不存在的key使用set: redis 127.0.0.1:6379> set name 'zhangsan' OK r
以个人信息为例操作string类型 设置操作: set: set key value 创建key-value名值对 setnx: setnx key value 创建不存在的key-value,已存在则创建失败 setex: setex key time value 创建time(s)内自动销毁的key-value setrange: setrange key pos value
package com.daxin.jedis_datastructure; import org.junit.After; import org.junit.Before; import org.junit.Test; import redis.clients.jedis.Jedis; /** * Unit test for simple App. */ public class AppTest { Jedis jedis = null; @Before public void before(
Redis中提供了原子性命令SETEX或SET来写入STRING类型数据并设置Key的过期时间: > SET key value EX NX ok > SETEX key value ok 但对于HASH结构则没有这样的命令,只能先写入数据然后设置过期时间: > HSET key field value ok > EXPIRE key 60 ok 这样就带了一个问题:HSET命令执行成功而EXPIRE命令执行失败,那么数据将不会过期.针对这个问题,本文提供两种解决方案: Lua脚本