Badgerati / PsRedis

PowerShell Module for interacting with Redis caches

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PsRedis

MIT licensed PowerShell

PowerShell module for interacting with Redis caches, via the StackExchange.Redis library.

Requires PowerShell 5.0+

Install

Install-Module -Name PsRedis
Import-Module PsRedis

Usage

Your scripts must first open a connection, and then close it:

Connect-Redis -ConnectionString $ConnectionString

# logic

Disconnect-Redis

or you can use the helper function that wraps the two:

Invoke-RedisScript -ConnectionString $ConnectionString -ScriptBlock {
    # logic
}

Return INFO about a Cache

This example will return the information you get from running the INFO command against the Redis cache:

Get-RedisInfo

Test to get Average Response Time

This example shows how to run a test against Redis to get the average response times for the cache. You need to supply a dummy Key value that will be used as a counter to increment - it's then removed after the test.

# get average response over 120s after incrementing counter once a second
Test-RedisTiming -Key 'counter' -Seconds 120

# get average response over 120s after rapidly incrementing counter
Test-RedisTiming -Key 'counter' -Seconds 120 -NoSleep

Get the value of a Key

Get-RedisKey -Key '<some-key>'

Remove all Keys that match a Pattern

This example will let you remove all keys from Redis that match a particular pattern - if the Redis version is 2.8.0 or greater then a SCAN is used, else KEYS is used.

# remove all "user" keys
Remove-RedisKeys -Pattern 'user:*'

# remove all "user" keys, but sleep for 5s between every 1000 removed
Remove-RedisKeys -Pattern 'user:*' -SleepThreshold 1000 -SleepSeconds 5

# remove all "user" keys, up to a max of 15000 keys then stop
Remove-RedisKeys -Pattern 'user:*' -MaxDelete 15000

Functions

  • Add-RedisKey
  • Add-RedisSetMember
  • Connect-Redis
  • Disconnect-Redis
  • Get-RedisInfo
  • Get-RedisInfoKeys
  • Get-RedisKey
  • Get-RedisKeyDetails
  • Get-RedisKeys
  • Get-RedisKeysCount
  • Get-RedisKeyTTL
  • Get-RedisKeyType
  • Get-RedisKeyValueLength
  • Get-RedisRandomKey
  • Get-RedisRandomKeys
  • Get-RedisRandomKeysQuick
  • Get-RedisUptime
  • Invoke-RedisScript
  • Remove-RedisKey
  • Remove-RedisKeys
  • Remove-RedisSetMember
  • Set-RedisIncrementKey
  • Set-RedisKeyTTL
  • Test-RedisTiming

About

PowerShell Module for interacting with Redis caches

License:MIT License


Languages

Language:PowerShell 100.0%