---
# System prepended metadata

title: Redis
tags: [tools]

---

# Redis
###### tags: `tools`
[TOC]
### install redis
```
yum install epel-release

yum install -y  redis
```
### redis-cli 
```
redis-cli -h 47.74.70.148 -p 6379
redis-cli -h localhost -p 6379
```


* display db
```
 info
 config get databases
```


* select db
```
 select 11
```


* display whole key
```
 keys * 
``` 


* get key value
```
get 'key'
```

* set key value
```
get 'key' 'value'
```


### display hole key
```
echo "KEYS Shared-AU:DATA_SOURCE:*" | redis-cli -h 47.74.70.148 -p 6379 -n 11 | less
```



### disply whole value script
```
str=$(echo "KEYS *" | redis-cli -h localhost -p 6379 -n 11)

if [ -f values.txt ]; then
    rm values.txt
fi

for key in $str; do
    if [[ "$key" =~ "DATA_SOURCE" ]]; then
        echo "key.........$key" | tee -a values.txt
        echo "GET $key" | redis-cli -h 47.74.70.148 -p 6379 -n 11 | tee -a values.txt
        echo "\n" | tee -a values.txt
    fi
done

```


# implement function
```java
public boolean setLock(String cacheKey, String value, long expire) {
    return redisClient.lock(getCacheKey(cacheKey), value, (int) expire);
}
```


# LUA delete all key

```
EVAL "local real_keys = redis.call('KEYS', KEYS[1]) local key_count = table.getn(real_keys) if key_count > 0 then redis.call('DEL', unpack(real_keys)) end" 1 "gaia-membership:v3:device:single:55a12ddf-5155-40d1-b38d-027a21ab5f5c_c1bda71b-879a-46a6-b3a5-d6f7abc28ff2*"


```