markdown Azure Redrest for Redis

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown Azure Redrest for Redis相关的知识,希望对你有一定的参考价值。

Typically used as a cache to improve the performance and scalability of systems that rely heavily on backend data-stores.

Performance is improved by temporarily copying frequently accessed data to fast storage located close to the application.

With Azure Cache for Redis, this fast storage is located in-memory with Azure Cache for Redis instead of being loaded from disk by a database.

It can also be used as an:
- in-memory data structure store, 
- a distributed non-relational database, and 
- a message broker.

Application performance is improved by taking advantage of the low-latency, high-throughput performance of the Redis engine.

# Programming

Use the `StackExchange.Redis` NuGet package for programmatic access to a cache.

# Create with CLI

```sh
# Create a Resource Group 
az group create --name contosoGroup --location eastus

# Create a Basic C0 (256 MB) Redis Cache
az redis create --name contosoCache --resource-group contosoGroup --location eastus --sku Basic --vm-size C0
```

Show details:
```sh
az redis show --name contosoCache --resource-group contosoGroup
```

# Connect from Desktop

Create cache as above, and set to allow non-SSL access.

Install Nodejs client from [here](https://redislabs.com/blog/get-redis-cli-without-installing-redis-server/).

```sh
c:\projects\az203
λ rdcli -h contosoCache.redis.cache.windows.net -p 6379 -a xky+U+tEkzyadayadayadalyBCGXe6690=
contosoCache.redis.cache.windows.net:6379> set message "Hello!"
OK
contosoCache.redis.cache.windows.net:6379> get message
Hello!
```
// Connect using multiplexer - share for all connections
private static Lazy<ConnectionMultiplexer> lazyConnection = new Lazy<ConnectionMultiplexer>(() =>
{
    //string cacheConnection = ConfigurationManager.AppSettings["CacheConnection"].ToString();
    string cacheConnection = "ric-01.redis.cache.windows.net.redis.cache.windows.net,abortConnect=false,ssl=true,password=LV13X4NvVAFLYxxxxxxxxxxxxxxDKYelFf2cQ=";
    return ConnectionMultiplexer.Connect(cacheConnection);
});
// static property that returns a connected instance
// a thread-safe way to initialize only a single connected ConnectionMultiplexer instance
public static ConnectionMultiplexer Connection
{
    get
    {
        return lazyConnection.Value;
    }
}

// Use connection to get database
IDatabase cache = lazyConnection.Value.GetDatabase();
// Or: IDatabase cache = Connection.GetDatabase();

// Use the cache ...

// Clean up connection
lazyConnection.Value.Dispose();
// Or: Connection.Dispose();
// PING
cache.Execute("PING").ToString()
// => PONG

// Simple get
cache.StringGet("Message").ToString()
// => _blank_

// Simple set
cache.StringSet("Message", "Hello!").ToString()
// => True

// Simple get again
cache.StringGet("Message").ToString()
// => Hello!

// Get the client list, useful to see if connection list is growing...
cache.Execute("CLIENT", "LIST").ToString()
// => id=674 addr=46.226.xxx.88:58570 fd=15 name=LAPTOP-1A2JKRH7 age=0 idle=0 flags=N db=0 sub=1 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 ow=0 owmem=0 events=r cmd=subscribe numops=5

// Add JSON serialized object to cache
Employee e007 = new Employee("007", "Davide Columbo", 100);
cache.StringSet("e007", JsonConvert.SerializeObject(e007))

// Retrieve JSON object from cache and deserialize
Employee e007FromCache = JsonConvert.DeserializeObject<Employee>(cache.StringGet("e007"));
# Keys

```
> set message "Hello!"
OK
> get message
Hello!
> append message " World!"
(integer) 13
> get message
Hello! World!

# Number of keys
> dbsize
(integer) 2

# Delete a key
> del message
(integer) 1

# Does a key exist
> exists message
(integer) 1
> exists other-key
(integer) 0

# Remove all keys from database / all databases
> flushdb
OK
> flushall
OK
```

# Clients

```
> client list
id=293 addr=xx.xx.xx.xx:60609 fd=13 name= age=298 idle=0 flags=N ...
```

# Counter

```
> set mykey "10"
OK
> incr mykey
(integer) 11
> get mykey
11
```

# Database Info

```
> info
# Server
redis_version:3.2.7
redis_mode:standalone
os:Windows
arch_bits:64

# Clients
connected_clients:1
maxclients:256
blocked_clients:0

# Memory
used_memory:304784
used_memory_human:297.64K
etc. etc.
```

以上是关于markdown Azure Redrest for Redis的主要内容,如果未能解决你的问题,请参考以下文章

markdown 将SPA部署到Azure存储

markdown Azure文件+符号链接

markdown 更新Azure ApplicationGateway的证书

markdown ARM模板模式#arm #azure

markdown 20190601-分享DevOps以及Azure DevOps的Pipeline功能做到CI以及CD

将图像添加到 Azure Devops 仪表板